• Resolved mxhosting.fi

    (@mxhostingfi)


    Hi,

    How can I get order total price separetly in PDF invoice? I need to input it to the different place.

    Here is the code:

    <?php foreach ( $this->get_woocommerce_totals() as $key => $total ) : ?>
    	<tr class="<?php echo esc_attr( $key ); ?>">
    		<th class="description"><?php echo $total['label']; ?></th>
    		<td class="price"><span class="totals-price"><?php echo $total['value']; ?></span></td>
    	</tr>
    <?php endforeach; ?>

    Total price is inside foreach, need to extract it?

    Best regards,
    Max

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor alexmigf

    (@alexmigf)

    Hi @mxhostingfi

    Try this:

    <?php echo wc_price( $this->order->get_total() ); ?>

    Let us know.

    Thread Starter mxhosting.fi

    (@mxhostingfi)

    Hi,

    this is worked for me, thank you!

    How about product discount and sale price meta?

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Those details are not stored by default in the order, as you can read here: Difference between sale price and discount

    However, you can install this plugin to begin saving those details in new orders: Sale price as order discount for WooCommerce

    Then, you should be able to access to this info from $item, here.

    Thread Starter mxhosting.fi

    (@mxhostingfi)

    Thanks for this information!

    I also noticed that I cannot get product price with after discount.

    For example product’s original price is 10$, client has ordered 5 qty of product with 10% discount. Total price is showing in PDF invoice correctly 45$, but product price is showing still 10$.

    I’am using this code:

    <?php echo $item['product']->get_meta('_regular_price') ?>

    Question is, how can I get product price after discount? Product price of one piece should be displayed 9$.

    Thank you!

    • This reply was modified 1 year, 9 months ago by mxhosting.fi.
    Plugin Contributor Yordan Soares

    (@yordansoares)

    Please note that “product” and “order item” is not the same:

    • The product details are the latest info related with a specific product from your inventory, including price, tax, etc., that it is stored in your inventory and can change in any moment, because of inflation, or any other factor.
    • The item details is the info stored in the order details, at the moment of placing an order. This info is not dependent of the product info, therefore, if the product price changes in the future, it will not affect the order. Also, an item could be not only a product, but a shipping charge or a fee.

    I mention this because you are using the product details, instead of the item ones, which could produces issues in the future, if the product details change, since it will modify the PDF documents from old orders!

    See this answer on Stack Overflow to learn more about how to get the item details: https://stackoverflow.com/a/40715347

    Please note that we have an extension, which includes a customizer that helps to manage all these details through blocks: Premium Templates. If you do not want to deal with code, please consider getting this extension ??

    Thread Starter mxhosting.fi

    (@mxhostingfi)

    Hi,

    I have purchased Premium Template for PDF plugin. How can I get descount in php format “<php echo wc_price ($this->order->get_total() ); ?>”?

    Thank you!

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @mxhostingfi,

    Please note that www.ads-software.com does not allow us to provide support or answering pre-sale questions for paid plugins here, that is why I have to ask you to write at [email protected]: I will be looking forward to your reply there!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to get total order price separetly’ is closed to new replies.