Created
November 6, 2023 10:07
-
-
Save braddalton/3dd2b0b2ccf2558486cc7e8a1dac8638 to your computer and use it in GitHub Desktop.
Unset variation attribute in WooCommerce https://wpsites.net/wordpress-tutorials/custom-functions-tutorials-small-plugins-for-woocommerce/
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
add_filter( 'woocommerce_available_variation', 'unset_variation_attribute', 10, 3 ); | |
function unset_variation_attribute( $data, $product, $variation ) { | |
// Define the attribute name you want to hide (e.g., "Size") | |
$attribute_to_hide = 'Size'; | |
// Unset the attribute if it exists in the variation data | |
if (isset($data['attributes']['attribute_' . sanitize_title($attribute_to_hide)])) { | |
unset($data['attributes']['attribute_' . sanitize_title($attribute_to_hide)]); | |
} | |
return $data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment