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 文件。測試和工作。
- 1 回答
- 0 關注
- 108 瀏覽
添加回答
舉報