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
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.