【问题标题】:Multiply custom product price by the quantity in WooCommerce cart将自定义产品价格乘以 WooCommerce 购物车中的数量
【发布时间】:2020-05-25 19:57:15
【问题描述】:

我在我的 WooCommerce 网站上使用以下脚本:

数量:. apply_filters( 'woocommerce_cart_item_quantity', $cart_item_quantity, $cart_item_key, $cart_item ) .

价格:. apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $woofc_product ), $cart_item, $cart_item_key ) .

我试图将数量乘以产品价格或直接从现有代码中获取。 (但我没找到)。

如何将产品价格乘以数量?


编辑:

我找到了一种使用您的答案代码获取数量的方法,但它不显示价格乘以数量,因为WC()->cart->get_product_price( $woofc_product ) 给出了带有货币符号的格式化价格。

$cart_html .= '<span class="woofc-item-price">' . $product_price = apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $woofc_product ), $cart_item, $cart_item_key ) . ' - Toplam: ' . $cart_item['quantity'] * $product_price . '</span>';
$cart_html .= '</div>';

【问题讨论】:

    标签: php wordpress woocommerce product cart


    【解决方案1】:

    更新关于不带货币符号的产品价格

    您的代码中存在一些错误,请尝试以下操作以获得正确的显示:

    $quantity   = apply_filters( 'woocommerce_cart_item_quantity', $cart_item['quantity'], $cart_item_key, $cart_item );
    $raw_price  = (float) wc_get_price_to_display( $woofc_product ); // Product raw display price 
    
    $cart_html .= '<span class="woofc-item-price">' . apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $woofc_product ), $cart_item, $cart_item_key );
    $cart_html .= ' - Toplam: ' . wc_price( $quantity * $raw_price ) . '</span>';
    $cart_html .= '</div>';
    

    它应该更好地工作。

    【讨论】:

    • 谢谢你这个答案真的很好但是我留下了一个小错误
    • 嘿,是的,我已经看到它变得非常好,但你能不能让 $product_price = apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $woofc_product ), $cart_item, $ cart_item_key );没有货币符号(就像这样做 number_format)
    猜你喜欢
    • 2017-12-10
    • 2018-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-07
    • 2019-12-21
    • 2017-04-06
    相关资源
    最近更新 更多