Wocommerce Vnpay: Update status and empty cart
Gửi URL file php cho bên Vnpay sau đó chèn đoạn code sau vào file
- <?php
-
- require_once($_SERVER['DOCUMENT_ROOT'].'/wp-load.php');
- global $woocommerce;
- $txnResponseCode = $_GET["vnp_ResponseCode"];
- $order = new WC_Order($_GET["vnp_TxnRef"]);
- // echo $order = getOrder(864);
- $secureHash = $_GET["vnp_SecureHash"];
-
- if ($txnResponseCode == '00') {
- $woocommerce->cart->empty_cart();
- $returnData['RspCode'] = '00';
- $returnData['Message'] = 'Confirm Success';
- $returnData['Signature'] = $secureHash;
- $order->add_order_note(__($transStatus, 'woocommerce'));
- $order->update_status('completed');
- }
- else {
- $woocommerce->cart->empty_cart();
- $returnData['RspCode'] = '00';
- $returnData['Message'] = 'Confirm Success';
- $returnData['Signature'] = $secureHash;
- $order->add_order_note(__($transStatus, 'woocommerce'));
- $order->update_status('failed');
-
- }
- ?>