问题描述:

How can i store last value of $total['value'] into $COD?

Variable and echo it and other place of page code is

 <?php foreach( $wpo_wcpdf->get_woocommerce_totals() as $key => $total ) : ?>

<tr class="<?php echo $key; ?>">

<td class="no-borders">&nbsp;</td>

<th class="description"><?php echo $total['label']; ?></th>

<td class="price"><span class="totals-price"><?php echo $total['value']; ?></span></td>

</tr>

<?php endforeach; ?>

This code of "WooCommerce PDF Invoices & Packing Slips" free plugin

网友答案:

Try this, values will get overwritten and ultimately you will have last value

$COD = $total['value'];
网友答案:

I Solve it using this

if ($key === 'order_total'){ $COD = $total['value']; }

<?php foreach( $wpo_wcpdf->get_woocommerce_totals($grand_total) as $key => $total ) : ?>
                    <tr class="<?php echo $key; ?>">
                        <td class="no-borders">&nbsp;</td> 
                        <th class="description"><?php echo $total['label']; ?></th>
                        <?php if ($key === 'order_total'){ $COD = $total['value']; } ?>

                        <td class="price"><span class="totals-price"><?php echo $total['value']; ?></span></td>
                    </tr>   
                    <?php endforeach; ?>

Thanks @Zl3n Thanks Stackoverflow

相关阅读:
Top