There is a really simple and smart trick to change the position of the price in WooCommerce & WPC.
Follow these steps:
- Install the "Simple CSS and JS" plugin, you can find it by clicking here: This plugin let you add custom CSS and JS code to your website. This is what we need to change the price position.
- Create a new JS by clicking on "Custom CSS & JS > Add Custom JS".
- Copy and paste the JS code below and save the JS code.
- You're done, now you can see the price position has moved from top to page bottom.
Here is the JS code:
jQuery(document).ready(function( $ ){
if($(".wpc_simulator_id").length){
$(".product .price").hide();
$( ".wpc-product-form" ).after('<p class="price"><span class="woocommerce-Price-amount amount"></span></div>');
WooPriceCalculator.calculateProductPrice();
}
});
Among the very common and the most regular complains coming from the clients is about the Excel file they use for the WPC formula.
Whether it is about the slow processing speed or complex calculation, it certainly affects the performance of the calculator.
To handle such issues and provide a guideline in advance, our team of experts has created an Excel template which can be mapped or used for almost every kind of Excel formula which you want to write for your WooPrice Calculator.
Continue Reading
If you want to show your calculator in a Wordpress page, you can use the WoooCommerce shortcode [product_page id="PRODUCT_ID"] to do that.
How to use your Shortcode?
In this example, it is explained how to show the calculator on a Wordpress "Page" (But of course you can add this shortcode wherever you want on your Wordpress website).
- In your WP-admin click on "Pages" > "Add new" (But if you have an existing page, edit it)
-
Add the shortcode [product_page id="PRODUCT_ID"] ensuring that you are using the "Text" editor as in some cases the "Visual" editor can change your text and make your shortcode unable to work:
Continue Reading
If you want to check the WooCommerce product price before your customer adds a product to the cart, you cannot use the "woocommerce_add_to_cart_validation" function. But the following is a really smart trick about how to do that:
This piece of code checks if the price is 0, in this case, an error message will be shown and the product will be removed from the cart, so the customer cannot buy it.
Checking add to cart price
To make this piece of code work, you need to append it to your "functions.php" file, located in your "/wp-content/themes/YOUR_THEME/ path":
/* Price must be different from 0 to be added to the cart */
function filter_custom_wpc_add_to_cart_callback($cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data){
global $woocommerce;
foreach(WC()->cart->get_cart() as $cart_item_key => $values){
$cartItemPrice = $values['data']->get_price();
if($cartItemPrice == 0){
/* Showing the error message */
wc_add_notice("Sorry but it's not possible to add this product to cart", "error");
/* Removing the product from the cart */
$woocommerce->cart->remove_cart_item($cart_item_key);
return;
}
}
}
add_action('woocommerce_add_to_cart', 'filter_custom_wpc_add_to_cart_callback', 20, 6);
Continue Reading
If you want to do more validation before adding a product to the cart (For example if you want to check "height + width" is less than a predetermined value), then this article is for you.
Using WooPrice Calculator you can set a minimum and maximum values for each field but you cannot validate more complex rules.
With Wordpress, WooPrice Calculator and WooCommerce this is really simple by using filters. You can use the filter "woocommerce_add_to_cart_validation" to do that.
How to make the validation?
For example, if you want check "height + width" must be less then 2000, you can append this new PHP function to your "functions.php" file, located in "/wp-content/themes/YOUR_THEME/": path.
function filter_custom_wpc_add_to_cart_validation($bool, $product_id, $quantity){
if($product_id == 40){
$width = $_REQUEST['aws_price_calc_1'];
$height = $_REQUEST['aws_price_calc_2'];
if(($width+$height) >= 2000){
wc_add_notice("Width and Height are greater then 2000 mm", "error");
return false;
}
}
return true;
}
add_filter('woocommerce_add_to_cart_validation', 'filter_custom_wpc_add_to_cart_validation', 20, 3);
Continue Reading