我有一家Woocommerce商店,我想给我的客户看一个估计的发货日期,在add to cart表单下面。逻辑是
我尝试了商人守则,但是我的逻辑有点复杂,所以我无法让它工作!
任何帮助都是非常感谢的!
发布于 2020-10-12 10:35:42
检查下面的代码(测试并运行良好)。如果您对不正确的时间有问题,请查看时区设置是否正确。根据您的查询,我假设时区应该是Kolkatta。
Goto仪表板->设置->通用->时区
function dispatch_message(){
$current_time = current_time('D | H');
$current_time = explode('|', $current_time );
$current_day = isset( $current_time[0] ) ? trim( $current_time[0] ) : false;
$current_hour = isset( $current_time[1] ) ? trim( $current_time[1] ) : false;
$message = '4-5 Working Days.';
if( in_array( $current_day, array( 'Fri', 'Sat', 'Sun' ) ) ){
//Weekend
$message = '3-5 Working Days from Monday.';
}else if( $current_hour <= "12"){
//Before 12pm IST
$message = '3-5 Working Days.';
}
?>
<div style="clear: both"></div>
<div style="margin-top: 10px;font-size: 17px;color: red;">
<b>Est Dispatch Date:</b> <?php echo $message; ?>
</div>
<br>
<?php
}
add_action( 'woocommerce_before_add_to_cart_button', 'dispatch_message' );
更新
您可以对上述代码进行更改,以隐藏某些类别的分派日期。添加if条件作为第一行代码,如下所示,然后返回,以跳过函数的其余部分。
function dispatch_message(){
if ( is_product() && has_term( array( 'dress', 'clothing' ), 'product_cat' ) ){
return;
}
$current_time = current_time('D | H');
$current_time = explode('|', $current_time );
$current_day = isset( $current_time[0] ) ? trim( $current_time[0] ) : false;
$current_hour = isset( $current_time[1] ) ? trim( $current_time[1] ) : false;
$message = '4-5 Working Days.';
if( in_array( $current_day, array( 'Fri', 'Sat', 'Sun' ) ) ){
//Weekend
$message = '3-5 Working Days from Monday.';
}else if( $current_hour <= "12"){
//Before 12pm IST
$message = '3-5 Working Days.';
}
?>
<div style="clear: both"></div>
<div style="margin-top: 10px;font-size: 17px;color: red;">
<b>Est Dispatch Date:</b> <?php echo $message; ?>
</div>
<br>
<?php
}
add_action( 'woocommerce_before_add_to_cart_button', 'dispatch_message' );
https://stackoverflow.com/questions/64311606
复制相似问题