2014-04-27 72 views
0

我发现这个线程在WordPress http://wordpress.org/support/topic/get-woocommerce-scheduled-sale-end-date?replies=15显示woocommerce销售结束日期

但是当我试了一下,没有工作。也许是因为答案太旧了。

任何人都知道如何获得预定的销售woocommerce产品的结束日期?

这是我迄今为止

$sale_price_dates_to = ($date = get_post_meta($thepostid, '_sale_price_dates_to', true)) ? date_i18n('Y-m-d', $date) : ''; 
echo $sale_price_dates_to; 

返回

string(0) "" 

感谢

回答

5

this页的例子,详细介绍如何可以做到:
添加以下到functions.php文件

add_filter('woocommerce_get_price_html', 'custom_price_html', 100, 2); 
function custom_price_html($price, $product) 
{ 
    global $post; 
    $sales_price_to = get_post_meta($post->ID, '_sale_price_dates_to', true); 
    if(is_single() && $sales_price_to != "") 
    { 
     $sales_price_date_to = date("j M y", $sales_price_to); 
     return str_replace('</ins>', ' </ins> <b>(Offer till '.$sales_price_date_to.')</b>', $price); 
    } 
    else 
    { 
     return apply_filters('woocommerce_get_price', $price); 
    } 
} 

我已经在我的网站上试过了,它适用于我。

+0

看起来这可能是默认的单品页面整洁的解决方案。太好了!但是,我需要以销售价格单独显示日期。 – Wayne

+0

我怎么能把西班牙文的日期格式,这工作整齐。 Thnaks –

2

这对我的作品:)

$thepostid = get_the_ID(); 
    $sale_price_dates_to = ($date = get_post_meta($thepostid, '_sale_price_dates_to', true)) ? date_i18n('Y-m-d', $date) : ''; 
相关问题