How To Override A WooCommerce AJAX Function


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!

, , Ryan Dorn 7 months 0 Answers 98 views 0

Leave an answer