代码之家  ›  专栏  ›  技术社区  ›  Trisha

按送货方式在“谢谢”页上添加自定义邮件

  •  1
  • Trisha  · 技术社区  · 7 年前

    我试图添加一个消息到订单接收(谢谢)页面,只有在订单使用免费送货。该消息可以替换标准的“谢谢…”消息,也可以是附加消息。

    这是我正在处理的代码。这是基于这里的答案: 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;
    }
    

    我不能让它正常工作,也不知道怎么了。任何帮助都非常感谢。

    1 回复  |  直到 7 年前
        1
  •  1
  •   LoicTheAztec    7 年前

    你只需要 (其中“免费送货”是您的免费送货方式的名称) :

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


    Customize Order received page based on shipping method in WooCommerce

    推荐文章