Maybe the remove action code could uncheck the Visible on the product page box on this one attribute somehow
Can you send a screenshot of exactly you want hidden and if also a URL
ok so I have two images for you. In the first you will find the category Chandelier highlighted in yellow.
http://2ndave.com/capture-4.png
In the second image you will see that same Chandelier category on top and the attribute Item Min Length or Square: lower down the page highlighted.
http://2ndave.com/capture-5.png
What I want to do is set it up when the category is Chandelier Hide the attribute Item Min Length or Square: aka (pa_item-min-length-or-square) because that dimension is not needed for that category. Is this possible with php code put into functions.php
I would send the url, but the site is currently in construction mode and can only be viewed with a login
The first one you can maybe write an if statement to hide that cat and the second one I would maybe hide it with page id in css?
I have found the following code to hide an attribute, just need to figure out how to base it on category. Do you have any suggestions?
function mycode_hide_attributes_from_additional_info_tabs( $attributes, $product ) {
/**
* Array of attributes to hide from the Additional Information
* tab on single WooCommerce product pages.
*/
$hidden_attributes = [
'pa_item-min-length-or-square',
];
foreach ( $hidden_attributes as $hidden_attribute ) {
if ( ! isset( $attributes[ $hidden_attribute ] ) ) {
continue;
}
$attribute = $attributes[ $hidden_attribute ];
$attribute->set_visible( false );
}
return $attributes;
}
add_filter( 'woocommerce_product_get_attributes', 'mycode_hide_attributes_from_additional_info_tabs', 20, 2 );
Got it working with the following code
add_action( 'wp', 'remove_product_content' );
function remove_product_content() {
// If a product in the 'Cookware' category is being viewed...
if ( has_term( array('CHANDEL-AIR', 'CHANDELIER','POT RACK','VANITY','BILLIARD/ISLAND' ), 'product_cat' ) ) {
function mycode_hide_attributes_from_additional_info_tabs( $attributes, $product ) {
/**
* Array of attributes to hide from the Additional Information
* tab on single WooCommerce product pages.
*/
$hidden_attributes = [
'pa_item-min-length-or-square',
];
foreach ( $hidden_attributes as $hidden_attribute ) {
if ( ! isset( $attributes[ $hidden_attribute ] ) ) {
continue;
}
$attribute = $attributes[ $hidden_attribute ];
$attribute->set_visible( false );
}
return $attributes;
}
add_filter( 'woocommerce_product_get_attributes', 'mycode_hide_attributes_from_additional_info_tabs', 20, 2 );
}
}