设置
我决定自己尝试一点PHP,我是一个完全的初学者。
我运行一个WooCommerce商店,并希望在每个产品页面上动态显示预期的交付日期范围。
交货日期是今天的日期加上3天和4天,例如今天是10月10日,所以交货日期是10月13日和14日。因此,在每一个产品页面上都应该提到,
Delivery between Oct 13 and Oct 14
我知道在哪里编写代码,这样它就会显示出我希望它出现在产品页面上的位置。
我还知道如何动态更新交付日期。
问题
回波混合变量,而不是,
Delivery between Oct 13 and Oct 14
它说,
Delivery between and Oct 13Oct 14
我的代码
function my_custom_action() {
$plus3 = strtotime("+3 day");
$plus4 = strtotime("+4 day");
$date_low = date('M d', $plus3);
$date_high = date('M d', $plus4);
$start_text = _e('Delivery between ','woodmart');
$end_text = _e(' and ','woodmart');
echo $start_text, $date_low, $end_text, $date_high ;
};
add_action( 'woocommerce_single_product_summary', 'my_custom_action', 15 ); 函数中需要$start_text和$end_text,所以字符串是可转换的。
最好我也有几个月(例如Oct)是可翻译的,但是现在我已经很高兴知道如何按照期望的顺序得到所有的变量。
发布于 2018-10-10 10:45:27
这可以通过字符串内插来解决。
就像。
$name = "PHP"; echo "I am reading {$name}POT"; // output: I am reading PHPPOT
下面链接到一个更详细的参考资料:可变内插
https://stackoverflow.com/questions/52738282
复制相似问题