Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #689009

    Hi,

    Thanks for the latest updates in the theme. Great work.

    I was wondering if there is a way to get the sale period available in a woocoom product that has a special price for a certain period. Have tried all tricks but I ran out of ideas. I guess som custom code is needed – can you help me?

    Best regards

    #690144

    Hi Zest!

    Thank you for using Enfold.

    This is possible but you have to create a custom field and the sale price will not be automatically updated after the date expiration. In a product, add a custom field called “sale_expiration” and add a date with Y-m-d format (ex: 2016-10-18). After that, add this in the functions.php file:

    add_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_sale_expiration', 1 );
    function woocommerce_output_sale_expiration() {
    	$salexp = get_post_meta(get_the_ID(), 'sale_expiration', true);
    	$salexpiration = strtotime($salexp);
    	$expiration = $salexpiration + (7 * 24 * 60 * 60);
    	$today = current_time('timestamp');
    	$date = date("F j, Y", strtotime($salexp));
    
    	if($expiration > $today)
    	{
    		echo "Sale price valid until: " . $date;
    	}
    }
    

    The sale price is still valid so it should render the following text:

    Sale price valid until: October 18, 2016
    

    Best regards,
    Ismael

    #690166

    Hi,

    Thanks for your reply. Just to be sure – can I not use the existing sales price that i have in the woo installation? Pls see the screenshot

    https://www.dropbox.com/s/jeho7ikvwrasn37/2016-09-22_09-50-04.jpg?dl=0

    Best regards

    #691078

    Hey!

    I forgot about that. Please use this instead:

    add_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_sale_expiration', 1 );
    function woocommerce_output_sale_expiration() {
    	global $post;
    	$sales_price_to = get_post_meta($post->ID, '_sale_price_dates_to', true);
        if(is_single() && $sales_price_to != "")
        {
            $salexp = $sales_price_to;
        }
    	$salexpiration = strtotime($salexp);
    	$expiration = $salexpiration + (7 * 24 * 60 * 60);
    	$today = current_time('timestamp');
    	$date = date("F j, Y", strtotime($salexp));
    
    	if($expiration > $today)
    	{
    		echo "Sale price valid until: " . $date;
    	}
    }

    Cheers!
    Ismael

    #691561

    Thanks so much. With minor modifications I got it to work with start sale date and end sale date. Really appreciate it!

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Sales price valid time’ is closed to new replies.