只有當購物車中有缺貨物品(我們的產品可在缺貨時提供)時,我需要在我的結帳訂單審覈中顯示一節。這裏是顯示部分的代碼...檢查購物車中是否有缺貨物品 - WooCommerce
的functions.php:
function notes_in_cart() {
global $woocommerce;
if (! $_POST || (is_admin() && ! is_ajax())) {
return;
}
if (isset($_POST['post_data'])) {
parse_str($_POST['post_data'], $post_data);
} else {
$post_data = $_POST; // fallback for final checkout (non-ajax)
}
if (WC()->cart->needs_shipping()){
//if cart has items out of stock
//if (cart has out of stock product) {
?>
<tr class="ceckoutStockMeta">
<th>Item Shipments</th>
<td>
<p style="color: red;">*You have one or more items in your cart that are currently out of stock. Please select a custom shipping option for your order.</p><br>
<form>
<input type="radio" name="stockOp" id="stockOption1" value="ship" />
<label for="stockOption1">Ship what is available now</label><br>
<input type="radio" name="stockOp" id="stockOption2" value="hold" />
<label for="stockOption2">Wait and ship together</label>
</form>
</td>
</tr>
<?php
//}
}
}
add_action('woocommerce_cart_totals_after_order_total', 'notes_in_cart');
add_action('woocommerce_review_order_after_order_total', 'notes_in_cart');
眼下部分顯示了所有的時間。我知道我可能需要調用購物車項目並用foreach循環來確定是否缺貨,但不知道如何。
非常好,謝謝!爲我節省了幾個小時。 –
很高興我可以服務 –