Woocommerce 中的自定义订单收到 return URL 查询参数
Custom Order received return URL query args in Woocommerce
每当我使用 Woocommerce 下订单时,我都会收到带有一些参数的 URL。看起来像这样 -> /order-received/12240/?key=wc_order_5bf66c9ea4f0a
我想在此添加一些我自己的 URL。但是我找不到这个 URL 是在哪里生成的。
我尝试了什么:
将add_query_arg( 'foo', 'bar' )
添加到感谢-you.php 文件中。没有工作。
也尝试过:
add_action('woocommerce_checkout_order_processed','my_function');
function my_function() {
add_query_arg( 'foo', 'bar' );
}
您需要使用专用的 woocommerce_get_return_url
过滤器挂钩。
Somme 支付网关也可以使用 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 文件。已测试并有效。
You will get: /order-received/12345/?key=wc_order_ab12cd45efg678&foo=bar&fruit=apple
每当我使用 Woocommerce 下订单时,我都会收到带有一些参数的 URL。看起来像这样 -> /order-received/12240/?key=wc_order_5bf66c9ea4f0a
我想在此添加一些我自己的 URL。但是我找不到这个 URL 是在哪里生成的。
我尝试了什么:
将add_query_arg( 'foo', 'bar' )
添加到感谢-you.php 文件中。没有工作。
也尝试过:
add_action('woocommerce_checkout_order_processed','my_function');
function my_function() {
add_query_arg( 'foo', 'bar' );
}
您需要使用专用的 woocommerce_get_return_url
过滤器挂钩。
Somme 支付网关也可以使用 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 文件。已测试并有效。
You will get:
/order-received/12345/?key=wc_order_ab12cd45efg678&foo=bar&fruit=apple