简体   繁体   中英

Multiply custom product price by the quantity in WooCommerce cart

I'm using the following script on my WooCommerce website:

Quantity: . 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 ).

Price: . 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 ).

I am trying to multiply the Quantity by the product Price or to get it directly from an existing code. (But I could n't find it).

How can I apply a multiplication from product price with the quantity?


Edit:

I have find a way to get the quantity with your answer code but it doesn't display the Multiplication of price by Quantity, as WC()->cart->get_product_price( $woofc_product ) gives the formatted price with currency symbol.

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

Updated regarding the product price without currency symbol

There are some mistakes in your code, try the following to get the correct display:

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

It should better work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM