I want to run some code after a product category is deleted, in that function I want to access the name of the deleted category, and according to their docs I could do this:
add_action('delete_product_cat', 'sync_cat_delete', 10, 1);
function sync_cat_delete($term, $tt_id, $deleted_term, $object_ids){
var_dump($deleted_term);
}
But when I do it, I get 500 internal server error
So what could be the issue?
Thanks
I want to run some code after a product category is deleted, in that function I want to access the name of the deleted category, and according to their docs I could do this:
add_action('delete_product_cat', 'sync_cat_delete', 10, 1);
function sync_cat_delete($term, $tt_id, $deleted_term, $object_ids){
var_dump($deleted_term);
}
But when I do it, I get 500 internal server error
So what could be the issue?
Thanks
You get 500 error, because you’ve added your filter incorrectly... It takes 4 params, but you register it as it was using only one.
add_action('delete_product_cat', 'sync_cat_delete', 10, 1);
// 10 is priority, 1 is number of params to take
function sync_cat_delete($term, $tt_id, $deleted_term, $object_ids){
var_dump($deleted_term);
}
So if you change that 1 to 4, it should be OK.
add_action
call specifies only a single function parameter (1
) but your function actually takes 4 parameters – Tom J Nowell ♦ Commented Dec 31, 2018 at 17:004
, not1
in youradd_action()
. – Jacob Peattie Commented Jan 1, 2019 at 1:55