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 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)