【问题标题】:Custom Order received return URL query args in Woocommerce自定义订单在 Woocommerce 中收到返回 URL 查询参数
【发布时间】:2019-04-24 21:57:01
【问题描述】:

每当我使用 Woocommerce 下订单时,我都会得到一个带有一些参数的 URL。看起来像这样 -> /order-received/12240/?key=wc_order_5bf66c9ea4f0a

我想在此 URL 中添加一些我自己的。但是我找不到这个 URL 的生成位置。

我尝试了什么:

将add_query_arg( 'foo', 'bar' ) 添加到thank-you.php 文件中。没用。

也试过了:

add_action('woocommerce_checkout_order_processed','my_function');
function my_function() {
     add_query_arg( 'foo', 'bar' );
}

【问题讨论】:

    标签: php wordpress woocommerce payment-gateway returnurl


    【解决方案1】:

    您需要使用专用的woocommerce_get_return_url 过滤器挂钩。 索姆支付网关也可以使用woocommerce_get_checkout_order_received_url 过滤钩。

    add_filter( 'woocommerce_get_return_url', 'customize_get_return_url', 10, 2 );
    add_filter( 'woocommerce_get_checkout_order_received_url', 'customize_get_return_url', 10, 2 );
    function customize_get_return_url( $return_url, $order ){
        $query_args = array(
            'foo' => 'bar',
            'fruit' => 'apple',
        );
        return add_query_arg( $query_args, $return_url );
    }
    

    代码在您的活动子主题(或活动主题)的functions.php 文件中。经过测试并且有效。

    你会得到:/order-received/12345/?key=wc_order_ab12cd45efg678&foo=bar&fruit=apple

    【讨论】:

      猜你喜欢
      • 2017-11-11
      • 1970-01-01
      • 2017-04-18
      • 2014-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-28
      • 2018-07-12
      相关资源
      最近更新 更多