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

后端 未结 8 1460
你的背包
你的背包 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:47

    I have done this using a combination of the other answers here and it worked well for me.

    This was done using WooCoommerce 3.3.5 and assume the filter was added relatively recently.

    You use the filter for the wc_dropdown_variation_attribute_options() function.

    // define the woocommerce_dropdown_variation_attribute_options_args callback 
    function filter_woocommerce_dropdown_variation_attribute_options_args( $array ) { 
    
        // Find the name of the attribute for the slug we passed in to the function
        $attribute_name = wc_attribute_label($array['attribute']);
    
        // Create a string for our select
        $select_text = 'Select a ' . $attribute_name;
    
        $array['show_option_none'] = __( $select_text, 'woocommerce' );
        return $array; 
    }; 
    
    // add the filter 
    add_filter( 'woocommerce_dropdown_variation_attribute_options_args', 'filter_woocommerce_dropdown_variation_attribute_options_args', 10, 1 ); 
    

    Hope this helps someone.

提交回复
热议问题