[英]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_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 ).
. 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>';
它应该更好地工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.