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

  • where exactly would this be displaying? – rudtek Dec 31 '18 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 Dec 31 '18 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 Dec 31 '18 at 17:00
  • @TomJNowell I figured that much, but according to the docs developer.wordpress.org/reference/hooks/delete_taxonomy there should be 4 parameters. – AL-Kateb Dec 31 '18 at 19:01
  • 1
    So you need to change the number of parameters to 4, not 1 in your add_action(). – Jacob Peattie Jan 1 at 1:55
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.

  • 1
    I just realized what this parameter does :facepalm: – AL-Kateb Jan 1 at 13:11

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.