【问题标题】:Update WooCommerce order status via WooCommerce callback通过 WooCommerce 回调更新 WooCommerce 订单状态
【发布时间】:2022-01-03 23:52:47
【问题描述】:

我创建了一个自定义支付网关插件,通过第三方支付网关满足 WooCommerce 网站订单的支付需求。一旦第三方收到客户的付款,它就会将发布数据发送到您指定的 URL,以便您可以处理/更新您的数据库。通过 Get 方法更新 WooCommerce 回调的订单状态有效,但不适用于 Post。

这就是我的工作

        add_action( 'woocommerce_api_callback', array( $this, 'thirdparty_response' ));  


        function thirdparty_response()
        {  
           global $woocommerce;

           if(isset($_POST['order_id']) && isset($_POST['order_status'])) //Parameters sent by third party gateway
           {
               $order_status = $_POST['order_status'];
               $order_id = $_POST['order_id'];
               $order = new WC_Order( $order_id );

               if ($order_status == "success") 
               {
                  $order->update_status('processing', __('Payment Received', 'woothemes'));
               }
               else
               {
                  $order->update_status('failed', __('Payment Failed', 'woothemes'));
               }

           }

        }

谢谢你,我希望你能帮助我。

【问题讨论】:

    标签: wordpress woocommerce


    【解决方案1】:

    您是否创建了网关类?这是来自 WC Paypal 网关的 sn-p,要激活 check_response,您必须配置您的第 3 方支付网关服务以回调您的 URL,如下所示(您需要在回调 URL 和钩子名称):

    $your_callback = str_replace( 'https:', 'http:', add_query_arg( 'wc-api', 'WC_Gateway_Paypal', home_url( '/' ) ) );
    
    public function __construct( $sandbox = false, $receiver_email = '' ) {
            add_action( 'woocommerce_api_wc_gateway_paypal', array( $this, 'check_response' ) );
            add_action( 'valid-paypal-standard-ipn-request', array( $this, 'valid_response' ) );
    
            $this->receiver_email = $receiver_email;
            $this->sandbox        = $sandbox;
        }
    

    【讨论】:

      猜你喜欢
      • 2022-11-04
      • 2017-05-24
      • 2017-07-16
      • 2021-01-17
      • 1970-01-01
      • 2018-01-01
      • 2019-02-01
      • 2022-09-30
      • 2016-10-17
      相关资源
      最近更新 更多