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

Calculating a maximum width

More
7 months 2 weeks ago - 7 months 2 weeks ago #1371 by Enrico
Enrico replied the topic: Calculating a maximum width
Hi Robin,

If you need to apply the same validation to all the WooCommerce products:
function filter_custom_wpc_add_to_cart_validation($bool, $product_id, $quantity){

		$sideA		= $_REQUEST['aws_price_calc_ID1'];
		$sideB		= $_REQUEST['aws_price_calc_ID2'];
		
		if(($sideA+$sideB) > 1500){
			wc_add_notice("SideA and SideB are greater then 1500 mm", "error");
			
			return false;
		}

	return true;
}
add_filter('woocommerce_add_to_cart_validation', 'filter_custom_wpc_add_to_cart_validation', 20, 3);

If you want to apply the same validation only to some products:
function filter_custom_wpc_add_to_cart_validation($bool, $product_id, $quantity){
        $products = array(PROD_ID1, PROD_ID2, PROD_ID3, PROD_ID4);

	if(in_array($product_id, $products)){
		$sideA		= $_REQUEST['aws_price_calc_ID1'];
		$sideB		= $_REQUEST['aws_price_calc_ID2'];
		
		if(($sideA+$sideB) > 1500){
			wc_add_notice("SideA and SideB are greater then 1500 mm", "error");
			
			return false;
		}
	}
	
	return true;
}
add_filter('woocommerce_add_to_cart_validation', 'filter_custom_wpc_add_to_cart_validation', 20, 3);

If you want to check different validation values for different products you can:
function filter_custom_wpc_add_to_cart_validation($bool, $product_id, $quantity){
        $values = array(
            PROD_ID1     => 1500,
            PROD_ID2      => 1250,
            PROD_ID3       => 1000,
            PROD_ID4     => 2000,
        );

	if(array_key_exists($product_id, $values)){
		$sideA		= $_REQUEST['aws_price_calc_ID1'];
		$sideB		= $_REQUEST['aws_price_calc_ID2'];
		
		if(($sideA+$sideB) > $values[$product_id]){
			wc_add_notice("SideA and SideB are greater then {$values[$product_id]} mm", "error");
			
			return false;
		}
	}
	
	return true;
}
add_filter('woocommerce_add_to_cart_validation', 'filter_custom_wpc_add_to_cart_validation', 20, 3);

Where:

PROD_ID1, PROD_ID2, PROD_ID3, PROD_ID4, IDn is the product ID

Kind Regards,
Enrico
AT234
Last Edit: 7 months 2 weeks ago by Enrico.

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

More
7 months 2 weeks ago - 7 months 2 weeks ago #1364 by Robin Hollaar
Robin Hollaar replied the topic: Calculating a maximum width
Hi Enrico,

Yeah the code is working now.
If I want to do the same validation on more product's is its possible to add more product id's to the code or do I need to copy paste a new code. ?

Robin
Last Edit: 7 months 2 weeks ago by Robin Hollaar.

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

More
7 months 2 weeks ago #1358 by Enrico
Enrico replied the topic: Calculating a maximum width
Hi Robin,

There was a problem on the plugin that wasn't executing your code correctly.

I've installed in your website the 2.2.1 version (bugfix). You can download it from here for future reference:


Part of the message is hidden for the guests. Please log in or register to see it.


Your code is working ok now.

Kind Regards,
Enrico
AT234
The following user(s) said Thank You: Robin Hollaar

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

More
7 months 2 weeks ago #1354 by Enrico
Enrico replied the topic: Calculating a maximum width
Hi Robin,

Please send me your WP-admin and your FTP credentials to " altoswebsolutions.com/contact-us ", I will look into the problem directly.

Kind Regards,
Enrico
AT234

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

More
7 months 2 weeks ago - 7 months 2 weeks ago #1346 by Robin Hollaar
Robin Hollaar replied the topic: Calculating a maximum width
Thanks enrico

After adding the code to the function.php I now have the warning but still the product gets add to the basket.

Is there a fix to this or am i missing something ?
Last Edit: 7 months 2 weeks ago by Robin Hollaar.

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

More
7 months 3 weeks ago #1326 by Enrico
Enrico replied the topic: Calculating a maximum width
Hi Robin,

You can use PHP filters to do that. Please read this article here: altoswebsolutions.com/blog/more-validati...lculator-woocommerce

In your case would be something like this:
function filter_custom_wpc_add_to_cart_validation($bool, $product_id, $quantity){
	if($product_id == PRODUCT_ID){
		$sideA		= $_REQUEST['aws_price_calc_ID1'];
		$sideB		= $_REQUEST['aws_price_calc_ID2'];
		
		if(($sideA+$sideB) > 1500){
			wc_add_notice("SideA and SideB are greater then 1500 mm", "error");
			
			return false;
		}
	}
	
	return true;
}
add_filter('woocommerce_add_to_cart_validation', 'filter_custom_wpc_add_to_cart_validation', 20, 3);

Where:

PRODUCT_ID: Your product ID
ID1: The WPC field ID of SideA
ID2: The WPC field ID of SideB


Follow the instructions on the article how to add this code in your website.

Kind Regards,
Enrico
AT234

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

More
7 months 3 weeks ago #1318 by Robin Hollaar
Robin Hollaar created the topic: Calculating a maximum width
Hi,

I want to set a maximum width. The situation

Side A = 100 mm
Side B = 100 mm

A+B Total = 200 mm [Max of 1500mm] I want a message to appear if the total amount is more than 1500 mm that you are not able to order because the max with = 1500 mm And that your not able to order.

Greetz Robin.

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

Moderators: david
Time to create page: 0.648 seconds

Cart

Total : 0.00 €