Add to cart ajax not working if user is logged in.
-
When you add the products to the cart when a user is logged in nothing happens but when you are not logged in it works.
I have deactivated all plugins and it still doesn’t work.
I cannot deactivate the theme as the functionality needed is within the theme’s code.
<?php /** * Adds all selected and checked product items to the basket. */ function add_cb_to_cart() { global $woocommerce; $selectedProductArray = $_POST['selected_product_array']; $checkedProductArray = $_POST['checked_product_array']; // Merge all products. $productArray = array_merge( (array) $selectedProductArray, (array) $checkedProductArray ); // Loops over each product and add it to basket. foreach ( $productArray as $row ) { $row = str_replace( '\"', '', $row ); $productCartId = $woocommerce->cart->generate_cart_id( $row ); $product = get_product( $row ); if ( ! $woocommerce->cart->find_product_in_cart( $productCartId ) ) { // If the product is not in the cart then add it. if ($product->is_type( 'grouped' )) { $grouped_products = []; foreach( $product->get_children() as $children_id ){ $grouped_products[] = $children_id; } foreach ($grouped_products as $groupedRow) { $woocommerce->cart->add_to_cart( $groupedRow ); } } else { $woocommerce->cart->add_to_cart( $row ); } } } die(); } add_action( 'wp_ajax_add_cb_to_cart', 'add_cb_to_cart' ); add_action( 'wp_ajax_nopriv_add_cb_to_cart', 'add_cb_to_cart' ); add_action('woocommerce_before_cart','QuadLayers_apply_coupon_cart_values');
The page I need help with: [log in to see the link]
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Add to cart ajax not working if user is logged in.’ is closed to new replies.