How do I change button text from “Choose an option” in Woocommerce?

后端 未结 8 1457
你的背包
你的背包 2021-02-08 16:28

How would I go about changing this PHP code to to change Choose an option based on the id of the select element in the Woocommerce plugin for WordPress? I believe I have found t

8条回答
  •  有刺的猬
    2021-02-08 16:50

    Here's a pretty simple solution for WC >2.4 that avoids rewriting functions and cluttering up your functions.php..

    Add the variable.php file to your theme (http://docs.woothemes.com/document/template-structure/), and change this (from line 27):

     $options ) : ?>
    
        
        
            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' ) . '' : '';
            ?>
        
    
    

    to this:

     $options ) : 
        ob_start(); ?>
        
            
            
                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' ) . '' : ''; ?>
            
        
         $ob) {
        echo str_ireplace('choose an option', 'Choose '.$name, $ob );
    } ?>
    

    This will replace 'Choose an option' with 'Choose Size', 'Choose Colour' etc. depending on the name of your attribute.

提交回复
热议问题