Saturday, December 24, 2022
HomeWordPress Developmentphp - How do I unset class from a product in wordpress...

php – How do I unset class from a product in wordpress by code


To take away all class from a WooCommerce product, you need to use the wp_set_object_terms() perform.

Right here is an instance of how you need to use wp_set_object_terms() to take away classes from a product:

// Set the product's classes to an empty array
$classes = array();

wp_set_object_terms( $product->ID, $classes, 'product_cat' );

If you wish to take away a particular class, you need to use the wp_remove_object_terms() perform as a substitute. This perform permits you to take away particular phrases from an object.

Right here is an instance of how you need to use wp_remove_object_terms() to take away a particular class from a product:

// Set the class ID to take away
$category_id = 123;

// Take away the class from the product
wp_remove_object_terms( $product->ID, $category_id, 'product_cat' );

This code will take away the class with an ID of 123 from the present product

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments