显示 woocommerce 销售结束日期 [英] Display woocommerce sale end date
本文介绍了显示 woocommerce 销售结束日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 wordpress 中找到了这个帖子http://wordpress.org/support/topic/get-woocommerce-scheduled-sale-end-date?replys=15
I found this thread in wordpress http://wordpress.org/support/topic/get-woocommerce-scheduled-sale-end-date?replies=15
但是当我尝试它时,它不起作用.也许是因为答案太旧了.
but when I tried it, it did not work. Perhaps because the answer was too old.
有谁知道如何获得预定销售 woocommerce 产品的结束日期?
Anyone knows how to get end date of scheduled sale woocommerce product?
这是我目前所拥有的
$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) ""
谢谢
推荐答案
这个 页面,详细说明如何做到:
将以下内容添加到 functions.php
文件
An example on this page, details how it can be done:
Add the following to the functions.php
file
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 );
}
}
我已经在我的网站上试过了,它对我有用.
I have tried it on my website and it works for me.
这篇关于显示 woocommerce 销售结束日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文