Woocommerce change total price of a varible product on quantity change
Woocommerce change total price of a varible product on quantity change
The objective is to CALCULATE TOTAL PRIZE MULTIPLIED by QUANTITY.
Below code works with simple products but not with VARIABLE PRODUCTS.
I was to able makeup to this.
The Problem is Variation Price is not getting multiplied.
<?php
add_filter( 'woocommerce_variable_price_html', 'bbloomer_variation_price_format_310', 10, 2 );
function bbloomer_variation_price_format_310( $price, $product ) {
// 1. Find the minimum regular and sale prices
$min_var_reg_price = $product->get_variation_regular_price( 'min', true );
$min_var_sale_price = $product->get_variation_sale_price( 'min', true );
// 2. New $price
if ( $min_var_sale_price < $min_var_reg_price ) {
$price = sprintf( __( 'From: <del>%1$s</del><ins>%2$s</ins>', 'woocommerce' ), wc_price( $min_var_reg_price ), wc_price( $min_var_sale_price ) );
} else {
$price = sprintf( __( 'From: %1$s', 'woocommerce' ), wc_price( $min_var_reg_price ) );
}
// 3. Return edited $price
return $price;
}
// 4. Multiplpier Section
add_action( 'woocommerce_single_product_summary', 'woocommerce_total_product_price', 31 );
function woocommerce_total_product_price()
{
global $woocommerce, $product;
// Divs
echo sprintf('
%s %s
',__('Product Total:','woocommerce'),'<span class="price">'.$product->get_price().'</span>');
?>
jQuery(function($)
{
//get price
var price = get_price(); ?>,
//get currency symbol
currency = '';
$('[name=quantity]').change(function(){
if (!(this.value
<?php
}
?>
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Comments
Post a Comment