Last active
September 13, 2021 06:06
-
-
Save damiencarbery/243821761aceb11f85d82e97a4253d69 to your computer and use it in GitHub Desktop.
Choose Attribute Name - https://www.damiencarbery.com/2018/06/customise-choose-an-option-dropdown-item/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Going from 'pa_size' to 'Size' the hard way. | |
if ( 0 === strpos( $args[ 'attribute' ], 'pa_' ) ) { | |
$args['show_option_none'] = 'Choose ' . ucwords( str_replace( '-', ' ', substr( $args[ 'attribute' ], 3 ) ) ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Choose Attribute Name | |
Plugin URI: https://www.damiencarbery.com/2018/06/customise-choose-an-option-dropdown-item/ | |
Description: Change the default "Choose an option" to be based on the attribute name. | |
Author: Damien Carbery | |
Version: 0.1 | |
*/ | |
// Change 'Choose an option' to use attribute name to be more user friendly. | |
// Inspired by: https://stackoverflow.com/a/34713246/8605943 | |
add_filter( 'woocommerce_dropdown_variation_attribute_options_args', 'am_change_option_none_text' ); | |
function am_change_option_none_text( $args ) { | |
$args['show_option_none'] = 'Choose ' . wc_attribute_label( $args[ 'attribute' ] ); | |
return $args; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'woocommerce_dropdown_variation_attribute_options_args', 'am_change_option_none_text' ); | |
function am_change_option_none_text( $args ) { | |
// Only change text for these two product attributes. | |
if ( 'pa_size' == $args[ 'attribute' ] ) { | |
$args['show_option_none'] = 'Choose size'; | |
} | |
if ( 'pa_colour' == $args[ 'attribute' ] ) { | |
$args['show_option_none'] = 'Choose colour'; | |
} | |
return $args; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment