went to hide specific attributes term
-
i want to hide specfic attribute term and also make sure after hiding the add to cart work plese suggest how its possible or if any code
https://patrickc103.sg-host.com/product/calm-oil/
The page I need help with: [log in to see the link]
-
when you select subscribe and save there is this attribute which i want to hide
Hi,
To hide a specific attribute term in WooCommerce and ensure that the “Add to Cart” button works properly even after hiding the term, you can use custom code. Below are the steps to achieve this:
- Identify the Attribute and Term:
- Determine the specific attribute and term you want to hide. You will need the attribute name (e.g., “Color”) and the term name (e.g., “Red”).
- Add Custom Code:
- In your WordPress theme’s
functions.phpfile, add the following code:
add_filter('woocommerce_product_variation_title_include_attributes', 'hide_specific_attribute_term', 10, 3); function hide_specific_attribute_term($include_attributes, $variation, $product) { // Define the attribute and term to hide $attribute_name = 'color'; // Replace with your attribute name $term_name = 'red'; // Replace with your term name // Check if the product has the specified term if (has_term($term_name, $attribute_name, $variation->get_id())) { // Remove the attribute from the variation title $include_attributes = false; } return $include_attributes; }Replace
'color'with the name of your attribute and'red'with the name of the term you want to hide.- Save Changes:
- Save the changes to your
functions.phpfile.
- Test:
- After adding this code, the specified attribute term should be hidden for variations that have that term. Test your products to ensure that the “Add to Cart” button functions correctly for these variations.
This code filters the variation title to hide the specified attribute term, but it doesn’t affect the functionality of the “Add to Cart” button. The button should work as expected for all variations, including those with the hidden attribute term.
Remember to make a backup of your theme’s
functions.phpfile before making any changes, and only add custom code if you’re comfortable with coding or consult with a developer if needed.You could hide it with CSS:
.button-variable-item-this {display:none}
@owadud655 this code have error its not work Your PHP code changes were not applied due to an error on line 14 of file wp-content/themes/woodmart-child/functions.php. Please fix and try saving again.
@seank123 the css code just hide the attribute term but add to cart still trigger
add_filter(‘woocommerce_product_variation_title_include_attributes’, ‘hide_specific_attribute_term’, 10, 2);
function hide_specific_attribute_term($include_attributes, $variation) {
// Define the attribute and term to hide
$attribute_name = ‘color’; // Replace with your attribute name
$term_name = ‘red’; // Replace with your term name// Get the product associated with the variation $product = wc_get_product($variation->get_parent_id()); // Check if the product has the specified term if (has_term($term_name, $attribute_name, $product->get_id())) { // Remove the attribute from the variation title $include_attributes = false; } return $include_attributes;}
i corrected this code its work but issue is its only hide the attrrbute term then i can add to cart becuase its still trigger
Hi there @tayyba11 👋
Thank you for contacting Woo support!
when you select subscribe and save there is this attribute which i want to hide
From what I gather, this refers to subscription functionality at your store.
Just to note, the product types that are supported in this forum are detailed here.
Feel free to reach out to the support channel of the plugin enabling the subscription functionality at the site at https://patrickc103.sg-host.com/product/calm-oil/, as they would be in a better position to assist you.
I trust that points you in the right direction, but if you have more questions, let us know.
We’re happy to help.
The topic ‘went to hide specific attributes term’ is closed to new replies.