I have tried to write a code in order to change the price of the products dynamically when a user tries to change the quantity of the product. After placing the code in the functions file I am getting a 500 error on my website my website is not accessible. Can someone please check where am I wrong doing this.
function return_custom_price($price, $product) {
$product =wc_get_product( $post->ID );
//global $post, $woocommerce;
$price = get_post_meta($product->id, '_price', true);
global $woocommerce;
$items = $woocommerce->cart->get_cart();
foreach ($items as $cart_item_key => $values) {
$quantity = $values['quantity'];
$cartProduct = $values['data'];
if ($quantity < 10)
return $price;
// do the ranges
if ($quantity >= 10 && $quantity <= 24)
return $product->get_attribute('10-24');
if ($quantity >= 25 && $quantity <= 49)
return $product->get_attribute('25-49');
if ($quantity >= 50) // originally 50-99
return $product->get_attribute('50-99');
/*
if ($quantity >= 100 && $quantity <= 249)
return $product->get_attribute('100-249');
if ($quantity >= 250 && $quantity <= 499)
return $product->get_attribute('250-499');
if ($quantity >= 500 && $quantity <= 999)
return $product->get_attribute('500-999');
if ($quantity >= 1000 && $quantity <= 2499)
return $product->get_attribute('1000-2499');
if ($quantity >= 2500)
return $product->get_attribute('2500');
*/
}
return $price;
}
if (!is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) {
add_filter('woocommerce_get_price', 'return_custom_price', $product, 2);
}