亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

基于運輸方式的動態信息顯示兩次

基于運輸方式的動態信息顯示兩次

PHP
大話西游666 2023-04-02 10:16:25
我已經嘗試從這個例子開始工作(動態信息基于運輸方式和購物車總計在 Woocommerce 中),但是我的動態消息顯示了兩次。任何幫助是極大的贊賞。本質上,我想做的是,如果用戶的送貨不在送貨區域(使用 WooCommerce 的“您的其他區域未涵蓋的位置”送貨區域),則顯示一條消息。只有當用戶不在定義的運輸區域時,該消息才會正確顯示 - 但它會加倍。一個似乎在 ajax 刷新之內,另一個似乎在它之外。不完全確定它是如何或為什么這樣做的。//add message to CHECKOUT if outside delivery areaadd_action( 'woocommerce_review_order_after_shipping', 'outside_delivery_checkout', 20);function outside_delivery_checkout() {    global $woocommerce;    if ( did_action( 'woocommerce_review_order_after_shipping' ) >= 2 ) {        return once;    }    $chosen_shipping_method_id = WC()->session->get( 'chosen_shipping_methods' )[0];    $chosen_shipping_method    = explode(':', $chosen_shipping_method_id)[0];    $cart_subtotal             = WC()->cart->subtotal;    if ($cart_subtotal && $chosen_shipping_method === 'free_shipping') {        echo '<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. <strong>Please refresh the page after updating your shipping settings.</strong></div>';    } elseif ($cart_subtotal && $chosen_shipping_method != 'free_shipping') {        // do nothing    }}這是問題的鏈接: https: //redstarrolloffqc.com/dumpster-sizes-rates/ - 添加產品并轉到結帳頁面。
查看完整描述

1 回答

?
千巷貓影

TA貢獻1829條經驗 獲得超7個贊

這里的主要問題是你試圖在結束 html 標簽之后的html 中<div>插入一個帶有一些內容的 html 標簽......<table></tr>


所以顯示的 Html 中斷,即使它看起來沒有。


相反,您應該使用以下 html 結構:


<tr><td colspan="2"><div>Your formatted text (message)</div></td></tr>

現在did_action()條件對您的代碼沒有影響,也不global $woocommerce是必需的(并且已經過時了一段時間)。


這樣您的內容將顯示在表格行中,因為它應該。


這將徹底解決您的問題……


所以你的代碼將是這樣的:


//add message to CHECKOUT if outside delivery area

add_action( 'woocommerce_review_order_after_shipping', 'outside_delivery_checkout', 20);

function outside_delivery_checkout() {

    $chosen_shipping_method_id = WC()->session->get( 'chosen_shipping_methods' )[0];

    $chosen_shipping_method    = explode(':', $chosen_shipping_method_id)[0];

    $cart_subtotal             = WC()->cart->subtotal;


    if ( $cart_subtotal && $chosen_shipping_method === 'free_shipping' ) {

        $html  = '<tr class="delivery-message"><td colspan="2"><div class="outside-delivery checkout">

            <strong>' . __("PLEASE NOTE:") . '</strong><br />';

        $html .= __("Your shipping destination is outside of our normal delivery area. Our team will call you to calculate an additional fuel surcharge.");

        $html .= ' <strong>' . __("Please refresh the page after updating your shipping settings.") . '</strong>';

        echo $html . '</div></td></tr>';

    }

}

代碼進入您的活動子主題(或活動主題)的 functions.php 文件。測試和工作。


查看完整回答
反對 回復 2023-04-02
  • 1 回答
  • 0 關注
  • 108 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號