• There is a function in functions.php where I need to work with discounts.

    I have created a discount campaign with finale lite. In the front-end it works fine with a discount in the cart.

    I am trying to get the sale price in the functions.php. I tried:
    $product->get_price();
    $product->get_regular_price();
    $product->get_sale_price();
    All of the above return the price before the discount.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author XLPlugins

    (@xlplugins)

    Hi @nbdevelopgreece,

    There’s a filter hook in Finale which you can use to get the Finale’s discounted price.

    This filter is ‘wcct_finale_discounted_price’.

    Use this in functions.php file as following :

    add_filter(‘wcct_finale_discounted_price’,’custom_finale_sales_price’,10,3);
    function custom_finale_sales_price($sale_price,$regular_price,$product_id){
    $s_price = $sale_price;
    $r_price = $regular_price;
    if(‘ ‘!=$s_price)
    {
    return $s_price;
    }
    else
    {
    return $r_price;
    }
    }

    Let us know if you have any other query.

    Thread Starter nbdevelopgreece

    (@nbdevelopgreece)

    Hi @xlplugins and thank you for your reply.

    Unfortunately this is not working. My thought is that I can not use this filter if I do not know the sale price in the first place.

    The basic code I have is:

    
    $product = wc_get_product( $ID );
    
    $normal_price = $product->get_price();
    echo $normal_price; //it prints normally
    
    $finale_sale_price = //what must I do to get the finale sale price here?
    echo $finale_sale_price; 
    
    //I also tried (with no result)
    //to get first variation	
    $product_variations = $product->get_available_variations();
    $variation_product_id = $product_variations [0]['variation_id'];
    $variation_product = new WC_Product_Variation( $variation_product_id );
     
    //based on first variation get regular and sale price
    echo $variation_product->regular_price; //displays regular price normally
    echo $variation_product->get_sale_price; //empty
    echo $variation_product->get_variation_sale_price; //empty
    print_r($product->get_variation_prices()); //displays an array with variations all of them with the regular prices
    echo $product->get_variation_regular_price(min,false); //displays regular price normally
    echo $product->get_variation_sale_price(min,false); //displays regular price
    echo $product->get_variation_price(min,false); //displays regular price
    
    Plugin Author XLPlugins

    (@xlplugins)

    Hi @nbdevelopgreece,

    Okay got you.

    Try this :

    $product = wc_get_product( $ID );

    $normal_price = $product->get_price();
    echo $normal_price; //it prints normally

    $finale_sale_price = add_filter(‘wcct_finale_discounted_price’,’custom_finale_sales_price’,10,3); //what must I do to get the finale sale price here?
    echo $finale_sale_price;

    //I also tried (with no result)
    //to get first variation
    $product_variations = $product->get_available_variations();
    $variation_product_id = $product_variations [0][‘variation_id’];
    $variation_product = new WC_Product_Variation( $variation_product_id );

    //based on first variation get regular and sale price
    echo $variation_product->regular_price; //displays regular price normally
    echo $variation_product->get_sale_price; //empty
    echo $variation_product->get_variation_sale_price; //empty
    print_r($product->get_variation_prices()); //displays an array with variations all of them with the regular prices
    echo $product->get_variation_regular_price(min,false); //displays regular price normally
    echo $product->get_variation_sale_price(min,false); //displays regular price
    echo $product->get_variation_price(min,false); //displays regular price

    I have added $finale_sale_price = add_filter(‘wcct_finale_discounted_price’,’custom_finale_sales_price’,10,3) in the code.

    Let us know if it doesn’t work.

    Plugin Author XLPlugins

    (@xlplugins)

    Hi @nbdevelopgreece,

    May I know which hook you are using on functions.php file to get product details like regular price, sale price etc.

    I cannot see any hook in the above code.

    Let us know.

    Thread Starter nbdevelopgreece

    (@nbdevelopgreece)

    Hi @xlplugins,

    I tried what you suggested and it is not working (it seemed it would not work in the first place to be honest because there is no connection with $product).

    Also what do you mean hook? I get the product details in the $product object with:
    $product = wc_get_product( $ID );

    Then I get the price with: $product->get_price()
    or (i.e.) the title with: $product->get_name()

    Plugin Author XLPlugins

    (@xlplugins)

    Hi @nbdevelopgreece,

    We need some more details so kidnly raise a support ticket here https://xlplugins.com/support/

    We monitor support tickets through the support desk every hour.

    Please share the site details and query with screenshot in our support desk on above given link

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to get discount price (Function equivalent to get_sale_price();)’ is closed to new replies.