php - 将动态值插入特定 WooCommerce 电子邮件模板的文本字符串中

我正在修改其中一个 WooCommerce 电子邮件模板并根据使用的付款方式添加文本:

if ( 'bacs' == $order->get_payment_method() ){
    echo "We are awaiting payment" ;
    echo $order->get_order_number();
}
elseif ( 'paypal' == $order->get_payment_method() )  {
    echo "Text2";
}
else {
    echo "Text3;
}

我需要将订单 ID 添加到第一个文本中(对于 BACS),以便显示:

我们正在等待付款。订单引用:1234(您的订单号)。

如何将订单号添加到我的纯文本中?

最佳答案

您可以使用 PHP printf()将变量值合并到显示的文本字符串中,如下所示:

if ( 'bacs' === $order->get_payment_method() ) {
    printf( __("We are awaiting payment. Order reference: %s (your order number).", "woocommerce"), $order->get_order_number() );
} elseif ( 'paypal' === $order->get_payment_method() ) {
    echo __("Text2", "woocommerce");
} else {
    echo __("Text3", "woocommerce");
}

https://stackoverflow.com/questions/65777738/

相关文章:

android - 如何在没有任何延迟的情况下在android中循环播放音频文件?

jestjs - 排毒配置 - 类型 'getEnv' 上不存在属性 'typeof jasmine

c - GDB monitor inside TMUX乱码

xamarin - 如何在 iOS 中的 Xamarin 按钮上将图像左对齐并将文本对齐到中心?

javascript - 当窗口变量在 react 中发生变化时如何更新状态

python - python 中的 turtle 迷宫。我不知道如何避免 turtle 穿墙和作弊

css - 如何将我的 mat-table CSS 列宽设置为只占用与数据一样多的空间?

powershell - 如何使用 powershell 启动 teams.exe

javascript - react : onChange callback not firing

unity3d - unity : Application keeps running in bac