Skip to content

Commit 68cb45d

Browse files
fix null cart call in cart_contains_only_donations
1 parent a45766d commit 68cb45d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

includes/class-wcdp-form.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,18 @@ static function render_donation_form(array $value, $context = 'shortcode'): stri
163163
</p>';
164164
}
165165

166+
/**
167+
* Checks if a grouped product has at least one purchasable donation child product
168+
*
169+
* @param mixed $product
170+
* @return bool
171+
*/
166172
private static function check_grouped_product($product)
167173
{
168174
if (!is_a($product, 'WC_Product_Grouped')) {
169175
return true;
170176
}
171-
$ids = $product->get_children('vier');
177+
$ids = $product->get_children('view');
172178
foreach ($ids as $id) {
173179
$productChild = wc_get_product($id);
174180
if ($productChild && $productChild->is_purchasable() && WCDP_Form::is_donable($id) && (is_a($productChild, 'WC_Product_Simple') || is_a($productChild, 'WC_Product_Subscription'))) {
@@ -189,6 +195,10 @@ public static function is_donable($id)
189195
return apply_filters('wcdp_is_donable', get_post_meta($id, '_donable', true) == 'yes');
190196
}
191197

198+
/**
199+
* Output a styled error message HTML
200+
* @param string $message
201+
*/
192202
public static function form_error_message($message)
193203
{
194204
echo '<ul class="woocommerce-error wcdp-error-message" id="wcdp-ajax-error" role="alert"><li>';
@@ -256,7 +266,7 @@ public static function cart_contains_donation(): bool
256266
*/
257267
public static function cart_contains_only_donations(): bool
258268
{
259-
if (!empty(WC()->cart->get_cart_contents())) {
269+
if (WC()->cart && !empty(WC()->cart->get_cart_contents())) {
260270
foreach (WC()->cart->get_cart_contents() as $cart_item) {
261271
if (isset($cart_item['product_id']) && !WCDP_Form::is_donable($cart_item['product_id'])) {
262272
return false;

0 commit comments

Comments
 (0)