php - 通过送货方式在感谢页面上添加自定义消息
问题描述
我正在尝试向已收到订单(谢谢)页面添加一条消息,前提是订单使用免费送货。该消息可以替换标准的“谢谢...”消息,也可以是附加消息。
这是我正在使用的代码。它基于此处的答案:根据 WooCommerce 中的运输方式自定义收到的订单页面
//add message to order received if outside delivery area
add_filter( 'woocommerce_thankyou_order_received_text', 'woo_change_order_received_text', 20, 2 );
function woo_change_order_received_text( $thankyou_text, $order ) {
if ( is_wc_endpoint_url( 'order-received' ) ) {
global $wp;
$order_id = absint( $wp->query_vars['order-received'] );
$order_key = isset( $_GET['key'] ) ? wc_clean( $_GET['key'] ) : '';
$method_title_names = array();
if( in_array( 'Free shipping', $method_title_names ) ) {
return sprintf( __("%s <div class=\"outside-delivery-checkout\"><b>PLEASE NOTE:</b><br />Your shipping destination is outside of our normal delivery area. Our team will call you to calculate an additional fuel surcharge.</div>", "woocommerce"),
$thankyou_text
);
}
}
return $thankyou_text;
}
我无法让它正常工作,也不知道出了什么问题。任何帮助是极大的赞赏。
解决方案
您只需要以下内容(其中“免费送货”是您的免费送货方式的名称):
add_filter( 'woocommerce_thankyou_order_received_text', 'woo_change_order_received_text', 20, 2 );
function woo_change_order_received_text( $text, $order ) {
if( $order->get_shipping_method() == 'Free shipping' ) {
$text .= ' <div class=\"outside-delivery-checkout\"><strong>'. __("PLEASE NOTE", "woocommerce") . ':</strong><br />'.__("Your shipping destination is outside of our normal delivery area. Our team will call you to calculate an additional fuel surcharge.", "woocommerce") . '</div>';
}
return $text;
}
类似:代码在您的活动子主题(或活动主题)的 function.php 文件中。测试和工作。
推荐阅读
- php - 如何使用 PHP 自动更新自定义帖子的特色图片?
- twincat - 事件记录器事件未显示在事件网格控件中
- javascript - Javascript 比较函数在 Firefox 和 Chrome 之间的行为不同
- elasticsearch - 我已经设置了启用 Xpack 安全性的 EFK 堆栈,它运行良好,直到其中一个 Elasticsearch pod 重新启动
- java - Android 中类似 facebook 的反应按钮
- kubernetes - 无法将 Pod 间关联性应用于 Airflow 调度程序
- django-rest-framework - 图像没有显示在 index.html 上,我正在 Django 中编辑酒店模板,只是基础知识
- c# - 使用 MediatR 控制器删除多个 ID
- python - 仅在完成写入后使用 .hdf5 文件
- r - make-distribution.sh 在 Make R 包步骤失败时失败。没有提供参数