僅當陣列中列出了 WP 產品 ID 時,我才需要回顯腳本。下面的代碼當然只適用于第一個產品 id (226),但我不確定如何更新這部分if(is_product() && get_the_id() == 226)以檢查所有陣列元素
$booking = array(
'226' => 349992,
'2456' => 349999,
'2498' => 350001,
'2500' => 350002,
'2502' => 350003,
'2504' => 350006,
'2665' => 350008
);
$item_number = $booking[$product->get_id()];
$fh_cal = '<script src="https://test.com/embeds/script/calendar-small/test/items/'.$item_number.'/?fallback=simple&full-items=no"></script>';
if(is_product() && get_the_id() == 226) {
echo $fh_cal;
} else {
include ABSPATH.'wp-content/themes/test/inc/form.php';
}
uj5u.com熱心網友回復:
如果您想知道該產品是否存在于該陣列中,我們可以簡單地isset()進行檢查:
改變
&& get_the_id() == 226
到
&& isset($booking[get_the_id()])
這將評估true好像有一個以該 ID 作為鍵的陣列元素
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/417675.html
標籤:
上一篇:使用PHP在CSV中添加新行
