SOLVED: Woo Composite product cannot be added to cart

Browser: Chrome 110
OS: Windows
URL: Link
Video: Jam

When I try to add a Woo Composite Product to the cart, the addition fails. It says in the notice that I haven’t chosen my variables for my variable product component. The issue is not present in a standard WordPress theme (TwentyTwentyFour).

Adding a regular Simple Product / Variable Product works fine.

Answer from Woo Supprot:

"I investigated on my end and I see that the Bricks theme is doing an AJAX call to add the product to the cart and it’s not passing what Composite Products needs to add the product to the cart. Here’s the call that Bricks is doing.

?wc-ajax=bricks_add_to_cart"

The SOLUTION was to disable Ajax add to cart.

1 Like

Is it possible to disable Ajax only on this type of product?

Hey. You probably figured this out, but it’s not possible to disable AJAX calls for just one product type.

Best regards,
Matej

@Matej Somehow I solved this with this custom function:

/**
 * Disable Bricks AJAX add to cart for booking products
 */
add_action('wp_enqueue_scripts', 'disable_bricks_ajax_for_booking', 999);

function disable_bricks_ajax_for_booking()
{
	if (!is_product()) {
		return;
	}

	global $post;
	$product = wc_get_product($post->ID);

	if (!$product || !$product->is_type('booking')) {
		return;
	}

	$inline_script = "
		if (typeof bricksWooCommerce !== 'undefined') {
			bricksWooCommerce.ajaxAddToCartEnabled = false;
		}
	";

	wp_add_inline_script('bricks-scripts', $inline_script, 'after');
}

Ah, nice, this is one “hacky” way to solve it. :flexed_biceps: Thanks for sharing :victory_hand:

Matej