paypal - How to change or add Woocommerce thank you page URL key content?

I have searched enough and I did not find an answer for this question but this may be a simple one.In analytics, I want

I have searched enough and I did not find an answer for this question but this may be a simple one.

In analytics, I want to set up goals for purchase and we have only 5 products, so each product purchase should be a separate goal.

The easy way to set purchase goal in Analytics is to supply thank you URL. Now, Woocommerce thank you URL includes important details in the thank you URL like below.

exampledomain/?key=wc_order_584a9caad78bc&amt=239.00&cc=USD&charset=windows-1252&cm={"order_id":13586,"order_key":"wc_order_584a9caad78bc"}&st=Completed&tx=2AF5736382483492L

This is how Paypal payment thank you pages are shown.

But when a user makes purchase directly on the site with gateways like 2checkout, moneris, stripe, I get the below URL type.

exampledomain/?key=wc_order_5849993d6ec72

As you can see above, this URL does not contain a lot of parameter for me to use.

The question is, How do I edit these URLs to include product SKU?

This way, it will be easy for me to filter based on SKU

I have searched enough and I did not find an answer for this question but this may be a simple one.

In analytics, I want to set up goals for purchase and we have only 5 products, so each product purchase should be a separate goal.

The easy way to set purchase goal in Analytics is to supply thank you URL. Now, Woocommerce thank you URL includes important details in the thank you URL like below.

exampledomain/?key=wc_order_584a9caad78bc&amt=239.00&cc=USD&charset=windows-1252&cm={"order_id":13586,"order_key":"wc_order_584a9caad78bc"}&st=Completed&tx=2AF5736382483492L

This is how Paypal payment thank you pages are shown.

But when a user makes purchase directly on the site with gateways like 2checkout, moneris, stripe, I get the below URL type.

exampledomain/?key=wc_order_5849993d6ec72

As you can see above, this URL does not contain a lot of parameter for me to use.

The question is, How do I edit these URLs to include product SKU?

This way, it will be easy for me to filter based on SKU

Share Improve this question asked Dec 14, 2016 at 19:32 DaveDave 731 gold badge1 silver badge4 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 4

you can edit the return url woocommerce provides to gateways by using the filter

woocommerce_get_return_url

some gateway plugins use a different method to get return url by invoking $order->get_checkout_order_received_url() ; which applies the filter

woocommerce_get_checkout_order_received_url

an example would be like :

add_filter('woocommerce_get_return_url','override_return_url',10,2);

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();
    }
    //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;

    return $modified_url;

  }

result url will be like

http://example/index.php/checkout/order-received/161/?key=wc_order_585214b2abb65&product_8=SKU1&product_45=SKU2

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744850686a4597107.html

相关推荐

  • paypal - How to change or add Woocommerce thank you page URL key content?

    I have searched enough and I did not find an answer for this question but this may be a simple one.In analytics, I want

    2天前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信