• Resolved Gareth D

    (@garydee1977)


    Hi there Pinal – what an excellent plugin! Honesly – really love it!
    I reached out to you on social – so if you see a request that was me…

    Can I ask – new to this customisation of the Woo emails and after a day of struggling I finally got the edits added to the request-new-quote.php file.

    Now – it works and looks perfect being sent – but the UNIT Price value does not format with a currency symbol (just shows number)
    So questions I have:
    1) Is how I’m doing the loop look ok? i.e. no leaving any resources open or should I have any other PHP code inserted after to close anything??
    2) How to call the unit price in that will display it with the default currency symbol (in this case Euro)

    Once again – what an excellent little plugin and I can see alot of uses for this!

    <?php
    
    foreach ( $order_obj->get_items() as $items ) {
    
    $productgd = $items->get_product(); // Get the WC_Product object
    
    ?>
    
    <tr>
    
    <td style="text-align:left; border: 1px solid #eee;"><?php echo esc_html( $productgd->get_sku() ); ?></td>
    
    <td style="text-align:left; border: 1px solid #eee;"><?php echo wp_kses_post( $items->get_name() ); ?></td>
    
    <td style="text-align:left; border: 1px solid #eee;"><?php echo esc_attr( $items->get_quantity() ); ?></td>
    
    <td style="text-align:left; border: 1px solid #eee;"><?php echo wp_kses_post( $productgd->get_price() ); ?></td>
    
    <td style="text-align:left; border: 1px solid #eee;"><?php echo wp_kses_post( $order_obj->get_formatted_line_subtotal( $items ) ); ?></td>
    </tr>
    <?php
    }
    ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Gareth D

    (@garydee1977)

    So I just worked around this by doing the following Pinal – once again, can you advise, does this code look ok? Or is there a better way to write certain bits? I couldn’t get the price to output formatted in its base currency, just put out the number – so I added the euro symbol coded in.

    <?php
    
    foreach ( $order_obj->get_items() as $items ) {
    
    $productgd = $items->get_product(); // Get the WC_Product object
    
    ?>
    
    <tr>
    <td style="text-align:left; border: 1px solid #eee;"><?php echo esc_html( $productgd->get_sku() ); ?></td>
    
    <td style="text-align:left; border: 1px solid #eee;"><?php echo wp_kses_post( $items->get_name() ); ?></td>
    
    <td style="text-align:left; border: 1px solid #eee;"><?php echo esc_attr( $items->get_quantity() ); ?></td>
    
    <td style="text-align:left; border: 1px solid #eee;">&euro;<?php echo wp_kses_post( $productgd->get_price() ); ?></td>
    
    <td style="text-align:left; border: 1px solid #eee;"><?php echo wp_kses_post( $order_obj->get_formatted_line_subtotal( $items ) ); ?></td>
    
    </tr>

    Thanks!!

    Plugin Author pinal.shah

    (@pinalshah)

    Hi Gareth,

    The code looks good.

    Another way to get the product object would be to use the product ID which is present in $items.
    $productgd = wc_get_product( $items['product_id'] );

    There’s nothing wrong with the way you’ve written it. I’m just suggesting an alternate way to get the object if you ever need to.

    Also, you can use the WC functionwc_price() to format the product price as below:

    <td style="text-align:left; border: 1px solid #eee;"><?php echo wp_kses_post( wc_price( $productgd->get_price() ) ); ?></td>

    I hope this helps.

    Pinal

    Thread Starter Gareth D

    (@garydee1977)

    Perfect!! Thank you Pinal!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘request-new-quote.php Custom change’ is closed to new replies.