Digital experiences for all disciplines
New Landing › How can we help? › Atelier › Chose an option…
New Landing › How can we help? › Atelier › Chose an option…
- This topic has 13 replies, 4 voices, and was last updated 9 years by David Martin – Support.
-
Posted in: Atelier
-
October 8, 2015 at 2:14 am #219270
Hello,
We have several attributes and variations set up for our products – including size, color and fragrance. On the product page the pull-down option boxes default to “Chose an Option.” Can we change this text to say Chose a color or Chose a size..etc.?
If so, how do I do that?
Thank you for your help.
DawnaAttachments:
You must be logged in to view attached files.October 8, 2015 at 8:09 am #219307Hi
Please contact WooCommerce about this as it’s their functionality.
Thanks
– KyleOctober 8, 2015 at 1:02 pm #219414How do I do that? When I go to their website, they say they only offer support for paying customers. Is there a another way to contact support?
Best,
DawnaOctober 8, 2015 at 1:12 pm #219419Go here: https://wordpress.org/support/plugin/woocommerce
– Kyle
October 8, 2015 at 2:16 pm #219446Hi Kyle,
The instructions I received are:
Go to variable.php
Look for this on line 24
<option value=””><?php echo __( ‘Choose an option’, ‘woocommerce’ ) ?>…</option>
and replace it with
<option value=””><?php echo sprintf( __( ‘Choose a %s’, ‘woocommerce’ ), $woocommerce->attribute_label( $name ) ) ?>…</option>
or you can just replace the ‘Choose an Option’ with the text of your choice
Where is the variable.php file?
October 8, 2015 at 2:19 pm #219448It’s in the woocommerce files.. wp-content/plugins/woocommerce
– Kyle
October 8, 2015 at 2:20 pm #219449Okay – so where are those files located? I don’t see them in the Appearance –> Editor area.
October 8, 2015 at 2:25 pm #219452You will have to edit them via ftp. Again, this is woocommerce functionality so please discuss with them
– Kyle
October 8, 2015 at 6:15 pm #219533In case anyone is wondering how we solved this – here are the instructions. You will need to use FTP to access the correct files).
1. Override ‘variable.php‘ file by copying it from ‘woocommerce/single-product/add-to-cart/variable.php‘ to your theme directory. For example; #your_theme_location/woocommerce/single-product/add-to-cart/variable.php.
2. Once done, edit variable.php and lookout for the code as the one shown below (In woocommerce version 2.4.7, the below code was starting at line 27 and ends at line 38):
<?php foreach ( $attributes as $attribute_name => $options ) : ?>
<tr>
<td class=”label”><label for=”<?php echo sanitize_title( $attribute_name ); ?>”><?php echo wc_attribute_label( $attribute_name ); ?></label></td>
<td class=”value”>
<?php
$selected = isset( $_REQUEST[ ‘attribute_’ . sanitize_title( $attribute_name ) ] ) ? $_REQUEST[ ‘attribute_’ . sanitize_title( $attribute_name ) ] : $product->get_variation_default_attribute( $attribute_name );
wc_dropdown_variation_attribute_options( array( ‘options’ => $options, ‘attribute’ => $attribute_name, ‘product’ => $product, ‘selected’ => $selected ) );
?>
</td>
</tr>
<?php endforeach;?>replace it with the below code:
<?php $variations_arr = array();
foreach ( $attributes as $attribute_name => $options ) : ob_start(); ?>
<tr>
<td class=”label”><label for=”<?php echo sanitize_title( $attribute_name ); ?>”><?php echo wc_attribute_label( $attribute_name ); ?></label></td>
<td class=”value”>
<?php $selected = isset( $_REQUEST[ ‘attribute_’ . sanitize_title( $attribute_name ) ] ) ? wc_clean( $_REQUEST[ ‘attribute_’ . sanitize_title( $attribute_name ) ] ) : $product->get_variation_default_attribute( $attribute_name ); wc_dropdown_variation_attribute_options( array( ‘options’ => $options, ‘attribute’ => $attribute_name, ‘product’ => $product, ‘selected’ => $selected ) ); echo end( $attribute_keys ) === $attribute_name ? ‘‘ . __( ‘Clear selection’, ‘woocommerce’ ) . ‘‘ : ”; ?>
</td>
</tr>
<?php $variations_ob = ob_get_clean(); $variations_arr[wc_attribute_label($attribute_name)] = $variations_ob; endforeach;foreach ($variations_arr as $name => $ob) { echo str_ireplace(‘choose an option’, ‘Choose ‘.$name, $ob );
} ?>Once done, save ‘variable.php‘ file and refresh your product page to see ‘Choose an option” replaced with ‘Choose <attribute_name>’. That’s it!
October 8, 2015 at 9:17 pm #219551Great! Thanks for sharing
– Kyle
October 19, 2015 at 2:10 pm #221595Hi,
The above solution did not work in my case.
I found another way to do this, which worked great for me to replace choose an option to choose a <attribute name>.
It also gave me the possibility to change easily the term “Choose a” to whatever I like, for example “choose from” or “select a”.Here it is :
In wc-template-functions.php in line 1915.
Select the following code :
$args = wp_parse_args( $args, array(
‘options’ => false,
‘attribute’ => false,
‘product’ => false,
‘selected’ => false,
‘name’ => ”,
‘id’ => ”,
‘class’ => ”,
‘show_option_none’ => __( ‘Choose an option’, ‘woocommerce’ )
) );And replace with :
$mb_name = $args[‘attribute’];
$args = wp_parse_args( $args, array(
‘options’ => false,
‘attribute’ => false,
‘product’ => false,
‘selected’ => false,
‘name’ => ”,
‘id’ => ”,
‘class’ => ”,
‘show_option_none’ => __( ‘Choose a ‘, ‘woocommerce’ ) . $mb_name
) );where you can edit ‘Choose a’ to whatever you like.
Source from https://wordpress.org/support/topic/feature-request-choose-an-option-woocommerce-v24
October 19, 2015 at 2:18 pm #221599I would not recommend editing the core plugin files, please consult their docs on the correct way to extend/modify their plugin: https://docs.woothemes.com/documentation/plugins/woocommerce/woocommerce-codex/extending/
November 9, 2015 at 2:52 pm #227071I’m all set with this issue – you can close it. Thank you! 🙂
November 9, 2015 at 2:56 pm #227073No problem, thanks.
David. -
Posted in: Atelier
You must be logged in and have valid license to reply to this topic.