Append order and order items parameters in Order r

2019-08-15 19:23发布

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:

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) { } }

1条回答
甜甜的少女心
2楼-- · 2019-08-15 19:32

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

查看更多
登录 后发表回答