Woocommerce create_category hook not working for product categories

So I want to hook into create_category and edit_category for products in WooCommerce. However it seems like it’s not using these hooks when creating / editing categories?

I know the hooks work for standard categories for stuff like blog posts.

Read More

It seems weird because for products itself I can just use the standard hooks for posts like transition_post_status and delete_post etc.

Does it use a different hook for product categories specific or does it not at all? Is there a way to do this?

Here’s just a little code I used to try the hook out:

add_action('create_category', 'sync_product_category', 10, 1);
function sync_product_category( $catid ) {
    $category = get_category($catid);
    error_log('category created');
}

it logs to the error_log.log fine when I create a category from blog posts, but when I create one in WooCommerce, it doesn’t show up.

Related posts

Leave a Reply

1 comment

  1. To hook into woocommerce product category creation use this line:

    add_action('create_product_cat', 'sync_product_category', 10, 1);
    

    The action you want to hook into is do_action( "create_$taxonomy", $term_id, $tt_id ); in the function wp_insert_term in wp-includes/taxonomy.php. The value of $taxonomy in your case is ‘product_cat’.