最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to find where an action is triggered?

programmeradmin3浏览0评论
Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 2 years ago.

Improve this question

As far as I understand about the action hook, add_action is used to add callback functions to an exsiting action hook, which means, to make lines like

add_action('some_action_hook',function(){ // some function})

work, you need to have a line that says do_action some_action_hook somewhere in your code. Is this understanding right?

I come across an action hook that I couldn't find where it is triggered: it is woocommerce's woocommerce_thankyou_bacs. I've done a thorough text search inside my website root folder for woocommerce_thankyou_bacs, the only line coming up is

add_action( 'woocommerce_thankyou_bacs', array( $this, 'thankyou_page' ) );

in \wp-content\plugins\woocommerce\includes\gateways\bacs\class-wc-gateway-bacs.php. I've also done a regex search for thankyou.*bacs, the result is same. I also search this action hook online and in Woocommerce's documentation, but didn't get much useful informations. This itself is trivial, but I'd like to know:

  1. Is the understanding that where there is a do_action, there must be a corresponding add_action correct, or at least generally correct?
  2. If 1) is correct, what is the solid way to find where do_action is for a certain action hook?
Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 2 years ago.

Improve this question

As far as I understand about the action hook, add_action is used to add callback functions to an exsiting action hook, which means, to make lines like

add_action('some_action_hook',function(){ // some function})

work, you need to have a line that says do_action some_action_hook somewhere in your code. Is this understanding right?

I come across an action hook that I couldn't find where it is triggered: it is woocommerce's woocommerce_thankyou_bacs. I've done a thorough text search inside my website root folder for woocommerce_thankyou_bacs, the only line coming up is

add_action( 'woocommerce_thankyou_bacs', array( $this, 'thankyou_page' ) );

in \wp-content\plugins\woocommerce\includes\gateways\bacs\class-wc-gateway-bacs.php. I've also done a regex search for thankyou.*bacs, the result is same. I also search this action hook online and in Woocommerce's documentation, but didn't get much useful informations. This itself is trivial, but I'd like to know:

  1. Is the understanding that where there is a do_action, there must be a corresponding add_action correct, or at least generally correct?
  2. If 1) is correct, what is the solid way to find where do_action is for a certain action hook?
Share Improve this question asked Feb 11, 2022 at 17:50 shenkwenshenkwen 1311 silver badge9 bronze badges 2
  • the action name can be assembled using variables, it doesn't have to be a static string, the WooCommerce documentation is the most appropriate place to look for the answer here. Also, you can add a function to an action that never gets called, and you can fire an action that is never hooked into. add_action( 'qjfberbierb fi', ... is still perfectly valid even though I mashed my keyboard to get the action name and it will never be ran. – Tom J Nowell Commented Feb 11, 2022 at 19:16
  • Also, WooCommerce and other 3rd party plugin dev support questions are off topic here, this stack isn't a place to get help with WooCommerce – Tom J Nowell Commented Feb 11, 2022 at 19:18
Add a comment  | 

1 Answer 1

Reset to default 2

In WooCommerce (my version v6.1.1) there is a file called /woocommerce/templates/checkout/thankyou.php and in line 79 you have trigger with dynamic payment method name so there is a place when each payment method do their magic

<?php do_action( 'woocommerce_thankyou_' . $order->get_payment_method(), $order->get_id() ); ?>

And answering your questions:

  1. The opposite. Where is add_action there is a corresponding do_action but i can be named dynamically just like we see it example above
  2. There is no 100% way to find each do_action because all hook names depends on creativity of developer. So i can be hard to find at first glance just like example above
发布评论

评论列表(0)

  1. 暂无评论