Total : 0.00 €

Before contacting us, please make sure to check our F.A.Q

Please, login or register to our website in order to be able to post a presale question in the forum.

× WooPrice Calculator PRO

Quantity Discount

More
5 days 23 hours ago #1954 by Naidi
Naidi replied the topic: Quantity Discount
Hi Tyler,

About the wrong default price:
You should check the default values you have set to the input fields you have created.
If you have set no default values to the input fields, than you should clear the cells
on the excel file before upload it.

About the 1 cent round problem:
Instead of using TEXT() formula use ROUND()
here some documentation how to use it :https://exceljet.net/excel-functions/excel-round-function

do not forget to reformat the cell B19 to be a general one.

Attached will find the excel file of your case that use the ROUND formula.

Best regards.
Naidi
AT849

File Attachment:

File Name: TEST-BAHCO...M42.xlsx
File Size:22 KB
Attachments:

Please Log in or Create an account to join the conversation.

More
1 week 1 day ago #1951 by Tyler Robinson
Tyler Robinson replied the topic: Quantity Discount
I have found a way to create a calculator in excel and import that. I works great! However, there are two minor issues. For some reason, the product defaults to the incorrect price. It defaults to the price starting at 9 feet. The other is that when I import the excel file, WooPrice Calculator rounds the price down 1 cent from what the excel file shows the price is. I have attached my excel file for viewing and testing if anyone can help me out with one or both of the issues.

Thanks!

File Attachment:

File Name: TEST-BAHCO...M42.xlsx
File Size:40 KB
Attachments:

Please Log in or Create an account to join the conversation.

More
4 weeks 1 day ago #1868 by Naidi
Naidi replied the topic: Quantity Discount
Hi,

creating a calculator form an excel file is a very easy step.
Here I'm sending you the links to our documentation on how you can achieve that:

altoswebsolutions.com/manual/woo-price-calculator/start

altoswebsolutions.com/live-demo/best-cases

Best regards.
Naidi
AT849

Please Log in or Create an account to join the conversation.

More
1 month 15 hours ago #1866 by Tyler Robinson
Tyler Robinson replied the topic: Quantity Discount
Here is one of the simpler product excel price sheets that my client had. I couldn't figure out how to make this work in the WooPriceCalculator. So, I made a calculator manually.

File Attachment:

File Name: LENOXPalle...terB.xls
File Size:16 KB
Attachments:

Please Log in or Create an account to join the conversation.

More
1 month 17 hours ago #1865 by Tyler Robinson
Tyler Robinson replied the topic: Quantity Discount
I didn't use an excel file for the calculations as my clients excel file was way to complicated. I manually set the calculations with WooPriceCalculator. If I could do it with an excel file, then that would be great, but I'm not sure it could be done.

Please Log in or Create an account to join the conversation.

More
1 month 20 hours ago #1863 by Naidi
Naidi replied the topic: Quantity Discount
Hi,

you can create quantity discounts in another way too.
Firstly remove the default quantity input of Woocommerce, and create a quantity input field with WooPriceCalculator.
Now you can create different rules and logic inside the excel file as you do for the other calculations too.

Best regards.
Naidi
AT84

Please Log in or Create an account to join the conversation.

More
1 month 1 day ago - 1 month 1 day ago #1862 by Tyler Robinson
Tyler Robinson created the topic: Quantity Discount
There are a number of quantity discount plugins out there, but none of them seem to work in tandem with the WooPrice Calculator. I had to resort to custom coding a quantity discount option and it works for the most part. Have you come across a quantity discount plugin that works with WooPrice Calculator?

I have managed to get the correct discounted price per quantity to show in the cart with the correct total price via the code below, but it only works correctly when one product is added to the cart. If you add two or more, then the price doesn't accurately show. The total at the bottom is correct, but the price for the products doesn't show correctly. If I delete the second product from the cart, then the remaining product price shows correctly. I need to figure out how to make them show correctly when multiple products are added as this will confuse the buyer when they see the total (although correct) doesn't match each product price.

To do this, I have added custom fields to the products in the back-end that the discount can be applied to. Can anyone help shed some light on this?

Here is what I have come up with so far in my functions.php file
// Display Fields
add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' );
function woo_add_custom_general_fields() {

	global $woocommerce, $post;
  
	echo '<div class="options_group">';
  
	// Text Field
	woocommerce_wp_text_input( 
		array( 
			'id'          => '_discount_1_4_items', 
			'label'       => __( 'Discount 1-4 items', 'woocommerce' ), 
			'placeholder' => '',
			'desc_tip'    => 'true',
			'description' => __( 'Enter discount percentage amount for 1 to 4 items.', 'woocommerce' ) 
		)
	);
	
	woocommerce_wp_text_input( 
		array( 
			'id'          => '_discount_5_9_items', 
			'label'       => __( 'Discount 5-9 items', 'woocommerce' ), 
			'placeholder' => '',
			'desc_tip'    => 'true',
			'description' => __( 'Enter discount percentage amount for 5 to 9 items.', 'woocommerce' ) 
		)
	);
	
	woocommerce_wp_text_input( 
		array( 
			'id'          => '_discount_10_19_items', 
			'label'       => __( 'Discount 10-19 items', 'woocommerce' ), 
			'placeholder' => '',
			'desc_tip'    => 'true',
			'description' => __( 'Enter discount percentage amount for 10 to 19 items.', 'woocommerce' ) 
		)
	);
	
	woocommerce_wp_text_input( 
		array( 
			'id'          => '_discount_20_items', 
			'label'       => __( 'Discount 20+ items', 'woocommerce' ), 
			'placeholder' => '',
			'desc_tip'    => 'true',
			'description' => __( 'Enter discount percentage amount for 20+ items.', 'woocommerce' ) 
		)
	);
  
	echo '</div>';
	
	echo '<div class="options_group">';
  
	// Text Field
	woocommerce_wp_text_input( 
		array( 
			'id'          => '_discount_1_5_items', 
			'label'       => __( 'Discount 1-5 items', 'woocommerce' ), 
			'placeholder' => '',
			'desc_tip'    => 'true',
			'description' => __( 'Enter discount percentage amount for 1 to 5 items.', 'woocommerce' ) 
		)
	);
	
	woocommerce_wp_text_input( 
		array( 
			'id'          => '_discount_6_10_items', 
			'label'       => __( 'Discount 6-10 items', 'woocommerce' ), 
			'placeholder' => '',
			'desc_tip'    => 'true',
			'description' => __( 'Enter discount percentage amount for 6 to 10 items.', 'woocommerce' ) 
		)
	);
	
	woocommerce_wp_text_input( 
		array( 
			'id'          => '_discount_11_items', 
			'label'       => __( 'Discount 11+ items', 'woocommerce' ), 
			'placeholder' => '',
			'desc_tip'    => 'true',
			'description' => __( 'Enter discount percentage amount for 11+ items.', 'woocommerce' ) 
		)
	);
  
	echo '</div>';
	
}

// Save Fields
add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save' );

function woo_add_custom_general_fields_save( $post_id ){
	
	// Text Field
	$woocommerce_discount_1_4_items = $_POST['_discount_1_4_items'];
	//if( !empty( $woocommerce_discount_1_4_items ) )
		update_post_meta( $post_id, '_discount_1_4_items', esc_attr( $woocommerce_discount_1_4_items ) );
		
	$woocommerce_discount_5_9_items = $_POST['_discount_5_9_items'];
	//if( !empty( $woocommerce_discount_5_9_items ) )
		update_post_meta( $post_id, '_discount_5_9_items', esc_attr( $woocommerce_discount_5_9_items ) );
	
	$woocommerce_discount_10_19_items = $_POST['_discount_10_19_items'];
	//if( !empty( $woocommerce_discount_10_19_items ) )
		update_post_meta( $post_id, '_discount_10_19_items', esc_attr( $woocommerce_discount_10_19_items ) );
	
	$woocommerce_discount_20_items = $_POST['_discount_20_items'];
	//if( !empty( $woocommerce_discount_20_items ) )
		update_post_meta( $post_id, '_discount_20_items', esc_attr( $woocommerce_discount_20_items ) );
	
	$woocommerce_discount_1_5_items = $_POST['_discount_1_5_items'];
	//if( !empty( $woocommerce_discount_1_5_items ) )
		update_post_meta( $post_id, '_discount_1_5_items', esc_attr( $woocommerce_discount_1_5_items ) );
	
	$woocommerce_discount_6_10_items = $_POST['_discount_6_10_items'];
	//if( !empty( $woocommerce_discount_6_10_items ) )
		update_post_meta( $post_id, '_discount_6_10_items', esc_attr( $woocommerce_discount_6_10_items ) );
	
	$woocommerce_discount_11_items = $_POST['_discount_11_items'];
	//if( !empty( $woocommerce_discount_11_items ) )
		update_post_meta( $post_id, '_discount_11_items', esc_attr( $woocommerce_discount_11_items ) );
	
}

add_filter( 'woocommerce_cart_item_subtotal', 'wp_update_woocommerce_cart_item_subtotal', 99, 3 );
function wp_update_woocommerce_cart_item_subtotal( $subtotal, $cart_item, $cart_item_key ){
        $qty = $cart_item['quantity'];

        $discount1 = get_post_meta($cart_item['product_id'], '_discount_1_4_items', true);
        $discount2 = get_post_meta($cart_item['product_id'], '_discount_5_9_items', true);
        $discount3 = get_post_meta($cart_item['product_id'], '_discount_10_19_items', true);
        $discount4 = get_post_meta($cart_item['product_id'], '_discount_20_items', true);

        $discount1_1 = get_post_meta($cart_item['product_id'], '_discount_1_5_items', true);
        $discount2_2 = get_post_meta($cart_item['product_id'], '_discount_6_10_items', true);
        $discount3_3 = get_post_meta($cart_item['product_id'], '_discount_11_items', true);

        $OriginalPrice = $cart_item['data']->get_price();

        if($discount1){
            if($qty >= 1 && $qty <=4){
                $FinalPrice = $OriginalPrice*$discount1;
            }elseif($qty >= 5 && $qty <=9){
                $FinalPrice = $OriginalPrice*$discount2;
            }elseif($qty >= 10 && $qty <=19){
                $FinalPrice = $OriginalPrice*$discount3;
            }elseif($qty >= 20 ){
                $FinalPrice = $OriginalPrice*$discount4;
            }
        }
        if($discount1_1){
            if($qty >= 1 && $qty <=5){
                $FinalPrice = $OriginalPrice*$discount1_1;
            }elseif($qty >= 6 && $qty <=10){
                $FinalPrice = $OriginalPrice*$discount2_2;
            }elseif($qty >= 11 ){
                $FinalPrice = $OriginalPrice*$discount3_3;
            }
        }

        $subtotal = wc_price( $FinalPrice * $cart_item['quantity']);

        //return sprintf( '<s>%s</s> %s', $subtotal, $newsubtotal );
        //$cart_item['data']->set_price( $FinalPrice * $cart_item['quantity'] );

return $subtotal;

}

add_action( 'woocommerce_add_cart_item_data', 'save_custom_data_hidden_fields', 10, 2 );
function save_custom_data_hidden_fields( $cart_item_data, $product_id ) {

    $data = array();

    $cart_item_data['custom_data']['discount_1'] = get_post_meta($product_id, '_discount_1_4_items', true);
    $data['discount_1'] = get_post_meta($product_id, '_discount_1_4_items', true);

    $cart_item_data['custom_data']['discount_2'] = get_post_meta($product_id, '_discount_1_4_items', true);
    $data['discount_2'] = get_post_meta($product_id, '_discount_5_9_items', true);

    $cart_item_data['custom_data']['discount_3'] = get_post_meta($product_id, '_discount_1_4_items', true);
    $data['discount_3'] = get_post_meta($product_id, '_discount_10_19_items', true);

    $cart_item_data['custom_data']['discount_4'] = get_post_meta($product_id, '_discount_1_4_items', true);
    $data['discount_4'] = get_post_meta($product_id, '_discount_20_items', true);

    $cart_item_data['custom_data']['discount_1_1'] = get_post_meta($product_id, '_discount_1_5_items', true);
    $data['discount_1_1'] = get_post_meta($product_id, '_discount_1_5_items', true);

    $cart_item_data['custom_data']['discount_2_2'] = get_post_meta($product_id, '_discount_6_10_items', true);
    $data['discount_2_2'] = get_post_meta($product_id, '_discount_6_10_items', true);

    $cart_item_data['custom_data']['discount_3_3'] = get_post_meta($product_id, '_discount_11_items', true);
    $data['discount_3_3'] = get_post_meta($product_id, '_discount_11_items', true);

    // below statement make sure every add to cart action as unique line item
    $cart_item_data['custom_data']['unique_key'] = md5( microtime().rand() );
    WC()->session->set( 'price_calculation', $data );

    return $cart_item_data;
}

// Change the cart prices if a unit_price is set
add_filter( 'woocommerce_before_calculate_totals', 'sv_change_product_price_cart', 10, 3 );
function sv_change_product_price_cart( $cart ) {

    foreach ( $cart->get_cart() as $cart_item_key => $cart_item ) {
        // The instance of the WC_Product Object
        $product = $cart_item['data'];
        $product_id = $product->get_id(); // The product ID

        $price = $product->get_price(); // The product price
        $qty = $cart_item['quantity'];


        $discount1 = get_post_meta($cart_item['product_id'], '_discount_1_4_items', true);
        $discount2 = get_post_meta($cart_item['product_id'], '_discount_5_9_items', true);
        $discount3 = get_post_meta($cart_item['product_id'], '_discount_10_19_items', true);
        $discount4 = get_post_meta($cart_item['product_id'], '_discount_20_items', true);

        $discount1_1 = get_post_meta($cart_item['product_id'], '_discount_1_5_items', true);
        $discount2_2 = get_post_meta($cart_item['product_id'], '_discount_6_10_items', true);
        $discount3_3 = get_post_meta($cart_item['product_id'], '_discount_11_items', true);

        if($discount1){
            if($qty >= 1 && $qty <=4){
                $discount = $discount1;
            }
            if($qty >= 5 && $qty <=9){
                $discount = $discount2;
            }
            if($qty >= 10 && $qty <=19){
                $discount = $discount3;
            }
            if($qty >= 20 ){
                $discount = $discount4;
            }
        }
        if($discount1_1){
            if($qty >= 1 && $qty <=5){
                $discount = $discount1_1;
            }
            if($qty >= 6 && $qty <=10){
                $discount = $discount2_2;
            }
            if($qty >= 11 ){
                $discount = $discount3_3;
            }
        }

        // Set the new cart item price
        $product->set_price( $price*$discount );
    }


}

In my cart.php template file within the foreach loop:
$qty = $cart_item['quantity'];

                $discount1 = get_post_meta($cart_item['product_id'], '_discount_1_4_items', true);
                $discount2 = get_post_meta($cart_item['product_id'], '_discount_5_9_items', true);
                $discount3 = get_post_meta($cart_item['product_id'], '_discount_10_19_items', true);
                $discount4 = get_post_meta($cart_item['product_id'], '_discount_20_items', true);

                $discount1_1 = get_post_meta($cart_item['product_id'], '_discount_1_5_items', true);
                $discount2_2 = get_post_meta($cart_item['product_id'], '_discount_6_10_items', true);
                $discount3_3 = get_post_meta($cart_item['product_id'], '_discount_11_items', true);

                $OriginalPrice = $cart_item['data']->get_price();

                if($discount1){
                    if($qty >= 1 && $qty <=4){
                        $discount = $discount1;
                    }
                    if($qty >= 5 && $qty <=9){
                        $discount = $discount2;
                    }
                    if($qty >= 10 && $qty <=19){
                        $discount = $discount3;
                    }
                    if($qty >= 20 ){
                        $discount = $discount4;
                    }
                }
                if($discount1_1){
                    if($qty >= 1 && $qty <=5){
                        $discount = $discount1_1;
                    }
                    if($qty >= 6 && $qty <=10){
                        $discount = $discount2_2;
                    }
                    if($qty >= 11 ){
                        $discount = $discount3_3;
                    }
                }

                $cart_item['data']->set_price( $OriginalPrice*$discount );

I've also had to replace the Price call (cart.php):
echo (apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $_product ), $cart_item, $cart_item_key )*); // PHPCS: XSS ok.
With:
echo '<span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">$</span>'.number_format((float)$OriginalPrice, 2, '.', '').'</span>';
Last Edit: 1 month 1 day ago by Tyler Robinson.

Please Log in or Create an account to join the conversation.

Moderators: david
Time to create page: 0.210 seconds

Cart

Total : 0.00 €