I have the follow code to add multiple item to cart using Woocommerce plugin and it give me Fatal error:
Fatal error: Maximum function nesting level of ‘100’ reached, aborting! in …wp-contentpluginswoocommercewoocommerce.php on line 94
I also try to increase the nesting level but it no help.
Here is the code:
add_action( 'init', 'multi_add_to_cart' );
function multi_add_to_cart() {
if( !isset( $_POST['multi_add_to_cart_nonce'] ) ) return false;
if ( !wp_verify_nonce( $_POST['multi_add_to_cart_nonce'], 'multi_add_to_cart_nonce') ) return false;
global $woocommerce;
$added_products = 0;
foreach( $_POST['multi_add_to_cart'] as $variation_id => $variation ) {
if( (int) $variation['quantity'] > 0 ) {
$woocommerce->cart->add_to_cart(
$variation['product_id'], // string $product_id
$variation['quantity'], // string $quantity = 1
(int) $variation_id, // integer $variation_id = ''
( isset($variation['attributes']) && !empty($variation['attributes']) ) ? $variation['attributes'] : false // Attributes!
);
$added_products++;
}
}
if( $added_products > 0 ) woocommerce_add_to_cart_message($variation['product_id'] );
}
there might be a lot of functions hooked to
init
. try changinginit
totemplate_redirect
.