Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Kamal\Jom;
- class GeneratePDF {
- public function __construct() {
- add_action( 'woocommerce_thankyou', 'get_order_data', 10, 1 );
- }
- public function get_order_data( $order_id ) {
- if ( !$order_id ) {
- return;
- }
- // Getting an instance of the order object
- $order = wc_get_order( $order_id );
- if ( $order->is_paid() ) {
- $paid = 'yes';
- } else {
- $paid = 'no';
- }
- // iterating through each order items (getting product ID and the product object)
- // (work for simple and variable products)
- foreach ( $order->get_items() as $item_id => $item ) {
- if ( $item['variation_id'] > 0 ) {
- $product_id = $item['variation_id']; // variable product
- } else {
- $product_id = $item['product_id']; // simple product
- }
- // Get the product object
- $product = wc_get_product( $product_id );
- }
- print_r( $order );
- // Ouptput some data
- echo '<p>Order ID: ' . $order_id . ' — Order Status: ' . $order->get_status() . ' — Order is paid: ' . $paid . '</p>';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement