我的 woocommerce 商店的“我的帳戶”頁面出現問題。事實上,當我使用從未下過訂單的新客戶帳戶登錄時,我的儀表板顯示錯誤,容器消失。
經過測驗,只有當我使用相關帳戶下訂單時,該錯誤才會消失。
執行一系列測驗后,產生該錯誤的代碼如下(顯示連接用戶的最后一條命令):
<?php foreach ($last_order->get_items() as $item) :
$product = $item->get_product();
$thumbnail = $product->get_image(array(50, 50));
if ($product->get_image_id() > 0) {
$item_name = '<div >' . $thumbnail . '</div>'; // You had an extra variable here
}
echo $item_name . $item->get_name();
endforeach;
?>
你知道這可能來自哪里嗎?
提前,非常感謝您的幫助。
uj5u.com熱心網友回復:
不確定這是從哪里來的,但它正在嘗試遍歷$last_order變數。
因此,為了防止回圈為從未下過訂單的用戶運行(這意味著$last_order為假),您可以將其包裝在一個if陳述句中并檢查是否$last_order為假,如下所示:
if($last_order){
foreach ($last_order->get_items() as $item) :
$product = $item->get_product();
$thumbnail = $product->get_image(array(50, 50));
if ($product->get_image_id() > 0) {
$item_name = '<div >' . $thumbnail . '</div>'; // You had an extra variable here
}
echo $item_name . $item->get_name();
endforeach;
}
請讓我知道這對你有沒有用!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/345939.html
