I'm trying to do the following, but I'm stuck with coding. Hope someone can help me out here.
In Woocommerce (on the product-edit page) I can choose in which category the product will be. I made a code where the product will be put in an extra category 'Aanbiedingen' (id=87) upon save, when there are certain conditions.
if ( !empty ($_POST['sale_enddate']) && ($_POST['sale_begindate']) ) {
$cat_ids = array( 87 );
wp_set_object_terms( $product_id, $cat_ids, 'product_cat', true );
}
Now I would like to have a code where (upon save) the product will be removed from the 'Aanbiedingen' category, but it will still be in other categories.
Example: The product is in category 'Aanbiedingen', 'Comfort', 'Therapie' and 'Warmtezakken' Can someone help me with a code where (upon save) the product will only be in 'Comfort', 'Therapie' and 'Warmtezakken' ?
I guess it has something todo with getting categories with wp_get_object_terms
, removing value 'Aanbiedingen' (or id 87) and saving this altered array back with wp_set_object_terms
?
I tried several things, but I can't get it done. Can someone please help me?