WooCommerce: Get Order Info (total, items, etc) From $order Object

As a WooCommerce development freelancer, every day I repeat many coding operations that make me waste time. One of them is: “How to get ____ if I have the $order variable/object?“.

For example, “How can I get the order total“? Or “How can I get the order items“? Or maybe the order dates, customer ID, billing info, payment method, order status, and so on… hopefully this article will help you save time as well!

As we’ve seen in other articles, get product info from $product object and get cart info from $cart object, not always you can have direct access to the $order variable.

Sometimes, you may have the $order_id available for example. In that scenario, you can “get” the order object with the wc_get_order WooCommerce function.

It’s also possible to gain $order information if you are in an email template. This can be helpful to show additional $order information in your transactional communications or trigger custom functions. Either way, enjoy!

1. You have access to $order variable

Hooks (do_action and apply_filters) use additional arguments which are passed on to the function. If they allow you to use the “$order” object, you’re in business. Here’s how to get all the order information:

// Get Order ID and Key
$order->get_id();
$order->get_order_key();

// Get Order Totals
$order->get_formatted_order_total();
$order->get_cart_tax();
$order->get_currency();
$order->get_discount_tax();
$order->get_discount_to_display();
$order->get_discount_total();
$order->get_total_fees();
$order->get_formatted_line_subtotal();
$order->get_shipping_tax();
$order->get_shipping_total();
$order->get_subtotal();
$order->get_subtotal_to_display();
$order->get_tax_location();
$order->get_tax_totals();
$order->get_taxes();
$order->get_total();
$order->get_total_discount();
$order->get_total_tax();
$order->get_total_refunded();
$order->get_total_tax_refunded();
$order->get_total_shipping_refunded();
$order->get_item_count_refunded();
$order->get_total_qty_refunded();
$order->get_qty_refunded_for_item();
$order->get_total_refunded_for_item();
$order->get_tax_refunded_for_item();
$order->get_total_tax_refunded_by_rate_id();
$order->get_remaining_refund_amount();
 
// Get and Loop Over Order Items
foreach ( $order->get_items() as $item_id => $item ) {
   $product_id = $item->get_product_id();
   $variation_id = $item->get_variation_id();
   $product = $item->get_product(); // see link above to get $product info
   $product_name = $item->get_name();
   $quantity = $item->get_quantity();
   $subtotal = $item->get_subtotal();
   $total = $item->get_total();
   $tax = $item->get_subtotal_tax();
   $tax_class = $item->get_tax_class();
   $tax_status = $item->get_tax_status();
   $allmeta = $item->get_meta_data();
   $somemeta = $item->get_meta( '_whatever', true );
   $item_type = $item->get_type(); // e.g. "line_item", "fee"
}

// Other Secondary Items Stuff
$order->get_items_key();
$order->get_items_tax_classes();
$order->get_item_count();
$order->get_item_total();
$order->get_downloadable_items();
$order->get_coupon_codes();
 
// Get Order Lines
$order->get_line_subtotal();
$order->get_line_tax();
$order->get_line_total();
 
// Get Order Shipping
$order->get_shipping_method();
$order->get_shipping_methods();
$order->get_shipping_to_display();
 
// Get Order Dates
$order->get_date_created();
$order->get_date_modified();
$order->get_date_completed();
$order->get_date_paid();
 
// Get Order User, Billing & Shipping Addresses
$order->get_customer_id();
$order->get_user_id();
$order->get_user();
$order->get_customer_ip_address();
$order->get_customer_user_agent();
$order->get_created_via();
$order->get_customer_note();
$order->get_address_prop();
$order->get_billing_first_name();
$order->get_billing_last_name();
$order->get_billing_company();
$order->get_billing_address_1();
$order->get_billing_address_2();
$order->get_billing_city();
$order->get_billing_state();
$order->get_billing_postcode();
$order->get_billing_country();
$order->get_billing_email();
$order->get_billing_phone();
$order->get_shipping_first_name();
$order->get_shipping_last_name();
$order->get_shipping_company();
$order->get_shipping_address_1();
$order->get_shipping_address_2();
$order->get_shipping_city();
$order->get_shipping_state();
$order->get_shipping_postcode();
$order->get_shipping_country();
$order->get_address();
$order->get_shipping_address_map_url();
$order->get_formatted_billing_full_name();
$order->get_formatted_shipping_full_name();
$order->get_formatted_billing_address();
$order->get_formatted_shipping_address();
 
// Get Order Payment Details
$order->get_payment_method();
$order->get_payment_method_title();
$order->get_transaction_id();
 
// Get Order URLs
$order->get_checkout_payment_url();
$order->get_checkout_order_received_url();
$order->get_cancel_order_url();
$order->get_cancel_order_url_raw();
$order->get_cancel_endpoint();
$order->get_view_order_url();
$order->get_edit_order_url();
 
// Get Order Status
$order->get_status();

// Get Thank You Page URL
$order->get_checkout_order_received_url();

2. You have access to $order_id variable

If you have access to the order ID (once again, usually the do_action or apply_filters might give you this), you have to get the order object first. Then do the exact same things as above, and get the order status, order billing, order shipping, etc.

// Get $order object from order ID
 
$order = wc_get_order( $order_id );
 
// Now you have access to (see above)...
 
if ( $order ) {
   $order->get_formatted_order_total( );
   // etc.
   // etc.
}

3. You have access to $email variable

If you are working with WooCommerce emails, often you will have the $email object available as parameter. In order to get the object from that, you need an additional step. Then do the exact same things as above.

// Get $order object from $email
 
$order = $email->object;
 
// Now you have access to (see above)...
 
if ( $order ) {
   $order->get_id();
   $order->get_formatted_order_total( );
   // etc.
   // etc.
}

Related content

  • WooCommerce: How to Add a Custom Checkout Field
    Let’s imagine you want to add a custom checkout field (and not an additional billing or shipping field) on the WooCommerce Checkout page. For example, it might be a customer licence number – this has got nothing to do with billing and nothing to do with shipping. Ideally, this custom field could show above the […]
  • WooCommerce: Allow Users to Edit Processing Orders
    How can WooCommerce customers edit an order they just placed and paid for? I swear I looked on search engine results and other places before coming to the conclusion I needed to code this myself. For example, a user might want to change the delivery date (if you provide this on the checkout page). Or […]
  • WooCommerce: Create a Custom Order Status
    All WooCommerce orders go to either “processing”, “completed”, “on-hold” and other default order statuses based on the payment method and product type. Sometimes these statuses are not enough. For example, you might need to mark certain orders in a different way for tracking, filtering, exporting purposes. Or you might want to disable default emails by […]
  • WooCommerce: Add Column to Orders Table @ WP Dashboard
    The WooCommerce Orders Table, which can be found under WP Dashboard > WooCommerce > Orders, provides us with 7 default columns: Order – Date – Status – Billing – Ship to – Total – Actions. This is used by shop managers to have an overview of all orders, before eventually clicking on a specific one. […]
  • WooCommerce: Don’t Send Emails for Free Orders
    There are times when you sell free products to give customers access to a membership, an online course, or for other reasons. In these cases, you might not want to send the “Order Completed” email or get the “New Order” transactional notification, so that you can avoid sending and receiving hundreds of emails. Of course, […]

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

104 thoughts on “WooCommerce: Get Order Info (total, items, etc) From $order Object

  1. I just want to say thank your for your tutorials and information pages. I use them A LOT!

  2. I use the polylang plugin for multilingual Woocommerce. How i can get the language that the user had set when he had placed the order?

    1. Did you ask Polylang already?

  3. Thanks for sharing so much content with us. I’ve tried in several ways and I still can’t. How can I turn this into a clickable link in the thankyou page: $order->get_checkout_order_received_url()?

    1. I found the answer myself, just take the parentheses out and it works.

      add_action( 'woocommerce_thankyou', 'send_order_link' );
      function send_order_link( $order ) {
      $link_order = "$order->get_checkout_order_received_url";
      echo "<a href='$link_order' rel="nofollow ugc">Link</a>";
      }
      
  4. Hi there, thanks for this and all your other great resources.

    I have a question about doing something like this in a loop.

    I’m trying to fetch the order ID for a number of products (Team Memberships) in a loop and the method described in the article is quite heavy as I suppose it’s getting everything, when I just need the order ID. Is there a better way to get at just one piece of data directly from the order without fetching all the data somehow?

    Not sure if it’s possible or there is a better approach, but what I’m hoping to do is:
    – Get the order
    – Get the order ID
    – Break / Stop
    – Get the next order and order ID
    – Repeat

    1. I’m currently using this :

      $order = $team->get_order('id');
      1. Once you have $order, you can get order ID with $order->get_id()

        Does that help?

  5. Hi, how do I get the Number of payments?

    1. Hey Ester thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  6. I just wrote my boss, “I think I’ve found the Holy Grail of WooCommerce help.”

    Thank you so much for your efforts!

  7. Hi! Thank you so much, it’s safe my life)). I try to parse order object like var_dump() and get vars, it’s nightmare believe me.

  8. Hi everyone!
    in section of order items

    // Get and Loop Over Order Items
    foreach ( $order-&gt;get_items() as $item_id =&gt; $item ) {
        // we can get order SKU like this (woo 3+)
        $item->get_product()->get_sku(); 
    }
    
  9. Hi,
    You are doing a brilliant job and saving the days for WordPress developers.
    HatsOff!!!!!

  10. Hey,
    How can I display the products inside the cart?

    https://prnt.sc/135z7bj

    I’m using the code from here – https://www.businessbloomer.com/woocommerce-add-column-to-orders-table-wp-dashboard/

    and I assume that i should use some of the code above

    [php]// Get and Loop Over Order Items
    foreach ( $order->get_items() as $item_id => $item ) {
    $product_id = $item->get_product_id();
    $variation_id = $item->get_variation_id();
    $product = $item->get_product();
    $name = $item->get_name();
    $quantity = $item->get_quantity();
    $subtotal = $item->get_subtotal();
    $total = $item->get_total();
    $tax = $item->get_subtotal_tax();
    $taxclass = $item->get_tax_class();
    $taxstat = $item->get_tax_status();
    $allmeta = $item->get_meta_data();
    $somemeta = $item->get_meta( ‘_whatever’, true );
    $type = $item->get_type();
    }[php]

    but not sure how to combine it with the code from your previous post.

    Thank you

    1. Hi Chris you can reuse the exact snippet, and then instead of

      echo $order->get_billing_country();

      you’d write

      foreach ( $order->get_items() as $item_id => $item ) {
         $name = $item->get_name();
      }
      

      Hope this helps

  11. Hai, Can we get the order details using customer_id in function.php ? Please help me in it

    1. Hi, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  12. Thank you so much, this was extremely helpful!

  13. Hey, just commenting now and should have done sooner. These lists are so very useful when you don’t have them memorised!

    Thanks so much for putting them together 🙂

    1. Great! How can I improve them?

  14. Hi, Is it possible to get the order object which is created to save the order to the database just before the payment gateway.

    1. If I understand properly, then yes, it is possible

  15. Hello,

    How I can display product name and product description on my account –> view order page

    Thanks!

    1. Hi Maya, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  16. Hello i have a question:(
    How can i remove ‘#’ in WooCommerce Orders???

    1. Hey Victor, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  17. Hi,

    Thanks a lot for this great page, it helped me already a lot. Yet I am trying to receive another field which is not mentioned . It is from the order the customer’s salutation/title (Mr./Mrs.). How can I receive that field?

    Thank you!

    1. Hey Paul that’s not a default WooCommerce field

  18. Hello,

    How can i get product custom field from my order total for telegram notification?

    Thanks.

    1. Hi Ammar, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  19. How to get any order details (like: notes, order id, product details) after making any change in woocommerce order page.

    1. In the same way described here

  20. Your information is really helpful and I thought I was following it carefully but I’m getting this warning (the code works):
    The WC_Abstract_Legacy_Order::get_product_from_item function is deprecated since version 4.4.0. Replace with $item->get_product().

    add_action('woocommerce_thankyou', 'update_members_table_for_renewal_household'); 
    function update_members_table_for_renewal_household($order_id) {
        $order   = wc_get_order($order_id);
        $method  = $order->get_payment_method_title();
        foreach ($order->get_items() as $item_id => $item) {
            if($item->get_name() == "Annual Renewal (household)") {
    
    1. Is there more code? Don’t see that PHP call here

      1. There is no call to get_product. I believe that the get_name call is raising it because I get an additional warning for each item.

      2. I assumed the get_name call was raising it. These are the only places in the code where woocommerce data is retrieved.

      3. Rodolfo,

        I’ve replied twice previously. They both initially said they were awaiting moderation but then they seem to have disappeared. Here is the full code (I’ve used a slightly simpler case with less code, but it raises the same warnings) if that was the problem with my previous replies. I have tried several things but am still getting the warning. Thanks.

        Kim

        // update members table after renewal payment for individual has been submitted, KB 28 Aug 2020
        
        add_action('woocommerce_thankyou', 'update_members_table_for_renewal_individual'); 
        function update_members_table_for_renewal_individual($order_id) {
            
            global $mydb;
            
            if(is_user_logged_in() and $order_id) {
                
                $getuser    = wp_get_current_user();
                $user       = intval($getuser->user_login);
                $today      = date('Y-m-d');
                $tyear      = intval(date('Y'));
                $hh_payment = 'no';
                $order      = wc_get_order($order_id);
                $method     = $order->get_payment_method();
                $currency   = $order->get_currency();
                
                // now see if one of the order items is a renewal for an individual
                
                foreach ($order->get_items() as $item_id => $item) {
                    
                    if($item->get_name() == "Annual Renewal") {
                        
                        // get order item information
                        
                        $amount = $item->get_total(); 
        
                        // figure out renewal year and get GBP prices from the membership_prices table
                            
                        $renewal_year = $tyear;
                        $next_renewal = "";
                        $next_renewal = $mydb->get_var("SELECT renewal_start FROM membership_prices WHERE financial_year = $tyear + 1");
                        if($next_renewal and ($today >= $next_renewal))
                            $renewal_year = $tyear + 1;
                        $yearpaid = "fy" . strval($renewal_year) . "paid";
                        $rprices = $mydb->get_row("SELECT annual_no_register, annual_with_register, annual_hh 
                            FROM membership_prices WHERE financial_year = $renewal_year");
                            
                        if($rprices) {  // we have renewal prices
                            
                            // get member's details
                            
                            $requester = $mydb->get_row("SELECT number, firstname, surname, primarymember, sendregister, 
                                          standingorder, repeattransactionauthority, directdebit, 
                            			  $yearpaid as paid, amountpaid, TermMemship, TermFY 
                                          FROM members WHERE number = '$user'");
                                          
                            $name   = $requester->firstname . ' ' . $requester->surname;
                            $soddrta = '';
                            if($requester->standingorder == "yes") 
                                $soddrta .= "so";
                            if($requester->repeattransactionauthority == "yes") 
                                $soddrta .= "rta";
                            if($requester->directdebit == "yes") 
                                $soddrta .= "dd";
                            $sendregister = "";
                            $memberprice = 0;
                    
                            $sendregister = $requester->sendregister;
                            if($requester->primarymember)       // household member, reduced rate
                                $memberprice = $rprices->annual_hh;
                            else if($sendregister == "yes")
                                $memberprice = $rprices->annual_with_register;
                            else
                                $memberprice = $rprices->annual_no_register;
                            $paid = $requester->paid;
                            $prev_pay = $requester->amountpaid;
                            
                	        // update the members table
        
                            if (!($paid == 'term' or $paid == 'life'))
                	            renewal_update_members_table($user,$method,$renewal_year,$memberprice);
                	        $query = "INSERT INTO renewals 
                    	            (year,order_id,hh_payment,paid_by,wc_method,wc_amount,wc_currency,member,
                    	             mem_name,mem_price,prev_pay,soddrta,mt_paid,mt_amount,mt_underpaid,submitted,confirmed)
                    	            VALUES('$renewal_year','$order_id','$hh_payment','$user','$method','$amount','$currency',
                    	                '$user','$name','$memberprice','$prev_pay','$soddrta',";
                	        if($method == "stripe")
                	            $query .= "'credit card',";
                	        else if($method == "paypal")
                	            $query .= "'paypal',";
                	        else
                	            $query .= "'$paid',";
            	            $query .= "'$memberprice',0,'$today',";
                	        if($method == 'stripe' or $method == 'paypal')
                	            $query .= "'$today')";
                	        else
                	            $query .= "'')";
                	        $mydb->query($query);
                            db_audit_log($query);
                            
                        }   // end if rprices
                        
                        break;      // there should just be one renewal item
                    }   // end if annual renewal
                    
                }   // end foreach item
                
            }   // end if logged in
        
        }   // end update members table after renewal payment for individual
        
        
        // update the members table, just set to subscription price regardless of actual payment amount because they
        // can only pay what remains of the full price even if there were previous payments
        
        function renewal_update_members_table($member,$method,$renewal_year,$memberprice) {
            
            global $mydb;
            
            $now    = time();
            $todaytext = date('l, jS F Y');
            $yearpaid = "fy" . strval($renewal_year) . "paid";
        
            switch($method) {
                case('stripe'):
                    $query = "UPDATE members SET $yearpaid = 'credit card', amountpaid = '$memberprice', 
                        underpayment = 0, paymentupdatedinternal = '$now' WHERE number = '$member'";
                    $mydb->query($query);
                    db_audit_log($query);
                    break;
                case('paypal'):
                    $query = "UPDATE members SET $yearpaid = 'paypal', amountpaid = '$memberprice', 
                        underpayment = 0, paymentupdatedinternal = '$now' WHERE number = '$member'";
                    $mydb->query($query);
                    db_audit_log($query);
                    break;
                case('cod'):    // standing order, should we set dd and rta to 'no'?
                    $query = "UPDATE members SET standingorder = 'yes', updated = '$todaytext', updatedinternal = '$now' WHERE number = '$member'";
                    $mydb->query($query);
                    db_audit_log($query);
                    break;
                case('bacs'):   // direct bank transfer, should we set so and rta to 'no'?
                case('gocardless'):
                    $query = "UPDATE members SET directdebit = 'yes', updated = '$todaytext', updatedinternal = '$now' WHERE number = '$member'";
                    $mydb->query($query);
                    db_audit_log($query);
                    break;
                default:    // e.g. cheque
                    break;
            }
            
        }   // end renewal update members table
        
        1. I can’t help you troubleshooting all this code. I recommend you disable all plugins but Woo, switch theme, “comment out” this snippet so that you execute one operation at a time (from top to bottom), and in this way you should see where the issue is coming from

  21. Hello,

    I’m currently making some custom email templates for the orders.
    Nearly everything goes good so far, but I can’t seem to get the info of the used payment accounts f.e :
    If I pay with iDEAL i want the customer to show their used bankaccount (IBAN : NL25******6857).

    I am using Mollie for this.

     
    	  Payment Method : <?php echo $order->get_payment_method_title(); ?> <br/>
    	  Transaction ID : <?php echo $order->get_transaction_id(); ?> <br/>
    	  Bank Account : .....
    	  Bank Holder Name : .....
    

    I can code the masked numbers myself if needed but I just need to get the data.

    Can you help me figure this out, or do you know the Solution to this ?

    1. You may need to look inside the Mollie plugin to see how they “get” those values?

  22. Hi,
    Thanks for such a nice article.
    $date = $order->get_date_created()->format (‘F j, Y – g:i A’);

    Here get_date_created() gives UTC rather than local time. How can it be changed to give UTC+5:30

  23. Hi,
    this examples are very great. Thank you very much Rodolfo!

    I have a problem:
    Does something changed inside WC?
    In WC 4.0.1 everything worked fine.
    In WC 4.1 I dont get any data like order items, addresses, …

    1. Cool, no, nothing changed

  24. How can I ask for customer id number as part of payment information?
    I am looking/expection a short filter, snippet to add to my functions.php
    Not a whole plugin.
    Thanks

    1. Hi Mulli, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  25. Hi
    Already thank’s for this … it really helps me!
    Just a question … is it possible to use it with multiple $order_id?
    I would like to make a resume (Products and quantity) of a group of X orders.
    Any idea?
    Best regards

    1. Hi Vincent, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  26. Hi I want to display some ACF fields i get when i import products with WP All import in the admin’s order page. By default woo only shows the item title, sku, quantity and price. Is the code you posted the right way to go? can you give me a hint? i’m totally lost. I know i can create a custom field inside the admin’s order page with ACF, but then i’ll have to fill in the content manually. That’s not what i need. What i need is that the field created in admin’s order page automatically pulls product information that is already loaded…for ex the tax fee applied to that product or whatever i need. Don’t confuse with the data the customer fills in when he makes an order, no. The data i need is already loaded in the product when i make the import with WP All import. Thanks

    1. Hi Alejandro, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  27. Thank you for this. It is very useful. Does this work on the checkout page before the order has actually been submitted? Is there another way to access the product information on that page otherwise?

    I tried this

    function product_requires_camper() {
    	$order = wc_get_order( $order_id );
    	if ( $order ) {
    		return "<h1>HELLO I'M HERE</h1>";
    	}
    }
    

    and used shortcode to add it to the checkout page. The message did not appear when I opened the checkout page.

  28. Rodolfo, your website is an incredible resource.

    I am looking to add a simple bar in the WP admin bar that can take me directly to the edit order page.

    Since we have this function: $order->get_edit_order_url(); wondering how you might achieve this? I cannot believe there is not a single plugin or even code snippet to achieve this. Often we get phone calls from customers and we need to go right to a specific order. This would allow in 1 single step.

    Any advice on how this might be achieved?

    1. Never mind my friend – thank you. We built a plugin that now handles this for normal naming convention of orders as well as changed naming conventions due to plugins.

      Please keep up the amazing work you do. I have used several of your code snippets and enjoy reading your extensively annotated work.

      Stay safe!

      1. Awesome!

  29. its possibility catch de category of de product/s que customer buyed? i need this dato for send different email for the customer in the moment of de buyed. Thanks

    1. Yes, it’s possible. Do you need to send a custom, additional email – or to customize an existing order email?

  30. Hi, I am trying to put a unit price of each item before quantity column on woocommerce email. Below is what I have done and it displays the unit price but if the item is discounted, this will show the discounted price. How can i make the unit price shows before discount price?

    <?php echo wc_price( $order->get_item_total( $item, true, true ), array( 'currency' => $order->get_order_currency() ) ); ?>

    Thanks in advance.

    1. Hi James, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  31. Thanks for this list! I’m trying to make good use of it. So I’ve set up an action in my functions.php file like this (is this a good place to hook into Woo?):

    add_action( 'woocommerce_before_checkout_billing_form', 'bazaarvoice_data' );

    and I am trying to get all kinds of stuff from about the Order, so I’ve started with the following:

    function bazaarvoice_data () {
    
    global $woocommerce;
    global $order_id, $order;
    
    $order_id = $order->get_id();
    
    echo $order_id;
    
    }
    

    And, when I run things, I keep getting this error:
    [22-Sep-2019 22:58:45 UTC] PHP Fatal error: Call to a member function get_id() on string in /mnt/objectivefs/dev_sites/gunvault/wp-content/themes/Avada-Child-Theme/functions.php on line 50

    So, I figure I’m missing something, but what? Do I need to add something to the get_id()? Or is it something else?

    Huge thanks in advance.

    ~Walt

    1. Hi Walt – that’s the wrong hook as the $order doesn’t exist yet. Try with “woocommerce_thankyou” instead, which gives you access to $order_id

      1. hello,

        I have used woocommerce_thankyou hook but still, am getting error ‘site blocked’.

        1. No idea

  32. How do I display the number of orders and the number of downloads per user in user profile?
    I want to show the number of orders and number of download per user in user profile.

    1. Shahoo, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  33. Hi,

    I used a total different template for those emails and unfortunately, I don’t manage to get the total discount…
    From this list (awesome btw), I should use either `$order->get_discount_total();` or `$order->get_total_discount();` but both display 0 while if I come back to the default woocommerce email template, the discount is displayed.

    The discount I’m talking about is not a coupon but a buy 2 get 1 free that has been coded in the store. But since Woocommerce template gets it, why can’t it?

    Thanks for the help,

    Any idea?

    1. Hello Nicolas, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  34. $order->get_used_coupons()

    use this snippet to get the all used coupon to this order.

    1. Thanks!

      1. get_used_coupons is deprecated. Use (WC 4.4):

        $order->get_coupon_codes()
        

        Returns an array and I just use the first element.

        1. THANKS!

          1. Try to use $order->get_used_coupons() and get error

            “get_used_coupons is deprecated since version 3.7! Use WC_Abstract_Order::get_coupon_codes instead.”

  35. Hello, I want to show the Order Status in the PDF Invoice, how can I do it?

    get_status($order_status); ?>

    1. Hello Mergim, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  36. This is Very Helpful ….. Thanks alot

    1. Great!

  37. Hi expert,

    Regards.
    I am using Woocommerce Multi Vendor Market Place (bu WCLovers) along with its WooCommerce Frontend Manager.
    I want to add more orders fields in Vendor Dashboard. In a view of Order List, like Billing Address for example.
    Please assist.

    Thank you
    Edo

    1. Edo, please ask their support team

  38. Hi Rodolfo!

    How can I have access in the $order object?

    1. Hey Mike! On which page are you?

  39. Can you help me ? Of course, for a fee. I want to add data to the order confirmation – everything is OK, but they are not showing off. Will you do such a service for me?

    1. Hello Jacek, thanks so much for your comment! Yes, if you’d like to get a quote, feel free to contact me here. Thanks a lot! ~R

  40. Hello Rodolfo,

    I have created a custom template in my theme file and would to get Woocommerce order details variable in that page. However when I tried to echo $order->get_total(), internet server error with notice “Failed to load resource” appeared. Is there possibility whereby the code only function if the php is in Woocommerce plugin directory?

    Thank you.

    1. Hey Will, thanks for your comment! The code will work everywhere (however, it’s better if you place it in functions.php) as long as you have access to the $order variable

  41. Hi Rodolfo,

    I would like to add a script at the “thank you page” in WooCommerce to run a URL like:

    Could you help me getting this parameters?

    Thank you

    1. Upss! I forgot to wrap it between tags.

      This is the URL:

      <script async src="https://example.com?total_price=XXXXXXX&order_id=XXXXXXX"></script>
      1. Hey Marco, thanks for your comment! Please see https://businessbloomer.com/woocommerce-add-conversion-tracking-code-thank-page/ and then given you have access to “$order_id”, you can “echo” those values with PHP inside the script. Hope this helps

    2. Hey Rodolfo,

      I tried to publish:

      add_action( 'woocommerce_thankyou', 'bbloomer_conversion_tracking_thank_you_page' );
       
      function bbloomer_conversion_tracking_thank_you_page() {
      
          $order = wc_get_order( $order_id );
      
          echo $order->get_order_number();
          echo $order->get_formatted_order_total();
      
      ?>
      
      <?php
      }
      

      But the page seems blocked. When I remove the code above and I reload the page, then it works. I think that the problem is related to de $order. I am not a developer.

      Thank you very much for your help.

      1. Hey Marco, thanks for your comment! You need to pass “$order_id” to the function

    3. Yeah, sure, but I don’t know how to do it… 🙁
      Could you help me?

      Thanks!

      1. Marco unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R

    4. Sure! I completely understand. Finally I got the solution.

      Thanks for your help!

      1. Awesome 🙂

    5. Marosseculi, if you’re still here would you mind sharing how you got the order_id and order_total into the link? I understand where to put the code (functions.php) but I’m unsure of how those values get written into the link.

  42. Great Blogpost, Thanks Rodolfo.

Leave a Reply

Your email address will not be published. Required fields are marked *