mrosata
Forum Replies Created
Viewing 1 replies (of 1 total)
-
Forum: Plugins
In reply to: [WooCommerce] Change "Choose an option" with attribute nameI believe fabrizioe is talking about the actual text inside the topmost option inside the select tag rather then the label for the dropdown.
This solution works well and is found on Stack Overflow.
Copy the file /plugins/woocommerce/templates/single-product/add-to-cart/variable.php to /themes/{your_theme_folder}/woocommerce/single-product/add-to-cart.php and then edit lines 27 – 28 from this (original):
<?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 ) ] ) ? 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 ? '<a class="reset_variations" href="#">' . __( 'Clear selection', 'woocommerce' ) . '</a>' : ''; ?> </td> </tr> <?php endforeach;?>to these lines this here:
<?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 ? '<a class="reset_variations" href="#">' . __( 'Clear selection', 'woocommerce' ) . '</a>' : ''; ?> </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 ); } ?>This is the safest option for your site as the other solutions could be overwritten through an update. Editing other peoples plugins is a bad which is probably the number 1 reason woocommerce allows us to override their templates from our themes rather then inside their plugin files.
Viewing 1 replies (of 1 total)