1

I have a new custom field named super_sale_price, and I'm trying to use that value for every product, so if this custom field value is exists,then we will show this in every where for that product,

I used this to display that price,

function return_custom_price($price, $product) {
    global $post, $blog_id;

     $price = get_post_meta($post->ID, 'super_sale_price', true);


    return $price;
}
add_filter('woocommerce_get_price', 'return_custom_price', 10, 2); 

This changes value in single product page, but once I add this product to cart, there the price shows 0. Please someone tell me why this happening ? Is this is a wrong hook?

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Ashkar
  • 712
  • 6
  • 17

1 Answers1

0

The hook that you are using is deprecated, Instead Try this instead:

add_filter('woocommerce_product_get_price', 'display_super_sale_price', 10, 2); 
function display_super_sale_price( $price, $product ) {
    if( $product->get_meta('super_sale_price') );
        $price = $product->get_meta('super_sale_price');

    return $price;
}

Code goes in function.php file of your active child theme (or active theme). It should work.

For variable products and product variations, see this answers threads:

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399