Filter : ‘wdm_csp_apply_quantity_price_in_cart’ – Manage application of the CSP prices in the cart.

Filter : wdm_csp_apply_quantity_price_in_cart

As the title of the article suggests, the CSP filter hook ‘wdm_csp_apply_quantity_price_in_cart‘ can be used in order to manage the application of the CSP prices in the cart.

You may require to prevent the application of CSP prices in the cart for some products. Using this filter you can conditionally manage the same.

The following examples will demonstrate the use of this filter.

Example #1 – How to manage the application of CSP in the cart specific to the user.

Prevent CSP prices for a user Id #123 because of some reason.

add_filter('wdm_csp_apply_quantity_price_in_cart', 'applyCSPInCart', 11, 3);
if (!function_exists('applyCSPInCart')) {
	function applyCSPInCart($apply, $cart_product_id, $cart_item) {
		$userId = get_current_user_id();
		if(0!==$userId && 123===$userId) {
		$apply = false;
		}
		return $apply;
	}	
}

This way you can conditionally manage CSP prices in the cart for the users.

Example #2 -Prevent CSP on certain product types.

If you are using the bundling plugin ‘YITH Product Bundles’ and want CSP to not apply to the bundled products.

add_filter('wdm_csp_apply_quantity_price_in_cart', 'applyCSPInCart', 11, 3);
if (!function_exists('applyCSPInCart')) {
	function applyCSPInCart($apply, $cart_product_id, $cart_item) {
		if ('yith_bundle'===$cart_item['data']->get_type()) {
            $apply = false;
        } elseif (isset($cart_item['bundled_by']) && !empty($cart_item['bundled_by'])) {
			$apply =false;
		} 
		return $apply;
	}	
}

The code above will not let CSP prices apply to the bundled products & the products wrapped in the bundles.

Find a list of useful action & filter hooks here.

Updated on December 11, 2020

Was this article helpful?

Related Articles