• Resolved Ibissen

    (@ibissen)


    Dear support team,

    this is what I’m planing to do:
    Include an addional line in invoice.php with rates:
    “Payable now: 20 % of Total”
    “Payable at ….: 80 % of Total”

    My approach was something like that:
    <?php
    $sum = $total[‘value’];

    – converting in float without currency
    – str_replace seems to be unconfortable here
    Does any build-in function exist?

    $rate1 = $sum / 5 ;
    $rate2 = $sum / 1.25 ;

    echo Payable 20 %: $rate1;
    echo Payable 20 %: $reate1;
    ?>
    My questions:
    Is this the best way to realize this?
    If I put “clear” php in invoice.php, all formating is gone.
    Do I have to go the way through functions.php?

    I would appreciate any help and will post the complete code, if it is working.

    Thank you,
    Elisa

    https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/

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

    (@pomegranate)

    Hi Elisa,
    You can get the order total as a double with the following code:

    $sum = $this->order->get_total();

    It depends on other factors whether I would do this via functions.php, but generally speaking, the functions.php approach (using pdf action hooks & filters) is the most update proof method.

    Hope that helps!
    Ewout

    Thread Starter Ibissen

    (@ibissen)

    Dear Ewout,

    Great! Thank you. It helps me a lot.
    The final code is so simple now – this wouldn’t be helpful for you php-pros. For the other beginners like me:

    <?php
    $sum = $this->order->get_total();
    $werta = $sum / 5 ;
    $wertb = $sum / 1.25 ;
    $wert1 = number_format ( $werta , $decimals = 2 , $dec_point = "," , $thousands_sep = "." );
    $wert2 = number_format ( $wertb , $decimals = 2 , $dec_point = "," , $thousands_sep = "." );
    ?>
    Pay immediately <?php echo $wert1; ?>
    Pay later <?php echo $wert2; ?>

    Elisa

    Plugin Contributor Ewout

    (@pomegranate)

    Hi Elisa,
    Even simpler:

    <?php $sum = $this->order->get_total(); ?>
    Pay immediately <?php echo wc_price( $sum * 0.2 ); ?>
    Pay later <?php echo wc_price( $sum * 0.8 ); ?>

    wc_price() gives you all the price formatting you need from the settings in WooCommerce.

    Have a great day!
    Ewout

    Thread Starter Ibissen

    (@ibissen)

    You are my king!
    E.

    Plugin Contributor Ewout

    (@pomegranate)

    You’re welcome – if you can spare a minute, I’d really appreciate it if you can post a review here on wordpress.org!

    Thanks and have a fantastic day!
    Ewout

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Modification Invoice’ is closed to new replies.