将自定义产品价格乘以WooCommerce购物车中的数量

时间:2020-05-25 19:57:15

标签: php wordpress woocommerce product cart

我在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>';

1 个答案:

答案 0 :(得分: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>';

应该更好地工作。