• Resolved bfeeee

    (@bfeeee)


    Hi,

    Does anybody have experience in changing Total in pdf.
    Right now I would like to change total to something like this (https://joxi.ru/bmo9BZPUR1lPAy) – Show VAT(%), Total price without VAT, Only total prices VAT and TOTAL price with VAT.

    I presume that I need to make changes in public function get_woocommerce_totals(), but for now I tried various ways and haven’t had any results.

    Maybe someone has any ideas?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    Hi! Rather than changing the get_woocommerce_totals function directly, I recommend using the filter applied to it: wpo_wcpdf_woocommerce_totals. This will let you change/replace the totals completely. This is beyond the scope of support for the free version, but here’s an example to get you on track with this:

    
    add_filter( 'wpo_wcpdf_woocommerce_totals', 'wpo_wcpdf_woocommerce_totals_custom', 10, 2 );
    function wpo_wcpdf_woocommerce_totals_custom( $totals, $order ) {
    	$totals = array(
    		'subtotal'	=> array(
    			'label'	=> __('Subtotal', 'wpo_wcpdf'),
    			'value'	=> $order->get_subtotal_to_display(),
    		),
    		// etc.
    	);
    
    	return $totals;
    }
    

    Hope that helps!
    Ewout

    Thread Starter bfeeee

    (@bfeeee)

    Hi, Ewout!

    I’m very grateful for Your answer, it helped! In the end made something like this

    add_filter( 'wpo_wcpdf_woocommerce_totals', 'wpo_wcpdf_woocommerce_totals_custom', 10, 2);
    function wpo_wcpdf_woocommerce_totals_custom( $totals, $order) {
        $totals = array(
            'price_without_vat'	=> array(
                'label'	=> __('Price without VAT', 'wpo_wcpdf'),
                'value'	=> wc_price( $order->get_total() - $order->get_total_tax(), array( 'currency' => WPO_WCPDF()->export->order->get_order_currency() ) ),
            ),
            'order_shipping'	=> array(
                'label'	=> __('Shipping', 'arga-custom'),
                //Can't find the function/variable to show shipping AND/OR is shipping even selected
                'value' => '',
            ),
            'total_tax'	=> array(
                'label'	=> __('Total tax', 'wpo_wcpdf'),
                'value'	=> wc_price( WPO_WCPDF()->export->order->get_total_tax() - WPO_WCPDF()->export->order->get_total_tax_refunded(), array( 'currency' => WPO_WCPDF()->export->order->get_order_currency() ) ),
            ),
    
            'total_price'	=> array(
                'label'	=> __('Total price', 'wpo_wcpdf'),
                'value'	=> wc_price( $order->get_total(), array( 'currency' => WPO_WCPDF()->export->order->get_order_currency() ) ),
            ),
            // etc.
        );
    
        return $totals;
    }

    but there is problem with shipping, somehow I can’t understand how to show shipping (if shipping even is selected).

    Tried adding get_order_shipping + changing add_filter to accept 3 variables and adding $tax variable, but it didn’t work.

    Plugin Contributor Ewout

    (@pomegranate)

    first of all, don’t use WPO_WCPDF()->export->order, you already have $order as the second function argument and the former will be deprecated in the 2.0 update.
    you can find all the order methods in the woocommerce source:
    https://github.com/woocommerce/woocommerce/blob/master/includes/abstracts/abstract-wc-order.php
    https://github.com/woocommerce/woocommerce/blob/master/includes/class-wc-order.php

    Good luck!
    Ewout

    What is a filter as indicated above and how can i get it in wordpress/woocomerce? Would like to use above. Thank you

    • This reply was modified 7 years, 1 month ago by wamburueric.
    Plugin Contributor Ewout

    (@pomegranate)

    Hello @wamburueric,
    If you do not have any programming experience, I recommend that rather than trying to roll your own, you get a copy of the Premium Templates extension. This will let you do this and much more directly from the settings, without writing any code.

    Kind regards,
    Ewout

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Show total price, price without VAT and VAT seperately’ is closed to new replies.