通过发送方式在“谢谢”页面上添加自定义消息 [英] Adding custom message on Thank You page by shipping method

查看:60
本文介绍了通过发送方式在“谢谢”页面上添加自定义消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅在订单使用免费送货时,我才尝试在已收到订单(谢谢)页面上添加一条消息。该消息可以代替标准的谢谢...消息,也可以添加。

I'm trying to add a message to the order-received (Thank You) page, only if the order is using Free Shipping. The message can either replace the standard "Thank you..." message, or can be in addition to.

这是我正在使用的代码。它基于以下答案:定制订单已接收页面根据WooCommerce中的送货方式

Here is the code I'm working with. It's based off of the answer here: 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;
}

我无法使其正常工作,也不知道出了什么问题。

I can't get it to work correctly, and not sure what's wrong. Any help is greatly appreciated.

推荐答案

您只需要以下(其中免费送货是您的名字)免费送货方式)

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文件中(或活动主题)。经过测试和工作。

Similar: Code goes in function.php file of your active child theme (or active theme). Tested and works.

根据WooCommerce中的送货方式自定义收到的订单页面

这篇关于通过发送方式在“谢谢”页面上添加自定义消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆