You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What are you trying to do?
I have a scenario where there could be just gift vouchers in a cart. At present the user still has to enter a shipping address, which is not needed as the gift voucher is a download. I want to be able to bypass the user entering a shipping address so I need a way to check if the cart has ONLY gift vouchers.
What's your proposed solution?
As per your suggestion on Discord:
public function hasGiftVouchers($hasOnly = false, $cart = null)
{
$giftVouchers = [];
if (!$cart) {
$cart = Commerce::getInstance()->getCarts()->getCart();
}
if (!$cart->lineItems) {
return false;
}
foreach ($cart->lineItems as $lineItem) {
$isGiftVoucher = (bool)(get_class($lineItem->purchasable) === Voucher::class);
if ($isGiftVoucher) {
$giftVouchers[] = $lineItem;
}
}
if ($hasOnly) {
return (count($cart->lineItems) === count($giftVouchers)) ? true : false;
} else {
return count($giftVouchers) ? true : false;
}
}
The text was updated successfully, but these errors were encountered:
What are you trying to do?
I have a scenario where there could be just gift vouchers in a cart. At present the user still has to enter a shipping address, which is not needed as the gift voucher is a download. I want to be able to bypass the user entering a shipping address so I need a way to check if the cart has ONLY gift vouchers.
What's your proposed solution?
As per your suggestion on Discord:
The text was updated successfully, but these errors were encountered: