Hi there
I would like to display the order ID as a variable within a shortcode on the woocomerce thank you page:
hidden link
(12345 in the url above is the order ID)
In my child theme's function.php file:
OPTION 1.
I could get the order ID from the url and create a shortcode that displays the order ID:
add_shortcode( 'fforderid', 'get_order_id_thankyou');
function get_order_id_thankyou( $atts ) {
if( ! is_wc_endpoint_url( 'order-received' ) )
return;
global $wp;
$order_id = absint( $wp->query_vars['order-received'] );
if ( empty($order_id) || $order_id == 0 )
return;
return '. $order_id .';
}
OPTION 2.
I could also get the order ID and just display it like this:
add_action('woocommerce_thankyou', 'get_order_id_thankyou');
function get_order_id_thankyou(){
if ( is_wc_endpoint_url( 'order-received' ) ) {
global $wp;
$current_order_id = intval( str_replace( 'checkout/order-received/', '', $wp->request ) );
echo $current_order_id;
}
}
THE PROBLEM
The problem is that I want to display that ID in a shortcode with this function:
add_action( 'woocommerce_thankyou', 'add_shortcode_to_thankyou', 10, 1 );
function add_shortcode_to_thankyou( $order_id ) {
echo do_shortcode("[wpv-view name='name-of-my-view' id='ORDER-ID-GOES-HERE']");
}
This nested idea doesn't work for example:
echo do_shortcode("[wpv-view name='name-of-my-view' id='<?php echo do_shortcode('[fforderid]'); ?>']");
I have tried a thousand other ideas but none work...
Hoping you can help me figure out how to get that order ID into the shortcode as the 'id' variable.
Thanks in advance!
Rita

Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Hello. Thank you for contacting the Toolset support.
Based on the custom code you shared, have you tried to register the shortcode name "fforderid" (without quotes) at:
=> Toolset => Settings => Frontend Content tab => Third-party shortcode arguments
More info:
- https://toolset.com/documentation/legacy-features/views-plugin/shortcodes-within-shortcodes/
Hi Minesh
Yes. I have the shortcode registered in Toolset.
I did some further tests to review 'presumptions' and double check...
If I add this in functions.php to check that the shortcode is actually getting the id number:
add_action( 'woocommerce_thankyou', 'display_shortcode', 10, 1 );
function display_shortcode( $order_id ) {
echo do_shortcode("[fforderid]");
}
This is displayed:
. $order_id .
So actually my code is not getting the order ID number afterall...
Where am I going wrong...

Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
I need problem URL where I can see the issue and exact steps I will have to follow that should help me to see the issue as well as admin access details.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.

Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
I will require FTP access details in order to access and make edits to the functions.php file.
Can you please send me FTP access details.
I have set the next reply to private which means only you and I have access to it.
Hi Minesh
Are you not able to edit that functions.php file right there?
That's what I do...
Rita

Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
I can but that's not recommended. For instance, if I make edit directly to functions.php file using the WordPress editor and if by chance there will be error the whole site will be down and I will not be able to revert the changes and eventually I will require FTP access details at that time. Better you could share that for now.
I have set the next reply to private which means only you and I have access to it.

Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Still the FTP/SFTP access details you shared is not working at this end. Can you please send me working FTP/SFTP access details.
I have set the next reply to private which means only you and I have access to it.