Skip to content

Instantly share code, notes, and snippets.

@WPprodigy
Created February 1, 2017 00:49
Show Gist options
  • Save WPprodigy/5bfc0f8523ad3fd9dd5e59f174fb666e to your computer and use it in GitHub Desktop.
Save WPprodigy/5bfc0f8523ad3fd9dd5e59f174fb666e to your computer and use it in GitHub Desktop.
Change WooCommerce attribute labels based on the Product ID
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