Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在opencart(2.0.3.1)订单电子邮件(客户端和管理员)上向运输成本添加税费_Php_Arrays_Opencart_Opencart2.x - Fatal编程技术网

Php 在opencart(2.0.3.1)订单电子邮件(客户端和管理员)上向运输成本添加税费

Php 在opencart(2.0.3.1)订单电子邮件(客户端和管理员)上向运输成本添加税费,php,arrays,opencart,opencart2.x,Php,Arrays,Opencart,Opencart2.x,如果订单的装运重量成本中存在文本手续费,我想添加手续费。我还希望避免编辑任何控制器。如何从我的视图中编辑confirm.tpl <tfoot> <?php foreach ($totals as $total) { ?> <tr> <td colspan="4" class="text-right"><strong><?php echo $total[

如果订单的装运重量成本中存在文本手续费,我想添加手续费。我还希望避免编辑任何控制器。如何从我的视图中编辑
confirm.tpl

<tfoot>
      <?php foreach ($totals as $total) { ?>
      <tr>
        <td colspan="4" class="text-right"><strong><?php echo $total['title']; ?>:</strong></td>
        <td class="text-right"><?php echo $total['text']; ?></td>
      </tr>
      <?php } ?>
</tfoot>


以下是我迄今为止所做的工作:

<tfoot>
      <?php foreach ($totals as $total) { ?>

      <?php 
        if(strpos($total['title'], "Handling") !== false) {
          // handling exists, what now?
        }
      ?>
      <tr>
        <td colspan="4" class="text-right"><strong><?php echo $total['title']; ?>:</strong></td>
        <td class="text-right"><?php echo $total['text']; ?></td>
      </tr>
      <?php } ?>
</tfoot>




这里有一个枯燥无味的答案。如果我能改进这一点,请让我现在。它使用strpos来隐藏手续费,并将preg_替换为float,以便我执行一些基本的算术运算

<?php

$totals = array(
    array('title' => 'Handling Fee', 'text' => '₱171.33'),
    array('title' => 'Sub-Total', 'text' => '₱17,132.85'),
    array('title' => 'Nationwide Fee', 'text' => '₱280.00')
);


?>


<tfoot>
    <?php $toAdd = 0; foreach ($totals as $total) { ?>
    <?php 
    if(strpos($total['title'], "Handling") !== false) { 
        $toAdd = (float)preg_replace('/[^.a-zA-Z0-9]/s', '', $total['text']);
    } else { ?> 
        <tr>
            <td colspan="4" class="text-right"><strong><?php echo $total['title']; ?>:</strong></td>
            <td class="text-right"><?php 
                if($toAdd && (strpos($total['title'], 'Nationwide') !== false)) {
                    $nationwide = (float)preg_replace('/[^.a-zA-Z0-9]/s', '', $total['text']);
                    echo "₱". number_format($nationwide + $toAdd, 2, '.', ','); 
                } else {
                    echo $total['text']; 
                }
            ?></td>
        </tr>
    <?php } ?>
    <?php } ?>
</tfoot>