【问题标题】:WooCommerce: Display product total price in cart/minicart instead of product priceWooCommerce:在购物车/迷你购物车中显示产品总价而不是产品价格
【发布时间】:2019-02-26 16:08:37
【问题描述】:

我在我的 Wordpress 网站上使用 WooCommerce,我想在我的购物车/迷你购物车中显示每个产品的总价格(例如:“产品数量”x“产品价格”=“产品总价格”)。 我现在使用的代码可以运行,但是存在舍入错误。

预期:

  • 产品 #1
  • 数量:2
  • 价格:3,50
  • 总价:7,00

显示:

  • 产品 #2
  • 数量:2
  • 价格:3,50
  • 总价:6,00

这是我正在使用的代码:

<?php $new_product_price_old = number_format((float)wp_kses( woocommerce_price( $_product->get_price() ), array() ) * $cart_item['quantity'], 2, ',', '.'); ?>
<?php echo '<span class="sidecart-item-price">' . $new_product_price ?>&nbsp;<span class="woocommerce-Price-currencySymbol">€</span></span>

有没有一种简单的方法来解决这个问题或另一段代码?还是我缺少的钩子?这里是初学者...

提前致谢

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    所以我自己解决了这个问题。我不知道我以前的代码是从哪里得到的,但我猜这部分是导致问题的原因:

    wp_kses( woocommerce_price( $_product->get_price() ), array()
    

    这是我的工作代码(我是初学者,所以可能有更好的方法来做到这一点):

    <?php   
    $product_price_single = $cart_item['data']->get_price();
    $product_price_total_formatted = number_format($product_price_single * $cart_item['quantity'], 2, ',', '.'); 
    ?>
    
    <?php echo '<span>' . $product_price_total_formatted ?>&nbsp;<span class="woocommerce-Price-currencySymbol">€</span></span>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-06
      • 2013-11-01
      • 2017-08-07
      • 1970-01-01
      • 2016-04-04
      • 2018-02-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多