-
AuthorPosts
-
September 20, 2016 at 8:41 am #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
September 22, 2016 at 8:28 am #690144Hi 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,
IsmaelSeptember 22, 2016 at 8:53 am #690166Hi,
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
September 24, 2016 at 5:50 am #691078Hey!
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!
IsmaelSeptember 26, 2016 at 11:44 am #691561Thanks so much. With minor modifications I got it to work with start sale date and end sale date. Really appreciate it!
-
AuthorPosts
- The topic ‘Sales price valid time’ is closed to new replies.