php - 通过送货方式在感谢页面上添加自定义消息

标签 php wordpress woocommerce checkout shipping-method

我正在尝试向已收到订单(谢谢)页面添加一条消息,前提是该订单使用免费送货。该消息可以替代标准的“​​谢谢...”消息,也可以作为补充。

这是我正在使用的代码。它基于此处的答案:Customize Order received page based on shipping method in 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 文件。测试和工作。


Customize Order received page based on shipping method in WooCommerce

关于php - 通过送货方式在感谢页面上添加自定义消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51829609/

相关文章:

php - 在 Linux 上使用带有 SMTP 服务器的默认 PHP 邮件功能

Wordpress自定义文件上传页面

html - CSS - 在 iPhone 和 Safari 上隐藏选择菜单中的选项

php - 将 “checkbox” 添加到策略行。 Woocommerce、Botiga 主题模板

wordpress - Woocommerce Admin 按库存/缺货过滤

php - Printer_open() 打印 html 输出

php - MYSQL PHP获取单个字段的平均值

php - ICS 文件格式是否允许更新和删除事件?

php - 覆盖 Buddypress 函数以更改 SQL 条件

woocommerce - 更改 Woocommerce 有货/缺货文本