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

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

    There is actually an easier way to customize it.

    If you take a look at the core WC file wc-template-functions.php you can see that the array inside wc_dropdown_variation_attribute_options function is actually it's arguments with the following key value pairs:

    'options'          => false,
    'attribute'        => false,
    'product'          => false,
    'selected'         => false,
    'name'             => '',
    'id'               => '',
    'class'            => '',
    'show_option_none' => __( 'Choose an option', 'woocommerce' )
    

    Now all you need to do is to change the same key value pair in the function in variable.php template file. So I wanted to show the dropdown label instead of the Choose An Option text so I change the fu

    wc_dropdown_variation_attribute_options(
        array(
             'options' => $options,
             'attribute' => $attribute_name,
             'product' => $product,
             'selected' => $selected,
             'show_option_none' => wc_attribute_label( $attribute_name )
        )
    );
    

    Same goes with other pairs. Hoep this helps. By the way, this only works in WC 2.4+ so be careful.

提交回复
热议问题