Ecommerce Shopify WordPress Discussion

Get user latest WooCommerce order ID to use it with Contact Form 7

On my website, when someone orders a specific product, he is redirected (using the “Thanks You URL” field in the product data) to a page where the customer have to fill out a form (made with Contact Form 7 obviously). What I would want is to get the latest order ID from the customer (knowing that he has to be logged in to order) and put it in the email sent to me and the customer when the form is filled. Any idea on how someone could do that ? Thanks ! I'm quite bad at this and couldn't find anything related to this specific question unfortunately.
To get the last order from a logged in customer, you can use the following code: $customer_orders = wc_get_orders([ 'limit' => 1, 'type' => 'shop_order', 'status' => wc_get_is_paid_statuses(), 'customer' => get_current_user_id(), 'order' => 'DESC', ]); if ( ! empty($customer_orders) ) { $order = reset($customer_orders); // Last order object // Display the order ID (for example) echo '<p>Order ID: ' . $order->get_id() . '</p>'; } else { echo '<p>There is no orders yet</p>'; } There are already some threads in Stack OverFlow showing how to add a variable value to a Contact Form 7 field… Related: Pass some WooCommerce product data to Contact Form 7 enquiry form How to send a woocommerce cart items in CF7 form email How to get WooCommerce order details Get Order items and WC_Order_Item_Product in WooCommerce 3

December 29, 2023

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.