在订单收到的回叫网址中附加订单和订单商品参数 [英] Append order and order items parameters in Order received callback URL
问题描述
function override_return_url($ return_url,$ order){
//创建空数组以存储url参数到
$ sku_list = array();
//订购产品
foreach($ order-> get_items()as $ key => $ item)
{
$ product = wc_get_product ($项[ 'PRODUCT_ID']);
//获取每个产品的sku并将其插入数组
$ sku_list ['product _'。$ item ['product_id']。 'sku'] = $ product-> get_sku();
$ lolo =66;
$ order_id = $ order-> get_user_id();
$ order_data = $ order-> get_data(); //订单数据
$ order_billing_country = $ order_data ['billing'] ['country'];
$ order_payment_method = $ order_data ['payment_method'];
$ b foreach($ order-> get_items()as $ item){
$ product_name = $ item ['name'] ;
$ b foreach($ order-> get_items()as $ item){
//获取订单商品数据(在不受保护的数组中)
$ item_data = $ item-> get_data();
//获取订单商品元数据(在不受保护的数组中)
$ item_meta_data = $ item-> get_meta_data();
$ //在SKU数组中创建查询字符串
$ url_extension = http_build_query($ sku_list);
//将我们的字符串追加到原始网址
$ modified_url = $ return_url。'&'。$ url_extension。'&'。$ lolo。'&'。$ order_id。'&' 。$ order_billing_country '和;'。$ order_payment_method。 '和;' $ PRODUCT_NAME。 '和;' $ item_meta_data。
返回$ modified_url;
}
我非常接近尝试设置正确的网址参数...
结果如下:> http:// localhost / checkout / order-received / 701 /?key = item_671sku =& 66& 1& MY& wc_dummy_gateway& helo& Array
在URL item_meta_data的最后部分,只有价值阵列不是真正的价值。
任何帮助表示赞赏。
(我认为这与不受保护的数组或其他东西有关。)
============================================
添加了更多信息
基本上,我想将这些元数据捕获到URL p>
结帐屏幕快照:
我试图让URL看起来像这样:
http:// localhost / motio /结帐/订单接收/ 707 /键= wc_order_5ac0d4c435662&安培; product_671sku =安培; 66&安培; 707&安培; MY&安培; wc_dummy_gateway&安培; VBID = VBID-0a1141f2-s9wyooko&安培;昵称= usernickname&安培; email=useremail@email.com&域=用户域.com& offer_name = annual& offer_id = 5& subscription_id = 9
注意:我也想剥离out http:// www 为& domain =参数
vbid:vbid-0a1141f2-s9wyooko
昵称:usernickname
电子邮件:useremail@email.com
域名: http://www.user-domain。
优惠名称:每年
offer_id:5
subscription_id:9
Var_Dump数据
object(WC_Cart)#986(11){[cart_contents] => array(0){} [removed_cart_contents] => array(0){} [applied_coupons] => array(0){} [tax_display_cart] =>字符串(4)excl[shipping_methods:protected] => NULL [default_totals:protected] =>数组(15){[小计] => int(0)[subtotal_tax] => int(0)[shipping_total] => int(0)[shipping_tax] => int(0)[shipping_taxes] => array(0){} [discount_total] => int(0)[discount_tax] => int(0)[cart_contents_total] => int(0)[cart_contents_tax] => int(0)[cart_contents_taxes] => array(0){} [fee_total] => int(0)[fee_tax] => int(0)[fee_taxes] => array(0){} [total] => int(0)[total_tax] => int(0)} [totals:protected] => array(0){} [session:protected] =>对象(WC_Cart_Session)#987(1){[cart:protected] => * RECURSION *} [fees_api:protected] => object(WC_Cart_Fees)#988(3){[fees:WC_Cart_Fees:private] => array(0){} [cart:WC_Cart_Fees:private] => * RECURSION * [default_fee_props:WC_Cart_Fees:private] => array(6){[id] =>字符串(0)[name] =>字符串(0)[tax_class] =>字符串(0)[taxable] => bool(false)[amount] => int(0)[total] => int(0)}} [cart_session_data] => array(15){[cart_contents_total] => int(0)[total] => int(0)[小计] => int(0)[subtotal_ex_tax] => int(0)[tax_total] => int(0)[taxes] => array(0){} [shipping_taxes] => array(0){} [discount_cart] => int(0)[discount_cart_tax] => int(0)[shipping_total] => int(0)[shipping_tax_total] => int(0)[coupon_discount_amounts] => array(0){} [coupon_discount_tax_amounts] => array(0){} [fee_total] => int(0)[费用] => array(0){}} [coupon_applied_count] =>数组(0){}}
p>
$ modified_url = $ return_url。'&'。$ url_extension。'&'。$ lolo。'&'。$ ORDER_ID。 '和;'。$ order_billing_country '和;'。$ order_payment_method。 '和;' $ PRODUCT_NAME '和;'。$ item_meta_data; b
$ modified_url = $ return_url。'&'。$ url_extension。'&'。$ lolo。'&'。$ order_id。'&'。$ order_billing_country。'&'。$ order_payment_method。 '和;'。$ PRODUCT_NAME '和;'。http_build_query($ item_meta_data)。
如果这样不能解决您的问题,请分享 var_dump()
变量 $ item_meta_data
In Woocommerce, I'm trying to get parameters values from order received (thankyou) URL, in the code below:
function override_return_url($return_url,$order){
//create empty array to store url parameters in
$sku_list = array();
// retrive products in order
foreach($order->get_items() as $key => $item)
{
$product = wc_get_product($item['product_id']);
//get sku of each product and insert it in array
$sku_list['product_'.$item['product_id'] . 'sku'] = $product->get_sku();
$lolo = "66";
$order_id = $order->get_user_id();
$order_data = $order->get_data(); // The Order data
$order_billing_country = $order_data['billing']['country'];
$order_payment_method = $order_data['payment_method'];
}
foreach($order->get_items() as $item) {
$product_name = $item['name'];
}
foreach( $order->get_items() as $item ){
// get order item data (in an unprotected array)
$item_data = $item->get_data();
// get order item meta data (in an unprotected array)
$item_meta_data = $item->get_meta_data();
}
}
//build query strings out of the SKU array
$url_extension = http_build_query($sku_list);
//append our strings to original url
$modified_url = $return_url.'&'.$url_extension.'&'.$lolo.'&'.$order_id.'&'.$order_billing_country.'&'.$order_payment_method.'&'.$product_name.'&'.$item_meta_data;
return $modified_url;
}
I'm very near trying to set the right url parameters…
This is the result : http://localhost/checkout/order-received/701/?key=wc_order_5ac08e6fef335&product_671sku=&66&1&MY&wc_dummy_gateway&helo&Array
At the last part of the URL item_meta_data, I only get value "Array" not the real value.
Any help is appreciated.
(I think it's something to do with unprotected array or something..)
============================================
added more info
Basically, I want to capture these meta data onto the URL
CHECKOUT SCREENSHOT:
I'm trying to make the URL looks like this :
http://localhost/motio/checkout/order-received/707/?key=wc_order_5ac0d4c435662&product_671sku=&66&707&MY&wc_dummy_gateway&vbid=vbid-0a1141f2-s9wyooko&nickname=usernickname&email=useremail@email.com&domain=user-domain.com&offer_name=yearly&offer_id=5&subscription_id=9
note : i also want to strip out the http://www for the &domain= parameters
vbid:vbid-0a1141f2-s9wyooko nickname:usernickname email:useremail@email.com domain:http://www.user-domain.com offer name:yearly offer_id:5 subscription_id:9
Var_Dump Data
object(WC_Cart)#986 (11) { ["cart_contents"]=> array(0) { } ["removed_cart_contents"]=> array(0) { } ["applied_coupons"]=> array(0) { } ["tax_display_cart"]=> string(4) "excl" ["shipping_methods":protected]=> NULL ["default_totals":protected]=> array(15) { ["subtotal"]=> int(0) ["subtotal_tax"]=> int(0) ["shipping_total"]=> int(0) ["shipping_tax"]=> int(0) ["shipping_taxes"]=> array(0) { } ["discount_total"]=> int(0) ["discount_tax"]=> int(0) ["cart_contents_total"]=> int(0) ["cart_contents_tax"]=> int(0) ["cart_contents_taxes"]=> array(0) { } ["fee_total"]=> int(0) ["fee_tax"]=> int(0) ["fee_taxes"]=> array(0) { } ["total"]=> int(0) ["total_tax"]=> int(0) } ["totals":protected]=> array(0) { } ["session":protected]=> object(WC_Cart_Session)#987 (1) { ["cart":protected]=> *RECURSION* } ["fees_api":protected]=> object(WC_Cart_Fees)#988 (3) { ["fees":"WC_Cart_Fees":private]=> array(0) { } ["cart":"WC_Cart_Fees":private]=> *RECURSION* ["default_fee_props":"WC_Cart_Fees":private]=> array(6) { ["id"]=> string(0) "" ["name"]=> string(0) "" ["tax_class"]=> string(0) "" ["taxable"]=> bool(false) ["amount"]=> int(0) ["total"]=> int(0) } } ["cart_session_data"]=> array(15) { ["cart_contents_total"]=> int(0) ["total"]=> int(0) ["subtotal"]=> int(0) ["subtotal_ex_tax"]=> int(0) ["tax_total"]=> int(0) ["taxes"]=> array(0) { } ["shipping_taxes"]=> array(0) { } ["discount_cart"]=> int(0) ["discount_cart_tax"]=> int(0) ["shipping_total"]=> int(0) ["shipping_tax_total"]=> int(0) ["coupon_discount_amounts"]=> array(0) { } ["coupon_discount_tax_amounts"]=> array(0) { } ["fee_total"]=> int(0) ["fees"]=> array(0) { } } ["coupon_applied_count"]=> array(0) { } }
Change:
$modified_url = $return_url.'&'.$url_extension.'&'.$lolo.'&'.$order_id.'&'.$order_billing_country.'&'.$order_payment_method.'&'.$product_name.'&'.$item_meta_data;
to this:
$modified_url = $return_url.'&'.$url_extension.'&'.$lolo.'&'.$order_id.'&'.$order_billing_country.'&'.$order_payment_method.'&'.$product_name.'&'.http_build_query($item_meta_data);
if that doesn't solve your problem, please share var_dump()
of the variable $item_meta_data
这篇关于在订单收到的回叫网址中附加订单和订单商品参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!