Total : 0.00 €

Woo Price Calculator User Manual

16.1 - Change the price - WPC

You can manipulate the final price of WPC PRO by using our custom function. Have a look at these examples below:

You can write it in your Wordpress theme functions.php:

/* For WPC >= 2.3.0

*	$price						The price
*	$params['errors']			List of errors
*	$params['priceRaw'] 		The price (No formatting)
*	$params['product']			The product data
*	$params['calculator']		The calculator
*	$params['data']				Raw user data
*	$params['userData']			Transformed user data
*	$params['outputResults']	Calculated output fields
*	$params['formatPrice']		Should the price be formatted?
*/
function custom_awspc_filter_calculate_price($price, $params){
	$price = $price*5;

	return $price;
}
add_filter('awspc_filter_calculate_price', 'custom_awspc_filter_calculate_price', 10, 2); 

/* For WPC < 2.3.0 (Deprecated) 
*	$price						The price
*	$product_id					The product ID
*	$calculator_id				The calculator ID
*	$data						Input values
*/
function cmw_custom_price($price, $product_id, $calculator_id, $data){
	$price = $price*5;

	return $price;
}
add_filter('woo_price_calculator_calculate_price', 'cmw_custom_price', 10, 4); 

add_filter is a core function of Wordpress, click here if you want more details.

If you want to change only the AJAX response use:

/* For WPC >= 2.3.0
*	$response['errorsCount']		Number of field errors
*	$response['errors']				List of field errors
*	$response['price']				The formatted price
*	$response['priceRaw']			Raw price
*	$response['outputFields']		List of the output fields
*	$response['conditionalLogic']	The conditional logic

*	$params['productId']			The product ID
*	$params['calculator']			The calculator
*	$params['fields']				The fields
*	$params['postData']				User data (No transformation)
*	$params['conditionalLogic']		The conditional logic
*	$params['outputResults']		The output results
*	$params['errors']				List of field errors
*	$params['price']				The formatted price
*	$params['priceRaw']				Raw price
*/
function custom_awspc_filter_calculate_price_ajax_response($response, $params){
	return $response;
}
add_filter('awspc_filter_calculate_price_ajax_response', 'custom_awspc_filter_calculate_price_ajax_response', 10, 2);

If you want to change the product price in cart page (for example to add different type of taxes, surcharges, or create discounts) for the current product in the cart:

/* For WPC >= 2.4.0
*	$productPrice			The current calculated product price.
*	$fieldsData				The data for each calculator field (Use: printf($fieldsData); to see the content)
*	$outputFields			The data for each output calculator field (Use: printf($outputFields); too see the content)
*/
function custom_awspc_filter_calculate_price_in_cart($productPrice, $fieldsData, $outputFields){
	$newProductPrice	= $productPrice + 100;
    
	return $newProductPrice;
}
add_filter('awspc_filter_calculate_price_in_cart', 'custom_awspc_filter_calculate_price_in_cart', 10, 3);

Cart

Total : 0.00 €