Modifying cart prices with php

[ad_1]

add_filter( "wdp_custom_override_cents", function ( $custom_price, $price, $context, $product ) {
	
	//set custom price
	
	return $custom_price;
	
}, 10, 4 );

I’ve been able to use this hook as a workaround, open to a more efficient better hook to use if anyone has a suggestion!

hi

Do you want to modify prices for cart items after our rules were applied ?

Do you want to modify prices for cart items after our rules were applied ?

Yes, so I’d like the rules to apply as normal, but for specific customers I want to apply my own custom pricing list, but I’m not sure at what point I can hook the cart process to do this and make sure it applies to the actual order processing and not just visually

so you tried this hook ?
add_filter('adp_before_apply_rule', function($rule, $processor, $cart){
return $rule;
},10,3);

Can you share your code and screenshot of the rule ?

I was not able to test adp_before_apply_rule because I think that would require me to have more complex knowledge of how ADP’s rules are structured in PHP, and I lack the time to reverse engineer that, my rules are thousands of simple bulk quantity discounts, then I have my own database with specific user ID prices in, that I want to lookup and apply different prices that over-ride the bulk discounts, my functions are rather long and complex to get the prices, cache them etc, but I was able to get the desired output using this function

add_filter( "wdp_custom_override_cents", function ( $custom_price, $price, $context, $product ) {
	
	$user_price = lookup_customer_price($product);
	
	if ($user_price !== null){
		$custom_price = $user_price;
		return $custom_price;
	}
	
}, 10, 4 );

can you think of a more efficient way to do it? my lookup price function will return null if user is not logged in or is not in the list etc

this hook is applied at the end of all calculations, so it’s definitely effective.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer