2014-04-27 69 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) : ''; 
相關問題