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.
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.
To hook into woocommerce product category creation use this line:
The action you want to hook into is
do_action( "create_$taxonomy", $term_id, $tt_id );
in the functionwp_insert_term
inwp-includes/taxonomy.php
. The value of$taxonomy
in your case is ‘product_cat’.