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

Multiply custom product price by the quantity in WooCommerce 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>';

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

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

$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>';

它应该更好用。