php - 带有条件的订单明细表下的文本
问题描述
我想在我的帐户页面的订单详细信息表下添加一个文本,如下面的屏幕截图所示,但如果订单状态更改为完成,我希望将此文本更改为另一个文本。
这是我用来显示文本的内容,但如果状态从任何状态更改为完成,我不能有条件地将文本更改为另一个文本。
add_action('woocommerce_order_details_after_order_table', 'action_order_details_after_order_table', 10, 4 );
function action_order_details_after_order_table( $order, $sent_to_admin = '', $plain_text = '', $email = '' ) {
// Only on "My Account" > "Order View"
if ( is_wc_endpoint_url( 'view-order' ) ) {
printf( '<p class="custom-text">' .
__("To cancel your license within the 30 day trial period click on %s" ,"woocommerce"),
'<strong>"' .__("Refund my entire order", "woocommerce") . '"</strong>.</p>' );
}
}
我只需要在订单状态完成后将此消息更改为另一条消息。
解决方案
Change your above codes with follows -
add_action('woocommerce_order_details_after_order_table', 'action_order_details_after_order_table', 10, 4 );
function action_order_details_after_order_table( $order, $sent_to_admin = '', $plain_text = '', $email = '' ) {
// Only on "My Account" > "Order View"
if ( is_wc_endpoint_url( 'view-order' ) ) {
if( $order->get_status() == 'completed' ){ // for completed status
printf( '<p class="custom-text">' .
__("Your order completed message goes here %s" ,"woocommerce"),
'<strong>"' .__("Refund my entire order", "woocommerce") . '"</strong>.</p>' );
}elseif($order->get_status() == 'cancelled'){ // for cancelled status
printf( '<p class="custom-text">' .
__("Your order cancelled message goes here %s" ,"woocommerce"),
'<strong>"' .__("Refund my entire order", "woocommerce") . '"</strong>.</p>' );
}else{ // for rest statuses
printf( '<p class="custom-text">' .
__("To cancel your license within the 30 day trial period click on %s" ,"woocommerce"),
'<strong>"' .__("Refund my entire order", "woocommerce") . '"</strong>.</p>' );
}
}
}
推荐阅读
- vue.js - 如何添加以下样式作为此 Vue 组件的道具
- shell - 如何在 Debian 10 上运行的 bash shell 脚本中使用 sed 或其他 bash 命令从“go version”命令中仅提取版本
- c++ - C++:迭代器的复制构造函数
- selenium - 如何在詹金斯中只运行冒烟测试用例套件?
- python-3.x - 发布嵌套模型 SQLAlchemy-Marshmallow
- laravel - Laravel 验证唯一值
- iis-express - What does Visual Studio for Mac use to host applications?
- ruby - 使用 RSpec 和 PDK 测试内部类是否存在
- python - 在 Python 中验证文件名的格式
- java - 返回空值的递归方法