Callback_handler will not launch WooCommerce

I am creating a payment gateway for WooCommerce where payment is made using an external URL. I need this page to be able to send messages back to the WooCommerce plugin, and the β€œcallback” URL is all I need.

WooCommerce seems to have this, but I can't get it to work. You must be able to ping:

http://yoursite/wc-api/WC_your_gateway

And then you should add add_action ('woocommerce_api_callback', 'callback_handler'); And then he should run such a function public function callback_handler () {}

But when I go to this URL, all I see is 1 on my page - my handler should redirect to another page (this is what I did to make it obvious). I would love it if someone has an example of this. I tried adding add_action and the handler function a lot of places, no luck.

+4
source share
3 answers

I have the same problem. Try adding exit; or wp_die (); at the end of your callback function.

This works for me.

+3
source

I had the same problem, so this is what worked for me:

class WC_mygateway extends WC_Payment_Gateway {
  public function __construct() {
    //'woocommerce_api_'.strtolower(get_class($this)) will result in 'woocommerce_api_wc_mygateway'
    add_action('woocommerce_api_'.strtolower(get_class($this)), array(&$this, 'handle_callback'));
  }
  function handle_callback() {
    //Handle the thing here!
  }
}

function woocommerce_mygateway_add_gateway( $methods ) {
  $methods[] = 'WC_mygateway';
  return $methods
}
add_filter( 'woocommerce_payment_gateways', 'woocommerce_mygateway_add_gateway');

, , . , http://example.com/?wc-api=wc_mygateway http://example.com/wc-api/wc_mygateway

, , !

+1

http://yoursite/wc-api/WC_your_gateway/ ( )?

add_action "woocommerce_api_ {class_name}" "woocommerce_api_callback". "woocommerce_api_wc_your_gateway".

0

Source: https://habr.com/ru/post/1543452/


All Articles