AJAX Event Handler
Author: WooThemes
function ts_remove_cart_item()
{
    $cart_item_key = sanitize_text_field($_POST['cart_item_key']);
    if ($cart_item = WC()->cart->get_cart_item($cart_item_key)) {
        WC()->cart->remove_cart_item($cart_item_key);
    }
    WC_AJAX::get_refreshed_fragments();
}
Exemple #2
1
 function evotx_woocommerce_ajax_add_to_cart()
 {
     global $woocommerce;
     // Initial values
     $product_id = apply_filters('woocommerce_add_to_cart_product_id', absint($_POST['product_id']));
     $variation_id = apply_filters('woocommerce_add_to_cart_variation_id', absint($_POST['variation_id']));
     $quantity = empty($_POST['quantity']) ? 1 : apply_filters('woocommerce_stock_amount', $_POST['quantity']);
     $passed_validation = apply_filters('woocommerce_add_to_cart_validation', true, $product_id, $quantity);
     // if variations are sent
     if (isset($_POST['variations'])) {
         $att = array();
         foreach ($_POST['variations'] as $varF => $varV) {
             $att[$varF] = $varV;
         }
     }
     if ($passed_validation && !empty($variation_id)) {
         $cart_item_key = WC()->cart->add_to_cart($product_id, $quantity, $variation_id, $att);
         do_action('woocommerce_ajax_added_to_cart', $product_id);
         $frags = new WC_AJAX();
         $frags->get_refreshed_fragments();
     }
     /*
     				// if variation ID is given
     				if(!empty($variation_id) && $variation_id > 0){
     					
     					$cart_item_key = $woocommerce->cart->add_to_cart( $product_id, $quantity, $variation_id ,$att);
     					 
     					do_action( 'woocommerce_ajax_added_to_cart', $product_id ,$quantity, $variation_id ,$variation);
     
     					// Return fragments
     					//$frags = new WC_AJAX( );
     		        	//$frags->get_refreshed_fragments( );
     
     
     					// if WC settings set to redirect after adding to cart
     					if ( get_option( 'woocommerce_cart_redirect_after_add' ) == 'yes' ) {
     						// show cart notification
     					 	wc_add_to_cart_message( $product_id );
     					 	$woocommerce->set_messages();
     					}
     				}else{
     				 
     					if ( $passed_validation && $woocommerce->cart->add_to_cart( $product_id, $quantity) ) {
     						do_action( 'woocommerce_ajax_added_to_cart', $product_id );
     						 
     						if ( get_option( 'woocommerce_cart_redirect_after_add' ) == 'yes' ) {
     						 	woocommerce_add_to_cart_message( $product_id );
     						 	$woocommerce->set_messages();
     						}
     						 
     						// Return fragments
     						// $frags = new WC_AJAX( );
     		        		// $frags->get_refreshed_fragments( );
     					 
     					} else {
     					 
     						header( 'Content-Type: application/json; charset=utf-8' );
     						 
     						// If there was an error adding to the cart, redirect to the product page to show any errors
     						$data = array(
     						 	'error' => true,
     						 	'product_url' => apply_filters( 'woocommerce_cart_redirect_after_error', get_permalink( $product_id ), $product_id )
     						);
     						 
     						$woocommerce->set_messages();
     						 
     						echo json_encode( $data );
     					 
     					}
     					die();
     				} // endif
     */
     $output = array('key' => $cart_item_key, 'variation' => WC()->cart->cart_contents_total);
     echo json_encode($output);
 }
 /**
  * Install WC
  */
 public static function install()
 {
     global $wpdb;
     if (!defined('WC_INSTALLING')) {
         define('WC_INSTALLING', true);
     }
     // Ensure needed classes are loaded
     include_once 'admin/class-wc-admin-notices.php';
     self::create_options();
     self::create_tables();
     self::create_roles();
     // Register post types
     WC_Post_types::register_post_types();
     WC_Post_types::register_taxonomies();
     // Also register endpoints - this needs to be done prior to rewrite rule flush
     WC()->query->init_query_vars();
     WC()->query->add_endpoints();
     WC_API::add_endpoint();
     WC_Auth::add_endpoint();
     WC_AJAX::add_endpoint();
     self::create_terms();
     self::create_cron_jobs();
     self::create_files();
     // Queue upgrades/setup wizard
     $current_wc_version = get_option('woocommerce_version', null);
     $current_db_version = get_option('woocommerce_db_version', null);
     $major_wc_version = substr(WC()->version, 0, strrpos(WC()->version, '.'));
     WC_Admin_Notices::remove_all_notices();
     // No versions? This is a new install :)
     if (is_null($current_wc_version) && is_null($current_db_version) && apply_filters('woocommerce_enable_setup_wizard', true)) {
         WC_Admin_Notices::add_notice('install');
         set_transient('_wc_activation_redirect', 1, 30);
         // No page? Let user run wizard again..
     } elseif (!get_option('woocommerce_cart_page_id')) {
         WC_Admin_Notices::add_notice('install');
         // Show welcome screen for major updates only
     } elseif (version_compare($current_wc_version, $major_wc_version, '<')) {
         set_transient('_wc_activation_redirect', 1, 30);
     }
     if (!is_null($current_db_version) && version_compare($current_db_version, max(array_keys(self::$db_updates)), '<')) {
         WC_Admin_Notices::add_notice('update');
     } else {
         self::update_db_version();
     }
     self::update_wc_version();
     // Flush rules after install
     flush_rewrite_rules();
     delete_transient('wc_attribute_taxonomies');
     /*
      * Deletes all expired transients. The multi-table delete syntax is used
      * to delete the transient record from table a, and the corresponding
      * transient_timeout record from table b.
      *
      * Based on code inside core's upgrade_network() function.
      */
     $sql = "DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b\n\t\t\tWHERE a.option_name LIKE %s\n\t\t\tAND a.option_name NOT LIKE %s\n\t\t\tAND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) )\n\t\t\tAND b.option_value < %d";
     $wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('_transient_') . '%', $wpdb->esc_like('_transient_timeout_') . '%', time()));
     // Trigger action
     do_action('woocommerce_installed');
 }
 /**
  * Front end styles and scripts.
  *
  * @return void
  */
 public static function frontend_scripts()
 {
     wp_register_style('wcsatt-css', WCS_ATT()->plugin_url() . '/assets/css/wcsatt-frontend.css', false, WCS_ATT::VERSION, 'all');
     wp_enqueue_style('wcsatt-css');
     if (is_cart()) {
         wp_register_script('wcsatt-cart', WCS_ATT()->plugin_url() . '/assets/js/wcsatt-cart.js', array('jquery', 'wc-country-select', 'wc-address-i18n'), WCS_ATT::VERSION, true);
     }
     wp_enqueue_script('wcsatt-cart');
     $params = array('update_cart_option_nonce' => wp_create_nonce('wcsatt_update_cart_option'), 'wc_ajax_url' => WCS_ATT_Core_Compatibility::is_wc_version_gte_2_4() ? WC_AJAX::get_endpoint("%%endpoint%%") : WC()->ajax_url());
     wp_localize_script('wcsatt-cart', 'wcsatt_cart_params', $params);
 }
 function woocommerce_add_to_cart_simple_rc_callback()
 {
     ob_start();
     $product_id = apply_filters('woocommerce_add_to_cart_product_id', absint($_POST['product_id']));
     $quantity = empty($_POST['quantity']) ? 1 : apply_filters('woocommerce_stock_amount', $_POST['quantity']);
     $passed_validation = apply_filters('woocommerce_add_to_cart_validation', true, $product_id, $quantity);
     if ($passed_validation && WC()->cart->add_to_cart($product_id, $quantity)) {
         do_action('woocommerce_ajax_added_to_cart', $product_id);
         if (get_option('woocommerce_cart_redirect_after_add') == 'yes') {
             wc_add_to_cart_message($product_id);
         }
         // Return fragments
         WC_AJAX::get_refreshed_fragments();
     } else {
         $this->json_headers();
         // If there was an error adding to the cart, redirect to the product page to show any errors
         $data = array('error' => true, 'product_url' => apply_filters('woocommerce_cart_redirect_after_error', get_permalink($product_id), $product_id));
         echo json_encode($data);
     }
     die;
 }
 function woocommerce_add_to_cart_variable_rc_callback()
 {
     ob_start();
     $product_id = apply_filters('woocommerce_add_to_cart_product_id', absint($_POST['product_id']));
     $quantity = empty($_POST['quantity']) ? 1 : apply_filters('woocommerce_stock_amount', $_POST['quantity']);
     $variation_id = $_POST['variation_id'];
     $variation = $_POST['variation'];
     $passed_validation = apply_filters('woocommerce_add_to_cart_validation', true, $product_id, $quantity);
     if ($passed_validation && WC()->cart->add_to_cart($product_id, $quantity, $variation_id, $variation)) {
         do_action('woocommerce_ajax_added_to_cart', $product_id);
         if (get_option('woocommerce_cart_redirect_after_add') == 'yes') {
             wc_add_to_cart_message($product_id);
         }
         // Return fragments
         WC_AJAX::get_refreshed_fragments();
     } else {
         // If there was an error adding to the cart, redirect to the product page to show any errors
         $notice = end(wc_get_notices('error'));
         $data = array('error' => true, 'product_url' => apply_filters('woocommerce_cart_redirect_after_error', get_permalink($product_id), $product_id), 'notice' => $notice);
         wp_send_json($data);
     }
     die;
 }
     * Bulk edit variations via AJAX
     */
    public static function bulk_edit_variations()
    {
        ob_start();
        check_ajax_referer('bulk-edit-variations', 'security');
        // Check permissions again and make sure we have what we need
        if (!current_user_can('edit_products') || empty($_POST['product_id']) || empty($_POST['bulk_action'])) {
            die(-1);
        }
        $product_id = absint($_POST['product_id']);
        $bulk_action = wc_clean($_POST['bulk_action']);
        $data = !empty($_POST['data']) ? array_map('wc_clean', $_POST['data']) : array();
        $variations = array();
        if (apply_filters('woocommerce_bulk_edit_variations_need_children', true)) {
            $variations = get_posts(array('post_parent' => $product_id, 'posts_per_page' => -1, 'post_type' => 'product_variation', 'fields' => 'ids', 'post_status' => array('publish', 'private')));
        }
        if (method_exists(__CLASS__, "variation_bulk_action_{$bulk_action}")) {
            call_user_func(array(__CLASS__, "variation_bulk_action_{$bulk_action}"), $variations, $data);
        } else {
            do_action('woocommerce_bulk_edit_variations_default', $bulk_action, $data, $product_id, $variations);
        }
        do_action('woocommerce_bulk_edit_variations', $bulk_action, $data, $product_id, $variations);
        // Sync and update transients
        WC_Product_Variable::sync($product_id);
        wc_delete_product_transients($product_id);
        die;
    }
}
WC_AJAX::init();
 /**
  * Return data for script handles.
  * @access private
  * @param  string $handle
  * @return array|bool
  */
 private static function get_script_data($handle)
 {
     global $wp;
     switch ($handle) {
         case 'woocommerce':
             return array('ajax_url' => WC()->ajax_url(), 'wc_ajax_url' => WC_AJAX::get_endpoint("%%endpoint%%"));
             break;
         case 'wc-geolocation':
             return array('wc_ajax_url' => WC_AJAX::get_endpoint("%%endpoint%%"), 'home_url' => home_url(), 'is_cart' => is_cart() ? '1' : '0', 'is_account_page' => is_account_page() ? '1' : '0', 'is_checkout' => is_checkout() ? '1' : '0', 'hash' => isset($_GET['v']) ? wc_clean($_GET['v']) : '');
             break;
         case 'wc-single-product':
             return array('i18n_required_rating_text' => esc_attr__('Please select a rating', 'woocommerce'), 'review_rating_required' => get_option('woocommerce_review_rating_required'));
             break;
         case 'wc-checkout':
             return array('ajax_url' => WC()->ajax_url(), 'wc_ajax_url' => WC_AJAX::get_endpoint("%%endpoint%%"), 'update_order_review_nonce' => wp_create_nonce('update-order-review'), 'apply_coupon_nonce' => wp_create_nonce('apply-coupon'), 'remove_coupon_nonce' => wp_create_nonce('remove-coupon'), 'option_guest_checkout' => get_option('woocommerce_enable_guest_checkout'), 'checkout_url' => WC_AJAX::get_endpoint("checkout"), 'is_checkout' => is_page(wc_get_page_id('checkout')) && empty($wp->query_vars['order-pay']) && !isset($wp->query_vars['order-received']) ? 1 : 0, 'debug_mode' => defined('WP_DEBUG') && WP_DEBUG, 'i18n_checkout_error' => esc_attr__('Error processing checkout. Please try again.', 'woocommerce'));
             break;
         case 'wc-address-i18n':
             return array('locale' => json_encode(WC()->countries->get_country_locale()), 'locale_fields' => json_encode(WC()->countries->get_country_locale_field_selectors()), 'i18n_required_text' => esc_attr__('required', 'woocommerce'));
             break;
         case 'wc-cart':
             return array('ajax_url' => WC()->ajax_url(), 'wc_ajax_url' => WC_AJAX::get_endpoint("%%endpoint%%"), 'update_shipping_method_nonce' => wp_create_nonce("update-shipping-method"));
             break;
         case 'wc-cart-fragments':
             return array('ajax_url' => WC()->ajax_url(), 'wc_ajax_url' => WC_AJAX::get_endpoint("%%endpoint%%"), 'fragment_name' => apply_filters('woocommerce_cart_fragment_name', 'wc_fragments'));
             break;
         case 'wc-add-to-cart':
             return array('ajax_url' => WC()->ajax_url(), 'wc_ajax_url' => WC_AJAX::get_endpoint("%%endpoint%%"), 'i18n_view_cart' => esc_attr__('View Cart', 'woocommerce'), 'cart_url' => apply_filters('woocommerce_add_to_cart_redirect', WC()->cart->get_cart_url()), 'is_cart' => is_cart(), 'cart_redirect_after_add' => get_option('woocommerce_cart_redirect_after_add'));
             break;
         case 'wc-add-to-cart-variation':
             return array('i18n_no_matching_variations_text' => esc_attr__('Sorry, no products matched your selection. Please choose a different combination.', 'woocommerce'), 'i18n_unavailable_text' => esc_attr__('Sorry, this product is unavailable. Please choose a different combination.', 'woocommerce'));
             break;
         case 'wc-country-select':
             return array('countries' => json_encode(array_merge(WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states())), 'i18n_select_state_text' => esc_attr__('Select an option&hellip;', 'woocommerce'), 'i18n_matches_1' => _x('One result is available, press enter to select it.', 'enhanced select', 'woocommerce'), 'i18n_matches_n' => _x('%qty% results are available, use up and down arrow keys to navigate.', 'enhanced select', 'woocommerce'), 'i18n_no_matches' => _x('No matches found', 'enhanced select', 'woocommerce'), 'i18n_ajax_error' => _x('Loading failed', 'enhanced select', 'woocommerce'), 'i18n_input_too_short_1' => _x('Please enter 1 or more characters', 'enhanced select', 'woocommerce'), 'i18n_input_too_short_n' => _x('Please enter %qty% or more characters', 'enhanced select', 'woocommerce'), 'i18n_input_too_long_1' => _x('Please delete 1 character', 'enhanced select', 'woocommerce'), 'i18n_input_too_long_n' => _x('Please delete %qty% characters', 'enhanced select', 'woocommerce'), 'i18n_selection_too_long_1' => _x('You can only select 1 item', 'enhanced select', 'woocommerce'), 'i18n_selection_too_long_n' => _x('You can only select %qty% items', 'enhanced select', 'woocommerce'), 'i18n_load_more' => _x('Loading more results&hellip;', 'enhanced select', 'woocommerce'), 'i18n_searching' => _x('Searching&hellip;', 'enhanced select', 'woocommerce'));
             break;
     }
     return false;
 }
Exemple #9
0
function removeCartToFly()
{
    global $woocommerce;
    $woocommerce->cart->set_quantity($_POST['remove_item'], 0);
    if ($woocommerce->cart) {
        $items_in_cart = $woocommerce->cart->cart_contents_count;
        $prod_ids_in_cart = array();
        foreach ($woocommerce->cart->get_cart() as $cart_item_key => $cart_item) {
            $product_id = apply_filters('woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key);
            array_push($prod_ids_in_cart, $product_id);
        }
        $test01 = 0;
        $test02 = 0;
        $test03 = 0;
        $test04 = 0;
        if (in_array("566", $prod_ids_in_cart)) {
            $test01 = 1;
        }
        if (in_array("568", $prod_ids_in_cart)) {
            $test02 = 1;
        }
        if (in_array("570", $prod_ids_in_cart)) {
            $test03 = 1;
        }
        if (in_array("572", $prod_ids_in_cart)) {
            $test04 = 1;
        }
        $how_many_tests_in_cart = $test01 + $test02 + $test03 + $test04;
        if (in_array("574", $prod_ids_in_cart)) {
            foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
                if ($cart_item['product_id'] == 574) {
                    $woocommerce->cart->set_quantity($cart_item_key, 0);
                }
            }
            if ($how_many_tests_in_cart == 0) {
            }
            if ($how_many_tests_in_cart == 1) {
                $woocommerce->cart->add_to_cart('574', '1', '719', '1');
            }
            if ($how_many_tests_in_cart == 2) {
                $woocommerce->cart->add_to_cart('574', '1', '720', '2');
            }
            if ($how_many_tests_in_cart == 3) {
                $woocommerce->cart->add_to_cart('574', '1', '721', '3');
            }
            if ($how_many_tests_in_cart == 4) {
                $woocommerce->cart->add_to_cart('574', '1', '722', '4');
            }
        }
        // end if there is processing in cart
    }
    // edn of if woocommerce cart
    $ver = explode(".", WC_VERSION);
    if ($ver[0] >= 2 && $ver[1] >= 0 && $ver[2] >= 0) {
        $wc_ajax = new WC_AJAX();
        $wc_ajax->get_refreshed_fragments();
    } else {
        woocommerce_get_refreshed_fragments();
    }
    die;
}
 function so_27270880_add_variation_to_cart()
 {
     ob_start();
     $product_id = apply_filters('woocommerce_add_to_cart_product_id', absint($_POST['product_id']));
     $quantity = empty($_POST['quantity']) ? 1 : wc_stock_amount($_POST['quantity']);
     $variation_id = isset($_POST['variation_id']) ? absint($_POST['variation_id']) : '';
     $variations = !empty($_POST['variation']) ? (array) $_POST['variation'] : '';
     $passed_validation = apply_filters('woocommerce_add_to_cart_validation', true, $product_id, $quantity, $variation_id, $variations, $cart_item_data);
     if ($passed_validation && WC()->cart->add_to_cart($product_id, $quantity, $variation_id, $variations)) {
         do_action('woocommerce_ajax_added_to_cart', $product_id);
         if (get_option('woocommerce_cart_redirect_after_add') == 'yes') {
             wc_add_to_cart_message($product_id);
         }
         // Return fragments
         WC_AJAX::get_refreshed_fragments();
     } else {
         // If there was an error adding to the cart, redirect to the product page to show any errors
         $data = array('error' => true, 'product_url' => apply_filters('woocommerce_cart_redirect_after_error', get_permalink($product_id), $product_id));
         wp_send_json($data);
     }
     die;
 }
Exemple #11
0
function porto_refresh_cart_fragment()
{
    $cart_ajax = new WC_AJAX();
    $cart_ajax->get_refreshed_fragments();
    exit;
}
 public function json_search_products()
 {
     WC_AJAX::json_search_products('', array('product'));
 }
 /**
  * Enqueue the scripts and styles in the page
  */
 public function enqueue_scripts()
 {
     // scripts
     wp_enqueue_script('yith-woocompare-main', YITH_WOOCOMPARE_ASSETS_URL . '/js/woocompare.js', array('jquery'), $this->version, true);
     wp_localize_script('yith-woocompare-main', 'yith_woocompare', array('ajaxurl' => WC_AJAX::get_endpoint("%%endpoint%%"), 'actionadd' => $this->action_add, 'actionremove' => $this->action_remove, 'actionview' => $this->action_view, 'added_label' => __('Added', 'yith-woocommerce-compare'), 'table_title' => __('Product Comparison', 'yith-woocommerce-compare'), 'auto_open' => get_option('yith_woocompare_auto_open', 'yes'), 'loader' => YITH_WOOCOMPARE_ASSETS_URL . '/images/loader.gif', 'button_text' => get_option('yith_woocompare_button_text')));
     // colorbox
     wp_enqueue_style('jquery-colorbox', YITH_WOOCOMPARE_ASSETS_URL . '/css/colorbox.css');
     wp_enqueue_script('jquery-colorbox', YITH_WOOCOMPARE_ASSETS_URL . '/js/jquery.colorbox-min.js', array('jquery'), '1.4.21', true);
     // widget
     if (is_active_widget(false, false, 'yith-woocompare-widget', true) && !is_admin()) {
         wp_enqueue_style('yith-woocompare-widget', YITH_WOOCOMPARE_ASSETS_URL . '/css/widget.css');
     }
 }
 /**
  * Install WC
  */
 public static function install()
 {
     global $wpdb;
     if (!defined('WC_INSTALLING')) {
         define('WC_INSTALLING', true);
     }
     // Ensure needed classes are loaded
     include_once 'admin/class-wc-admin-notices.php';
     self::create_options();
     self::create_tables();
     self::create_roles();
     // Register post types
     WC_Post_types::register_post_types();
     WC_Post_types::register_taxonomies();
     // Also register endpoints - this needs to be done prior to rewrite rule flush
     WC()->query->init_query_vars();
     WC()->query->add_endpoints();
     WC_API::add_endpoint();
     WC_Auth::add_endpoint();
     WC_AJAX::add_endpoint();
     self::create_terms();
     self::create_cron_jobs();
     self::create_files();
     // Queue upgrades
     $current_db_version = get_option('woocommerce_db_version', null);
     if (version_compare($current_db_version, '2.3.0', '<') && null !== $current_db_version) {
         WC_Admin_Notices::add_notice('update');
     } else {
         delete_option('woocommerce_db_version');
         add_option('woocommerce_db_version', WC()->version);
     }
     // Update version
     delete_option('woocommerce_version');
     add_option('woocommerce_version', WC()->version);
     // Check if pages are needed
     if (wc_get_page_id('shop') < 1) {
         WC_Admin_Notices::add_notice('install');
     }
     // Flush rules after install
     flush_rewrite_rules();
     delete_transient('wc_attribute_taxonomies');
     /*
      * Deletes all expired transients. The multi-table delete syntax is used
      * to delete the transient record from table a, and the corresponding
      * transient_timeout record from table b.
      *
      * Based on code inside core's upgrade_network() function.
      */
     $sql = "DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b\n\t\t\tWHERE a.option_name LIKE %s\n\t\t\tAND a.option_name NOT LIKE %s\n\t\t\tAND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) )\n\t\t\tAND b.option_value < %d";
     $wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('_transient_') . '%', $wpdb->esc_like('_transient_timeout_') . '%', time()));
     // Redirect to welcome screen
     if (!is_network_admin() && !isset($_GET['activate-multi'])) {
         set_transient('_wc_activation_redirect', 1, 30);
     }
     // Trigger action
     do_action('woocommerce_installed');
 }
Exemple #15
0
function venedor_ajax_product_remove()
{
    $cart = WC()->instance()->cart;
    $cart_id = $_POST['cart_id'];
    $cart_item_id = $cart->find_product_in_cart($cart_id);
    if ($cart_item_id) {
        $cart->set_quantity($cart_item_id, 0);
    }
    $cart_ajax = new WC_AJAX();
    $cart_ajax->get_refreshed_fragments();
    exit;
}
 public function addToCart()
 {
     check_ajax_referer('jckqv', 'nonce');
     global $woocommerce;
     $varId = isset($_GET['variation_id']) ? $_GET['variation_id'] : '';
     $_GET['quantity'] = isset($_GET['quantity']) ? $_GET['quantity'] : 1;
     $variations = array();
     foreach ($_GET as $key => $value) {
         if (substr($key, 0, 10) == "attribute_") {
             $variations[$key] = $value;
         }
     }
     if (is_array($_GET['quantity'])) {
         foreach ($_GET['quantity'] as $prodId => $prodQty) {
             if ($prodQty > 0) {
                 $atc = $woocommerce->cart->add_to_cart($prodId, $prodQty, $varId, $variations);
                 if ($atc) {
                     continue;
                 } else {
                     break;
                 }
             }
         }
     } else {
         $atc = $woocommerce->cart->add_to_cart($_GET['product_id'], $_GET['quantity'], $varId, $variations);
     }
     if ($atc) {
         $woocommerce->cart->maybe_set_cart_cookies();
         $wc_ajax = new WC_AJAX();
         $wc_ajax->get_refreshed_fragments();
     } else {
         header('Content-Type: application/json');
         $soldIndv = get_post_meta($_GET['product_id'], '_sold_individually', true);
         if ($soldIndv == "yes") {
             $response = array('result' => 'individual');
             $response['message'] = __('Sorry, that item can only be added once.', $this->slug);
         } else {
             $response = array('result' => 'fail');
             $response['message'] = __('Sorry, something went wrong. Please try again.', $this->slug);
         }
         $response['get'] = $_GET;
         echo json_encode($response);
     }
     die;
 }
 /**
  * Enqueue the scripts and styles in the page
  */
 public function enqueue_scripts()
 {
     // scripts
     $min = !(defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '.min' : '';
     wp_register_script('yith-woocompare-main', YITH_WOOCOMPARE_ASSETS_URL . '/js/woocompare' . $min . '.js', array('jquery'), $this->version, true);
     // enqueue and add localize
     wp_enqueue_script('yith-woocompare-main');
     wp_localize_script('yith-woocompare-main', 'yith_woocompare', array('ajaxurl' => version_compare(WC()->version, '2.4', '>=') ? WC_AJAX::get_endpoint("%%endpoint%%") : admin_url('admin-ajax.php', 'relative'), 'actionadd' => $this->action_add, 'actionremove' => $this->action_remove, 'actionview' => $this->action_view, 'added_label' => apply_filters('yith_woocompare_compare_added_label', __('Added', 'yith-woocommerce-compare')), 'table_title' => apply_filters('yith_woocompare_compare_table_title', __('Product Comparison', 'yith-woocommerce-compare')), 'auto_open' => get_option('yith_woocompare_auto_open', 'yes'), 'loader' => YITH_WOOCOMPARE_ASSETS_URL . '/images/loader.gif', 'button_text' => get_option('yith_woocompare_button_text')));
     // colorbox
     wp_enqueue_style('jquery-colorbox', YITH_WOOCOMPARE_ASSETS_URL . '/css/colorbox.css');
     wp_enqueue_script('jquery-colorbox', YITH_WOOCOMPARE_ASSETS_URL . '/js/jquery.colorbox-min.js', array('jquery'), '1.4.21', true);
     // widget
     if (is_active_widget(false, false, 'yith-woocompare-widget', true) && !is_admin()) {
         wp_enqueue_style('yith-woocompare-widget', YITH_WOOCOMPARE_ASSETS_URL . '/css/widget.css');
     }
 }
 /**
  * Return data for script handles.
  * @access private
  * @param  string $handle
  * @return array|bool
  */
 private static function get_script_data($handle)
 {
     global $wp;
     switch ($handle) {
         case 'woocommerce':
             return array('ajax_url' => WC()->ajax_url(), 'wc_ajax_url' => WC_AJAX::get_endpoint("%%endpoint%%"));
             break;
         case 'wc-geolocation':
             return array('wc_ajax_url' => WC_AJAX::get_endpoint("%%endpoint%%"), 'home_url' => home_url(), 'is_available' => !(is_cart() || is_account_page() || is_checkout() || is_customize_preview()) ? '1' : '0', 'hash' => isset($_GET['version']) ? wc_clean($_GET['version']) : '');
             break;
         case 'wc-single-product':
             return array('i18n_required_rating_text' => esc_attr__('Please select a rating', 'woocommerce'), 'review_rating_required' => get_option('woocommerce_review_rating_required'), 'flexslider' => apply_filters('woocommerce_single_product_carousel_options', array('rtl' => is_rtl(), 'animation' => 'slide', 'smoothHeight' => true, 'directionNav' => false, 'controlNav' => 'thumbnails', 'slideshow' => false, 'animationSpeed' => 500)));
             break;
         case 'wc-checkout':
             return array('ajax_url' => WC()->ajax_url(), 'wc_ajax_url' => WC_AJAX::get_endpoint("%%endpoint%%"), 'update_order_review_nonce' => wp_create_nonce('update-order-review'), 'apply_coupon_nonce' => wp_create_nonce('apply-coupon'), 'remove_coupon_nonce' => wp_create_nonce('remove-coupon'), 'option_guest_checkout' => get_option('woocommerce_enable_guest_checkout'), 'checkout_url' => WC_AJAX::get_endpoint("checkout"), 'is_checkout' => is_page(wc_get_page_id('checkout')) && empty($wp->query_vars['order-pay']) && !isset($wp->query_vars['order-received']) ? 1 : 0, 'debug_mode' => defined('WP_DEBUG') && WP_DEBUG, 'i18n_checkout_error' => esc_attr__('Error processing checkout. Please try again.', 'woocommerce'));
             break;
         case 'wc-address-i18n':
             return array('locale' => json_encode(WC()->countries->get_country_locale()), 'locale_fields' => json_encode(WC()->countries->get_country_locale_field_selectors()), 'i18n_required_text' => esc_attr__('required', 'woocommerce'));
             break;
         case 'wc-cart':
             return array('ajax_url' => WC()->ajax_url(), 'wc_ajax_url' => WC_AJAX::get_endpoint("%%endpoint%%"), 'update_shipping_method_nonce' => wp_create_nonce("update-shipping-method"), 'apply_coupon_nonce' => wp_create_nonce("apply-coupon"), 'remove_coupon_nonce' => wp_create_nonce("remove-coupon"));
             break;
         case 'wc-cart-fragments':
             return array('ajax_url' => WC()->ajax_url(), 'wc_ajax_url' => WC_AJAX::get_endpoint("%%endpoint%%"), 'fragment_name' => apply_filters('woocommerce_cart_fragment_name', 'wc_fragments'));
             break;
         case 'wc-add-to-cart':
             return array('ajax_url' => WC()->ajax_url(), 'wc_ajax_url' => WC_AJAX::get_endpoint("%%endpoint%%"), 'i18n_view_cart' => esc_attr__('View cart', 'woocommerce'), 'cart_url' => apply_filters('woocommerce_add_to_cart_redirect', wc_get_cart_url()), 'is_cart' => is_cart(), 'cart_redirect_after_add' => get_option('woocommerce_cart_redirect_after_add'));
             break;
         case 'wc-add-to-cart-variation':
             // We also need the wp.template for this script :)
             wc_get_template('single-product/add-to-cart/variation.php');
             return array('wc_ajax_url' => WC_AJAX::get_endpoint("%%endpoint%%"), 'i18n_no_matching_variations_text' => esc_attr__('Sorry, no products matched your selection. Please choose a different combination.', 'woocommerce'), 'i18n_make_a_selection_text' => esc_attr__('Please select some product options before adding this product to your cart.', 'woocommerce'), 'i18n_unavailable_text' => esc_attr__('Sorry, this product is unavailable. Please choose a different combination.', 'woocommerce'));
             break;
         case 'wc-country-select':
             return array('countries' => json_encode(array_merge(WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states())), 'i18n_select_state_text' => esc_attr__('Select an option&hellip;', 'woocommerce'), 'i18n_matches_1' => _x('One result is available, press enter to select it.', 'enhanced select', 'woocommerce'), 'i18n_matches_n' => _x('%qty% results are available, use up and down arrow keys to navigate.', 'enhanced select', 'woocommerce'), 'i18n_no_matches' => _x('No matches found', 'enhanced select', 'woocommerce'), 'i18n_ajax_error' => _x('Loading failed', 'enhanced select', 'woocommerce'), 'i18n_input_too_short_1' => _x('Please enter 1 or more characters', 'enhanced select', 'woocommerce'), 'i18n_input_too_short_n' => _x('Please enter %qty% or more characters', 'enhanced select', 'woocommerce'), 'i18n_input_too_long_1' => _x('Please delete 1 character', 'enhanced select', 'woocommerce'), 'i18n_input_too_long_n' => _x('Please delete %qty% characters', 'enhanced select', 'woocommerce'), 'i18n_selection_too_long_1' => _x('You can only select 1 item', 'enhanced select', 'woocommerce'), 'i18n_selection_too_long_n' => _x('You can only select %qty% items', 'enhanced select', 'woocommerce'), 'i18n_load_more' => _x('Loading more results&hellip;', 'enhanced select', 'woocommerce'), 'i18n_searching' => _x('Searching&hellip;', 'enhanced select', 'woocommerce'));
             break;
         case 'wc-password-strength-meter':
             return array('min_password_strength' => apply_filters('woocommerce_min_password_strength', 3), 'i18n_password_error' => esc_attr__('Please enter a stronger password.', 'woocommerce'), 'i18n_password_hint' => esc_attr__('The password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers and symbols like ! " ? $ % ^ &amp; ).', 'woocommerce'));
             break;
     }
     return false;
 }
 /**
  * Install WC
  */
 public static function install()
 {
     if (!defined('WC_INSTALLING')) {
         define('WC_INSTALLING', true);
     }
     // Ensure needed classes are loaded
     include_once 'admin/class-wc-admin-notices.php';
     self::create_options();
     self::create_tables();
     self::create_roles();
     // Register post types
     WC_Post_types::register_post_types();
     WC_Post_types::register_taxonomies();
     // Also register endpoints - this needs to be done prior to rewrite rule flush
     WC()->query->init_query_vars();
     WC()->query->add_endpoints();
     WC_API::add_endpoint();
     WC_AJAX::add_endpoint();
     self::create_terms();
     self::create_cron_jobs();
     self::create_files();
     // Queue upgrades
     $current_db_version = get_option('woocommerce_db_version', null);
     if (version_compare($current_db_version, '2.3.0', '<') && null !== $current_db_version) {
         WC_Admin_Notices::add_notice('update');
     } else {
         delete_option('woocommerce_db_version');
         add_option('woocommerce_db_version', WC()->version);
     }
     // Update version
     delete_option('woocommerce_version');
     add_option('woocommerce_version', WC()->version);
     // Check if pages are needed
     if (wc_get_page_id('shop') < 1) {
         WC_Admin_Notices::add_notice('install');
     }
     // Flush rules after install
     flush_rewrite_rules();
     delete_transient('wc_attribute_taxonomies');
     // Redirect to welcome screen
     if (!is_network_admin() && !isset($_GET['activate-multi'])) {
         set_transient('_wc_activation_redirect', 1, 30);
     }
     // Trigger action
     do_action('woocommerce_installed');
 }