In woocommerce, we allow to buy only one product at the time on our shop. We have very few products and no shop page (or archives pages). Quantity fields are disabled and customer is redirected to checkout on add to cart.
We need to customize some URLs to detect what has been added to cart (what has been bought). So I would need to propagate the product SKU Checkout and Order received URLs.
I was able, for example, to add the SKU in the THANK YOU URL with this code:
add_filter('woocommerce_get_checkout_order_received_url','override_return_url',10,2);
function override_return_url($return_url,$order){
// create empty array to store url parameters in
$sku_list = array();
// retrieve 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;
}
But I need the SKU in the checkout URL too.
For information I have multiple kinds of Add to cart buttons on a product page:
- The woocommerce default one.
- Some others in the product content using Shortcode like
[add_to_cart id="99"]
- one last using Sticky add to cart for WooCommerce plugin.
Is it possible? How should I do?