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?

  • it is harder to help if you don't show the code that doesn't work Nov 14, 2015 at 18:29
  • I was looking for (new) code that works, not repairing existing code. I just found my answer below... wp_remove_object_terms() Nov 14, 2015 at 21:04

1 Answer 1


wp_remove_object_terms( $product_id, 'Aanbiedingen', 'product_cat' );


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.