Woocommerce Woo定制徽章/气泡条件
我根据发布的时间创建自定义徽章/气泡“New!”:Woocommerce Woo定制徽章/气泡条件,woocommerce,Woocommerce,我根据发布的时间创建自定义徽章/气泡“New!”: add_action( 'woocommerce_before_shop_loop_item', function() { #add_action( 'woocommerce_single_product_image_html', function() { $postdate = get_the_time( 'Y-m-d' ); // Post date $postdatestamp = strtot
add_action( 'woocommerce_before_shop_loop_item', function() {
#add_action( 'woocommerce_single_product_image_html', function() {
$postdate = get_the_time( 'Y-m-d' ); // Post date
$postdatestamp = strtotime( $postdate ); // Timestamped post date
$newness = 10; // Newness in days
if ( ( time() - ( 60 * 60 * 24 * $newness ) ) < $postdatestamp ) {
echo '<div class="woo-entry-new-badge"><div class="woo-cust-new-badge">' . esc_html__( 'New!', 'woocommerce' ) . '</div></div>';
}
}, 20 );
add_操作('woocommerce_-before_-shop_-loop_-item',函数(){
#添加操作('woocommerce\u single\u product\u image\u html',函数(){
$postdate=获取时间('Y-m-d');//发布日期
$postdatestamp=strottime($postdate);//贴有时间戳的发布日期
$newness=10;//以天为单位的newness
如果((时间()-(60*60*24*$newness))<$postdatestamp){
echo'.esc_html_uuu('New!','woocommerce')。';
}
}, 20 );
但我想添加条件以显示是否未设置“在售”。
你看起来怎么样
谢谢!–返回产品是否在销售中
function my\u callback\u function(){
全球$产品;
$postdate=get_日期('Y-m-d',$product->get_id());//发布日期
$postdatestamp=strottime($postdate);//贴有时间戳的发布日期
$newness=10;//以天为单位的newness
$onsale=$product->正在销售中();
if((time()-(60*60*24*$newness))<$postdatestamp&&!$onsale){
echo'.esc_html_uuu('New!','woocommerce')。';
}
}
添加\u操作('woocommerce\u-before\u-shop\u-loop\u-item','my\u-callback\u-function',10,0);
谢谢你的快速回答!工作起来很有魅力!