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.


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.


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

1 Answer 1


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


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


an example would be like :


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

  • Dear @Mohamed, Thank you very much, when I read your code, the logic seems to be good but when I tried, it, there is no change to the return URL. Also, there is NO error when I did a test order. What could I be doing wrong? Can you please tell me.
    – Dave
    Dec 20, 2016 at 23:16
  • @Dave I have seen some gateway plugins use a different method to get return url by invoking which is $order->get_checkout_order_received_url() ; which applies the filter "woocommerce_get_checkout_order_received_url" . maybe you should try hooking override function to this filter instead , or check gateway plugin to find out which hook it uses to get return url Dec 22, 2016 at 0:05
  • Would you please update this filter also in your Answer that way others can also find it. Thank you so much
    – Dave
    Dec 22, 2016 at 21:00
  • Glad it worked for you ,I have added that filter to my answer :) Dec 24, 2016 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.