It’s been a long while since I last posted anything related to coding. I haven’t really stopped, but from Android app development, I switched back to PHP. Life has become occupied with other things, but when I do code, it’s in WordPress with WooCommerce. It’s for my online shop.
In my opinion, WordPress is not the most pleasant platform to use if you’re a developer (after years of MVC coding for Android I find WordPress quite messy), but it’s what I already know. I don’t have time to learn another.
Today’s code snippet is for customizing the Thank You page (post-checkout) by retrieving the “order” object.
1 2 3 4 5 6 7 8 |
<?php add_action('woocommerce_thankyou', 'thankyou_page_insert_order_details', 11); function thankyou_page_insert_order_details($order_id) { $order = wc_get_order($order_id); echo 'Thank you for ordering, ' . $order->get_billing_first_name() . '!'; } |
The $order_id
is what we’ll start with. Then we get the order object with the help of the wc_get_order($order_id)
method. Once you’re able to successfully call the order object, you may use its methods such as get_billing_first_name()
to get the order details.
You may refer to the WC_Order class page for a list of available methods.
I originally got this code from Order Received (Thank you) page in WooCommerce and modified it to suit my needs. Check his blog out, as he has many helpful posts on how to customize WooCommerce!