• Resolved rgbear

    (@rgbear)


    Hi I made a filter function to modify prices of products, but in cart and checkout page products get 0 as price.

    This is the function:

    add_filter('woocommerce_get_price', 'return_custom_price', 10, 2);
    add_filter( 'woocommerce_product_get_price', 'return_custom_price', 10, 2 );
    add_filter( 'woocommerce_product_variation_get_price', 'return_custom_price', 10, 2 );
    add_filter( 'woocommerce_product_get_regular_price', 'return_custom_price', 10, 2 );
    add_filter( 'woocommerce_product_get_sale_price', 'return_custom_price', 10, 2 );
    
    		function return_custom_price($price, $product) {
    			global $post, $blog_id;
    			$post_id = $value['product_id'];
    			$price = get_post_meta($post->ID, '_regular_price', true);
    			$ssivata = 7.93;
    			$tax = 122/100;
    			$shipping = 6.5;
    			//calcola prezzo di fabbrica
    			$price = $price - $ssivata;
    			$price = $price / $tax;
    			//calcolo del prezzo
    			$price = $price + $shipping;
    			$price = $price*$tax;
    			return $price;
    	
    	}
    
    • This topic was modified 5 years, 11 months ago by rgbear.
Viewing 1 replies (of 1 total)
  • Thread Starter rgbear

    (@rgbear)

    FIXED seems to work fine. Global variables broke the cart.

    function product_custom_price($price, $product) {
    	$custom_price = $product->get_regular_price();
    	$ssivata = 7.93;
    	$tax = 122/100;
    	$shipping = 6.5;
    	//calcola prezzo di fabbrica
    	$custom_price = $custom_price - $ssivata;
    	$custom_price = $custom_price / $tax;
    	//calcolo del prezzo
    	$custom_price = $custom_price + $shipping;
    	$custom_price = $custom_price * $tax;
        return $custom_price;
    }
    add_filter('woocommerce_product_get_price', 'product_custom_price', 10, 2);
    add_filter( 'woocommerce_product_variation_get_price', 'product_custom_price', 10, 2 );
    add_filter( 'woocommerce_product_get_sale_price', 'product_custom_price', 10, 2 );
    
    • This reply was modified 5 years, 11 months ago by rgbear.
Viewing 1 replies (of 1 total)
  • The topic ‘get_price breaks cart and checkout’ is closed to new replies.