显示woocommerce销售结束日期

Way*_*yne 1 php wordpress woocommerce

我在wordpress中找到了这个帖子 http://wordpress.org/support/topic/get-woocommerce-scheduled-sale-end-date?replies=15

但是当我尝试它时,它没有用.也许是因为答案太旧了.

任何人都知道如何获得定期销售的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;
Run Code Online (Sandbox Code Playgroud)

它返回

string(0) ""
Run Code Online (Sandbox Code Playgroud)

谢谢

Way*_*yne 6

这对我有用:)

    $thepostid = get_the_ID();
    $sale_price_dates_to    = ( $date = get_post_meta( $thepostid, '_sale_price_dates_to', true ) ) ? date_i18n( 'Y-m-d', $date ) : '';
Run Code Online (Sandbox Code Playgroud)


How*_*wli 5

页面上的示例详细说明了如何完成此操作:
将以下内容添加到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 );
    }
}
Run Code Online (Sandbox Code Playgroud)

我在我的网站上试过它,它对我有用.