Reputation: 1
I want to show the name of an attribute at the drop-down-menu when no variation is selected. This is the code:
function wc_dropdown_variation_attribute_options( $args = array() ) {
$args = wp_parse_args( apply_filters( 'woocommerce_dropdown_variation_attribute_options_args', $args ), array(
'options' => false,
'attribute' => false,
'product' => false,
'selected' => false,
'name' => '',
'id' => '',
'class' => '',
'show_option_none' => __( 'Choose:', 'woocommerce' ),
) );
It should be: "Choose: attribute-name" e.g. Color or Size etc.
Can anyone help me?
Upvotes: 0
Views: 789
Reputation: 3562
modifying the core function directly is not recommended at all because you are going to lose any modification that you are going to do when the plugin is updated however with WordPress you can alter the function args with filter so here is how you can achieve your target goal.
add_filter( 'woocommerce_dropdown_variation_attribute_options_args', 'change_default_choose_text' );
function change_default_choose_text( $args ) {
$term = wc_attribute_label( $args['attribute'] ); //Get Attribute label
$args['show_option_none'] = __( 'Choose ' . $term . ' ', 'woocommerce' ); //Modify the Default option value
return $args;
}
Output:
Just put the code above in your functions.php
For More informations about WordPress Filter you can check the below Reference :
Upvotes: 1