What function of Woocommerce is called in response to IPN PayPal?

I'm having trouble figuring out which function is called when payment is completed using Woocommerce and PayPal sends an IPN.

It turns out IPN, because the PayPal log file is updated as soon as I click Pay , but I can’t figure out which function writes this file.

I need to find out if there is already built-in functionality for sending email to the administrator when an order is created and where it happens.

If it exists, I need to modify it to send a message to other people, and if not, then I need to create it myself, but I need to know where to put the code.

+4
source share
2 answers

Checking the file /wp-content/plugins/woocommerce/classes/gateways/paypal/class-wc-paypal.php , we see that there is an action hook inside the check_ipn_response function:

 if ($this->check_ipn_request_is_valid()) : header('HTTP/1.1 200 OK'); do_action("valid-paypal-standard-ipn-request", $_POST); 

You can connect to it as follows:

 add_action( 'valid-paypal-standard-ipn-request', 'so_12967331_ipn_response', 10, 1 ); function so_12967331_ipn_response( $formdata ) { // do your stuff } 
+10
source

Based on @brasofilo's answer, I had to do extra work for each product for the current order.

Note. I'm new to (un) data serialization, so I don't know why I had to abandon double quotes in order to get unserialize() to work. Otherwise, she threw an error. Maybe there is a better way to handle this.

 function so_12967331_ipn_response( $formdata ) { if ( !empty( $formdata['invoice'] ) && !empty( $formdata['custom'] ) ) { if( $formdata['payment_status'] == 'Completed' ) { if( is_serialized( $posted['custom'] ) ) { // backwards compatible // unserialize data $order_data = unserialize( str_replace('\"', '"', $posted['custom'] ) ); $order_id = $order_data[0]; } else { // custom data was changed to JSON at some point $order_data = (array)json_decode( $posted['custom'] ); $order_id = $order_data['order_id']; } // get order $order = new WC_Order( $order_id ); // got something to work with? if ( $order ) { // get user id $user_id = get_post_meta( $order_id, '_customer_user', true ); // get user data $user = get_userdata( $user_id ); // get order items $items = $order->get_items(); // loop thru each item foreach( $items as $order_item_id => $item ) { $product = new WC_Product( $item['product_id'] ); // do extra work... } } } } } 
+4
source

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


All Articles