WooCommerce: Use PayPal with notify_URL

2019-09-15 16:04发布

问题:

I am setting up a webshop using WordPress and WooCommerce. I want to use it to sell software which uses some copy protection. So when the customer buys the software he should receive an individual licence code by e-mail.

What actually works: I can create a PayPal "buy now" button, enter my product ID there and define the variable "notify_url" to the url of my licensing server. This works well but I don't want to use a "buy now" button.

Instead I would like to integrate it into the shop system WooCommerce. I managed to setup the PayPal Standard process there but what is missing is the interaction with the licensing server.

So my question is: How can I configure WooCommerce so that my licensing server is contacted by PayPal or WooCommerce with information of the purchase, the product ID and the customers e-mail address in order to generate the license key and send it to the customer?

thank you very much!

回答1:

You can use PayPal IPN

OR

Hook into WooCommerce hook woocommerce_order_status_completed or woocommerce_payment_complete_order_status

Example:

add_action( 'woocommerce_order_status_completed', 'your_func', 10, 1 ); 

function your_func($order_id) { 

    $order = new WC_Order( $order_id );
    /* Do Something with order ID or somthing related to it*/

}