我从这里得到了这个代码( Display woocommerce sale end date )
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 );
}
}这只会显示销售日期。我如何使它显示销售日期从销售日期到?
我试着编辑这一行:
return str_replace( '</ins>', ' </ins> <b>(Offer till '.$sales_price_date_to.')</b>', $price );至
return str_replace( '</ins>', ' </ins> <b>(Offer from '.$sales_price_date_from.' till '.$sales_price_date_to.')</b>', $price );但它没有显示销售日期。
那么,谁能告诉我,我如何显示销售日期和销售日期?
发布于 2016-11-21 03:12:35
我已经在我的网站上试过了,它对我很有用。
add_filter( 'woocommerce_get_price_html', 'custom_price_html', 100, 2 );
function custom_price_html( $price, $product ) {
$sales_price_from = get_post_meta( $product->id, '_sale_price_dates_from', true );
$sales_price_to = get_post_meta( $product->id, '_sale_price_dates_to', true );
if ( is_single() && $product->is_on_sale() && $sales_price_to != "" ) {
$sales_price_date_from = date( "j M y", $sales_price_from );
$sales_price_date_to = date( "j M y", $sales_price_to );
$price = str_replace( '</ins>', ' </ins> <b>(Offer from ' . $sales_price_date_from . ' till ' . $sales_price_date_to . ')</b>', $price );
}
return apply_filters( 'woocommerce_get_price', $price );
}发布于 2018-11-04 11:11:48
我已经为这个做了一个插件(100%免费,没有广告,也没有隐藏功能)。
商店与其他商店的主要区别在于,它也适用于Variations (即使每个变体都有不同的日期)。
https://wordpress.org/plugins/woo-on-sale-information/
此外,开发时考虑到了简单性,并为开发人员提供了过滤器,使其能够在没有问题的情况下对其进行调整(代码也有很好的文档记录)。
看一看;)
https://stackoverflow.com/questions/40711914
复制相似问题