doukeyong3746487 2018-08-13 19:50
浏览 53
已采纳

通过送货方式在Thank You页面上添加自定义消息

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.

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.

  • 写回答

1条回答 默认 最新

  • dtkf64283 2018-08-13 20:34
    关注

    You need simply the following (where "Free shipping" is the name of your free shipping method):

    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;
    }
    

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


    Customize Order received page based on shipping method in WooCommerce

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100