The url currently looks like this,
site.com/checkout/order-received/827/?key=wc_order_AN9woFNlCBbXM&product_id=211
I understand that 827 is the order number, but I need it as a string in order to pass data to a form.
I can get the product id in the URL but i can't seem to add the order number. Is there a better solution? How can I add both query strings? Any help is appreciated.
add_filter( 'woocommerce_get_checkout_order_received_url', 'custom_add_product_id_in_order_url', 10, 2 );
function custom_add_product_id_in_order_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_id'] = $product->get_id();
}
// 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;
}