categories - How to access deleted term inside delete_product_cat action

admin2025-06-05  0

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

Share Improve this question asked Dec 31, 2018 at 16:16 AL-KatebAL-Kateb 1033 bronze badges 6
  • where exactly would this be displaying? – rudtek Commented Dec 31, 2018 at 16:22
  • It would be displayed in the ajax response when a category is deleted, I placed var_dump there just for testing purposes, I could read the output with fiddler, an HTTP debugger. – AL-Kateb Commented Dec 31, 2018 at 16:30
  • 1 I think your 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:00
  • @TomJNowell I figured that much, but according to the docs developer.wordpress/reference/hooks/delete_taxonomy there should be 4 parameters. – AL-Kateb Commented Dec 31, 2018 at 19:01
  • 1 So you need to change the number of parameters to 4, not 1 in your add_action(). – Jacob Peattie Commented Jan 1, 2019 at 1:55
 |  Show 1 more comment

1 Answer 1

Reset to default 1

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.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749054870a315969.html

最新回复(0)