Skip to content

Instantly share code, notes, and snippets.

@Kenshino
Created August 22, 2014 03:06
Show Gist options
  • Save Kenshino/9cf053d4845e7696ff59 to your computer and use it in GitHub Desktop.
Save Kenshino/9cf053d4845e7696ff59 to your computer and use it in GitHub Desktop.
Unset product post type from categories
function unset_preorder_terms( $product ) {
if ( is_object( $product ) )
$product = $product->id;
$terms = wp_get_post_terms($product, 'product_cat');
$term_ids = array();
foreach ( $terms as $term ){
if ( strpos($term->slug, 'pre-order') === false ){
$term_ids[] = $term->term_id;
}
}
wp_set_post_terms( $product, $term_ids, 'product_cat');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment