admin管理员组文章数量:1122846
I would like to override a WP (WooCommerce AJAX function) using add_filter.
The original code is set in a WC OOP class via something like:
add_action( 'wp_ajax_wc_function', array( $this, 'wc_do_stuff' ) );
add_action( 'wp_ajax_nopriv_wc_function', array( $this, 'wc_do_stuff' ) );
And wc_do_stuff
is a public function.
My question(s):
- What callback would I need to target?
- Is it possible to use add_filter to override an AJAX function; if so, how would I do so?
I've tried (i.e. override 'wc_do_stuff' with 'my_override_do_stuff' ...within my custom class):
// Tried this, doesn't work
add_filter( 'wc_do_stuff', array( $this, 'my_override_do_stuff' ), 20 );
// And this, also doesn't work
add_filter( 'wc_do_stuff', array('WC_Parent_Class', 'my_override_do_stuff'), 20);
Thanks in advance!
I would like to override a WP (WooCommerce AJAX function) using add_filter.
The original code is set in a WC OOP class via something like:
add_action( 'wp_ajax_wc_function', array( $this, 'wc_do_stuff' ) );
add_action( 'wp_ajax_nopriv_wc_function', array( $this, 'wc_do_stuff' ) );
And wc_do_stuff
is a public function.
My question(s):
- What callback would I need to target?
- Is it possible to use add_filter to override an AJAX function; if so, how would I do so?
I've tried (i.e. override 'wc_do_stuff' with 'my_override_do_stuff' ...within my custom class):
// Tried this, doesn't work
add_filter( 'wc_do_stuff', array( $this, 'my_override_do_stuff' ), 20 );
// And this, also doesn't work
add_filter( 'wc_do_stuff', array('WC_Parent_Class', 'my_override_do_stuff'), 20);
Thanks in advance!
Share Improve this question edited Jul 31, 2017 at 22:34 Ryan Dorn asked Jul 31, 2017 at 18:39 Ryan DornRyan Dorn 3499 silver badges23 bronze badges2 Answers
Reset to default 2Ok, so I don't know if this is the best way, but it's working for now.
Within my OOP class (I have a custom plugin to override a WC plugin):
remove_action( 'wp_ajax_wc_function', array( WC_Parent_Class, 'wc_do_stuff' ) );
remove_action( 'wp_ajax_nopriv_wc_function', array( WC_Parent_Class, 'wc_do_stuff' ) );
add_action( 'wp_ajax_wc_function', array( __CLASS__, 'my_override_do_stuff' ) );
add_action( 'wp_ajax_nopriv_wc_function', array( __CLASS__, 'my_override_do_stuff' )
Hope this helps someone and I'd welcome/appreciate if anyone has a better method. :)
Just a little something (I can't comment OP's answer as I don't have enough rep right now).
If you want to override a function of a Class in your functions.php without using a class yourself, just do :
remove_action( 'wp_ajax_wc_function', array( WC_Parent_Class, 'wc_function' ) );
add_action( 'wp_ajax_wc_function', 'your_new_function' ); // no need to array
本文标签: filtersHow To Override A WooCommerce AJAX Function
版权声明:本文标题:filters - How To Override A WooCommerce AJAX Function 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736309587a1934072.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论