简体   繁体   English

下订单后强制Woocommerce打开感谢页面

[英]Force Woocommerce open thankyou page after Placed order

I want to add an action right after customers placed an order (push order detail to api) I'm using woocommerce_thankyou hook to add my custom scripts But It always shows Order received page instead of thankyou page Please tell me the way to resolve this. 我想在客户下订单后立即添加操作(将订单详细信息推送到api)我正在使用woocommerce_thankyou挂钩添加我的自定义脚本,但是它始终显示“已收到订单”页面而不是“谢谢”页面。请告诉我解决此问题的方法。 Here is my code: 这是我的代码:

add_action('woocommerce_thankyou', 'push_order', 1, 1);
function push_order($order_id) {
    try {
        $logger = new WC_Logger();
        $logger->add("push-order-to-sap", "Start pushing order id: {$order_id}");
        $order = wc_get_order($order_id);
        $xml = order_mapping($order);
        die;
        $push = call_api(
            <endpoint>,
            $xml,
            'order'
        );
        $logger->add("push-order-to-sap", "Pushing result: {$push}");
    } catch (Exception $e) {
        $logger->add("push-order-to-sap", "ERROR: ".$e->getMessage());
    }
    return;
}

Good Evening 晚上好

May i hope my answer will help you to solve out your query, 我希望我的回答可以帮助您解决您的查询,

add_action( 'woocommerce_thankyou', 'custom_redirect'); 

function custom_redirect( $order_id ){
  $order = new WC_Order( $order_id );
  $url = 'http://yoursite.com/custom-url';
  if ( $order->status != 'failed' ) {
      wp_redirect($url);
      exit;
    }
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 woocommerce_thankyou 页面中保存了 API 的订单 - saved order at API in woocommerce_thankyou page 结帐后 Woocommerce 感谢页面不起作用 - Woocommerce thankyou page is not working after checkout 在 WooCommerce “收到订单”谢谢页面上获取订单 ID - Get the order id on WooCommerce “Order received” Thankyou page WooCommerce:如果请求不带订单的thankyou页面,则重定向到购物车页面 - WooCommerce: Redirecting to cart page if thankyou page is requested without an order 在“收到的WooCommerce订单(谢谢)”页面中检查新客户 - Check for new customers in WooCommerce Order received (Thankyou) page WooCommerce-在“谢谢”订单接收页面上自定义“总计”文本 - WooCommerce - Customize “Total” text on Thankyou order received page 根据订单状态更改 WooCommerce 感谢页面标题 - Change WooCommerce thankyou page title based on order status 发送订单确认 email 通知 WooCommerce 谢谢 - Send Order Confirmation email notification in WooCommerce thankyou 显示自定义动态字段存储数据 woocommerce 订单管理和来自元的感谢页面。? - Display custom dynamic fields stored data woocommerce order admin and thankyou page from meta.? 在感谢页面 WooCommerce 上获取 cookie 值 - Getting cookie value on thankyou page WooCommerce
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM