Created
February 1, 2017 00:49
-
-
Save WPprodigy/5bfc0f8523ad3fd9dd5e59f174fb666e to your computer and use it in GitHub Desktop.
Change WooCommerce attribute labels based on the Product ID
This file contains hidden or 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
add_action( 'woocommerce_attribute_label', 'wc_ninja_change_attribute_label', 20, 3 ); | |
function wc_ninja_change_attribute_label( $label, $name, $product ) { | |
// Check if on single product page and if the attribute name is 'color' | |
if ( is_product() && 'color' === $name ) { | |
global $product; | |
// Change the label text based on the product ID | |
switch ( $product->id ) { | |
case '357': | |
$label = 'Custom Label One'; | |
break; | |
case '436': | |
$label = 'Custom Label Two'; | |
break; | |
} | |
} | |
// Return the label, untouched if none of the above conditions were true | |
return $label; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment