自定义订单在 Woocommerce 中收到返回 URL 查询参数 [英] Custom Order received return URL query args in Woocommerce
问题描述
每当我使用 Woocommerce 下订单时,我都会得到一个带有几个参数的 URL.看起来像这样 -> /order-received/12240/?key=wc_order_5bf66c9ea4f0a
Wehenever I place an order using Woocommerce I get an URL with a few parameters. It looks like this -> /order-received/12240/?key=wc_order_5bf66c9ea4f0a
我想在此 URL 中添加一些我自己的内容.但是我找不到这个 URL 是在哪里生成的.
I would like to add a few of my own to this URL. But i cant find where this URL is generated.
我尝试了什么:
将 add_query_arg( 'foo', 'bar' )
添加到thank-you.php 文件中.没有工作.
to add add_query_arg( 'foo', 'bar' )
to the thank-you.php file. Didnt work.
也试过:
add_action('woocommerce_checkout_order_processed','my_function');
function my_function() {
add_query_arg( 'foo', 'bar' );
}
推荐答案
您需要使用专用的 woocommerce_get_return_url
过滤器钩子.索姆支付网关也可以使用 woocommerce_get_checkout_order_received_url
过滤钩.
You need to use the dedicated woocommerce_get_return_url
filter hook.
Somme payment gateways can also use woocommerce_get_checkout_order_received_url
filter hook.
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 文件中.经测试有效.
Code goes in functions.php file of your active child theme (or active theme). tested and works.
您将获得:/order-received/12345/?key=wc_order_ab12cd45efg678&foo=bar&fruit=apple
这篇关于自定义订单在 Woocommerce 中收到返回 URL 查询参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!