在Woocommerce中,我正在尝试从下面的代码中的订单收到(thankyou)URL中获取参数值:
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;
}
我非常接近设置正确的网址参数......
结果如下: http://localhost/checkout/order-received/701/?key=wc_order_5ac08e6fef335&product_671sku=&66&1&MY&wc_dummy_gateway&helo&Array
在URL item_meta_data的最后一部分,我只得到值“Array”而不是实际值。
感谢任何帮助。
(我认为这与未受保护的数组或其他东西有关..)
============================================
添加了更多信息
基本上,我想将这些元数据捕获到URL
结账放映:
我正在尝试将网址看起来像这样:
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
注意:我还要删除& domain = parameters
的http://wwwVBID:VBID-0a1141f2-s9wyooko 昵称:usernickname 电子邮件:useremail@email.com 域:http://www.user-domain.com 报价名称:每年 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"]=> 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) { } }
答案 0 :(得分:0)
变化:
$modified_url = $return_url.'&'.$url_extension.'&'.$lolo.'&'.$order_id.'&'.$order_billing_country.'&'.$order_payment_method.'&'.$product_name.'&'.$item_meta_data;
到此:
$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()
的{{1}}