示例#1
0
文件: woo-json.php 项目: bulats/chef
function woo_insert_update_data($post)
{
    global $wpdb, $woocommerce;
    $_POST = $post;
    // Fix: PHP 5.4
    $editable_fields = array('_billing_first_name', '_billing_last_name', '_billing_email', '_billing_address_1', '_billing_address_2', '_billing_city', '_billing_state', '_billing_country', '_billing_postcode', '_billing_phone', '_shipping_first_name', '_shipping_last_name', '_shipping_address_1', '_shipping_address_2', '_shipping_city', '_shipping_state', '_shipping_country', '_shipping_postcode', 'order_status');
    $new_product = json_decode($_POST['edited']);
    $result = array('productId' => array());
    // To get distinct meta_key for Simple Products. => Executed only once
    $post_meta_info = $wpdb->get_col("SELECT distinct postmeta.meta_key FROM {$wpdb->prefix}postmeta AS postmeta INNER JOIN {$wpdb->prefix}posts AS posts on posts.ID = postmeta.post_id WHERE posts.post_type='product' AND posts.post_status IN ('publish','draft')");
    // To get distinct meta_key for Child Products i.e. Variations. => Executed only once
    $post_meta_info_variations = $wpdb->get_col("SELECT distinct postmeta.meta_key FROM {$wpdb->prefix}postmeta AS postmeta INNER JOIN {$wpdb->prefix}posts AS posts on posts.ID = postmeta.post_id WHERE posts.post_type='product_variation' AND posts.post_status IN ('publish','draft') AND posts.post_parent > 0");
    // meta_key required for new products, that are entered through Smart Manager
    if (count($post_meta_info) <= 0 || count($post_meta_info) < 23) {
        $post_meta_info = array('_edit_last', '_edit_lock', '_regular_price', '_sale_price', '_weight', '_length', '_width', '_height', '_tax_status', '_tax_class', '_stock_status', '_visibility', '_featured', '_sku', '_product_attributes', '_downloadable', '_virtual', '_sale_price_dates_from', '_sale_price_dates_to', '_price', '_stock', '_manage_stock', '_backorders');
    }
    if (is_foreachable($new_product)) {
        foreach ($new_product as $obj) {
            if ($_POST['active_module'] == 'Products') {
                $price = get_price($obj->_regular_price, $obj->_sale_price, $obj->_sale_price_dates_from, $obj->_sale_price_dates_to);
                if (isset($obj->id) && $obj->id != '') {
                    $product_custom_fields = get_post_custom($obj->id);
                    // woocommerce uses this method to load product's details before creating WooCommerce Product Object
                    $post = get_post($obj->id);
                    // woocommerce load posts from cache
                    $terms = wp_get_object_terms($obj->id, 'product_type', array('fields' => 'names'));
                    // woocommerce gets product_type using this method
                    $product_type = isset($terms[0]) ? sanitize_title($terms[0]) : 'simple';
                    if ($product_type == 'variable') {
                        // To unset price fields for Parent Products having variations
                        $obj->_regular_price = '';
                        $obj->_sale_price = '';
                        $obj->_price = $price = $product_custom_fields['_min_variation_sale_price'][0] === '' || $product_custom_fields['_min_variation_regular_price'][0] < $product_custom_fields['_min_variation_sale_price'][0] ? $product_custom_fields['_min_variation_regular_price'][0] : $product_custom_fields['_min_variation_sale_price'][0];
                    }
                } else {
                    //to not include current date for sales price for new product
                    $obj->_sale_price_dates_from = '';
                    $obj->_sale_price_dates_to = '';
                    $price = get_price($obj->_regular_price, $obj->_sale_price, $obj->_sale_price_dates_from, $obj->_sale_price_dates_to);
                }
                if (!(empty($obj->post_parent) || $obj->post_parent == '')) {
                    $id = $obj->post_parent;
                    $product_type_parent = wp_get_object_terms($id, 'product_type', array('fields' => 'slugs'));
                }
                if ($_POST['SM_IS_WOO16'] == "true") {
                    if ($obj->post_parent > 0 && $product_type_parent[0] != "grouped") {
                        $price = $obj->_regular_price;
                    }
                }
                // create an array to be used for updating product's details. add modified value from Smart Manager & rest same as in original post
                $postarr = array('ID' => isset($obj->id) ? $obj->id : '', 'post_author' => isset($post->post_author) ? $post->post_author : '', 'post_content' => isset($obj->post_content) ? $obj->post_content : '', 'post_title' => isset($obj->post_title) ? $obj->post_title : '', 'post_excerpt' => isset($obj->post_excerpt) ? $obj->post_excerpt : '', 'post_date' => isset($post->post_date) ? $post->post_date : '', 'post_date_gmt' => isset($post->post_date_gmt) ? $post->post_date_gmt : '', 'post_status' => isset($obj->post_status) ? $obj->post_status : '', 'comment_status' => isset($post->comment_status) ? $post->comment_status : 'open', 'ping_status' => isset($post->ping_status) ? $post->ping_status : 'open', 'post_parent' => isset($obj->post_parent) ? $obj->post_parent : $post->post_parent, 'guid' => isset($post->guid) ? $post->guid : site_url() . '/?post_type=product&p=' . $post->ID, 'menu_order' => isset($post->menu_order) ? $post->menu_order : 0, 'post_type' => isset($post->post_type) ? $post->post_type : 'product', 'comment_count' => isset($post->comment_count) ? $post->comment_count : 0, 'ancestors' => isset($post->ancestors) ? $post->ancestors : array(), 'filter' => isset($post->filter) ? $post->filter : 'raw', '_product_attributes' => isset($product_custom_fields['_product_attributes'][0]) ? $product_custom_fields['_product_attributes'][0] : serialize(array()), 'user_ID' => 1, 'action' => 'editpost', 'originalaction' => 'editpost', 'original_post_status' => 'auto-draft', 'auto_draft' => 1, 'post_ID' => $obj->id, 'hidden_post_status' => 'draft', 'hidden_post_visibility' => 'public', '_visibility' => isset($obj->_visibility) ? $obj->_visibility : 'visible', 'original_publish' => 'Publish', 'publish' => 'Publish', 'newproduct_cat' => 'New Product Category Name', 'newproduct_cat_parent' => -1, 'content' => isset($obj->post_content) ? $obj->post_content : $post->post_content, 'product-type' => isset($product_type) ? $product_type : 'simple', '_virtual' => isset($product_custom_fields['_virtual'][0]) ? $product_custom_fields['_virtual'][0] : 'no', '_downloadable' => isset($product_custom_fields['_downloadable'][0]) ? $product_custom_fields['_downloadable'][0] : 'no', '_featured' => isset($product_custom_fields['_featured'][0]) ? $product_custom_fields['_featured'][0] : 'no', '_sku' => isset($obj->_sku) ? $obj->_sku : '', '_price' => $price, '_regular_price' => isset($obj->_regular_price) ? $obj->_regular_price : '', '_sale_price' => isset($obj->_sale_price) ? $obj->_sale_price : '', '_sale_price_dates_from' => isset($obj->_sale_price_dates_from) ? strtotime($obj->_sale_price_dates_from) : '', '_sale_price_dates_to' => isset($obj->_sale_price_dates_to) ? strtotime($obj->_sale_price_dates_to) : '', '_weight' => isset($obj->_weight) ? $obj->_weight : '', '_length' => isset($obj->_length) ? $obj->_length : '', '_width' => isset($obj->_width) ? $obj->_width : '', '_height' => isset($obj->_height) ? $obj->_height : '', '_tax_status' => isset($obj->_tax_status) ? $obj->_tax_status : 'taxable', '_tax_class' => isset($product_custom_fields['_tax_class'][0]) ? $product_custom_fields['_tax_class'][0] : '', '_manage_stock' => isset($product_custom_fields['_manage_stock'][0]) ? $product_custom_fields['_manage_stock'][0] : '', '_stock_status' => isset($product_custom_fields['_stock_status'][0]) ? $product_custom_fields['_stock_status'][0] : '', '_stock' => isset($obj->_stock) ? $obj->_stock : '', '_backorders' => isset($product_custom_fields['_backorders'][0]) ? $product_custom_fields['_backorders'][0] : 'no', 'excerpt' => isset($obj->post_excerpt) ? $obj->post_excerpt : $post->post_excerpt, 'advanced_view' => 1);
                if ($obj->post_parent == 0 && $obj->product_type != 'variable' || $product_type_parent[0] == "grouped") {
                    $post_id = wp_insert_post($postarr);
                    $post_meta_key = $post_meta_info;
                } else {
                    $parent_id = $postarr['post_parent'];
                    $post_id = $postarr['ID'];
                    $post_meta_key = $post_meta_info_variations;
                }
                array_push($result['productId'], $post_id);
                foreach ($post_meta_key as $object) {
                    // ================================================================================================
                    // Code for enabling negative values for inline editing
                    // ================================================================================================
                    // if ( $object == '_sale_price' || $object == '_price' || $object == '_regular_price' ) {
                    //     update_post_meta($wpdb->_real_escape($post_id), $wpdb->_real_escape($object), $wpdb->_real_escape($postarr[$object]) );
                    //     continue;
                    // }
                    // ================================================================================================
                    if (isset($postarr[$object]) && $postarr[$object] > -1) {
                        // to skip query for blank value
                        //Code to handle the condition for the attribute visibility on product page issue while save action
                        if ($object == '_product_attributes' && isset($product_custom_fields['_product_attributes'][0])) {
                            continue;
                        }
                        if (empty($obj->id) || $obj->id == '') {
                            $query = "INSERT INTO {$wpdb->prefix}postmeta(post_id,meta_key,meta_value) values(" . $wpdb->_real_escape($post_id) . ", '" . $wpdb->_real_escape($object) . "', '" . $wpdb->_real_escape($postarr[$object]) . "')";
                            $var = $wpdb->query($query);
                            wp_set_object_terms($post_id, 'simple', 'product_type');
                        } else {
                            //$query = "UPDATE {$wpdb->prefix}postmeta SET meta_value = '".$wpdb->_real_escape($postarr[$object])."' WHERE post_id = " . $wpdb->_real_escape($post_id) . " AND meta_key = '" . $wpdb->_real_escape($object) . "'";
                            update_post_meta($wpdb->_real_escape($post_id), $wpdb->_real_escape($object), $wpdb->_real_escape($postarr[$object]));
                        }
                    }
                }
                //Code For updating the parent price of the product
                if ($parent_id > 0) {
                    variable_price_sync($parent_id);
                }
            } elseif ($_POST['active_module'] == 'Orders') {
                foreach ($obj as $key => $value) {
                    if (in_array($key, $editable_fields)) {
                        if ($key == 'order_status') {
                            $term_taxonomy_id = get_term_taxonomy_id($value);
                            $query = "UPDATE {$wpdb->prefix}term_relationships SET term_taxonomy_id = " . $wpdb->_real_escape($term_taxonomy_id) . " WHERE object_id = " . $wpdb->_real_escape($obj->id) . ";";
                            if ($value == 'processing' || $value == 'completed') {
                                $order = new WC_Order($obj->id);
                                $order->update_status($value);
                            }
                        } else {
                            $query = "UPDATE {$wpdb->prefix}postmeta SET meta_value = '" . $wpdb->_real_escape($value) . "' WHERE post_id = " . $wpdb->_real_escape($obj->id) . " AND meta_key = '" . $wpdb->_real_escape($key) . "';";
                        }
                        $wpdb->query($query);
                    }
                }
            } elseif ($_POST['active_module'] == 'Customers') {
                //Query to get the email and customer_user for all the selected ids
                $query_email = "SELECT DISTINCT(GROUP_CONCAT( meta_value\n                                     ORDER BY meta_id SEPARATOR '###' ) )AS meta_value,\n                                     GROUP_CONCAT(distinct meta_key\n                                     ORDER BY meta_id SEPARATOR '###' ) AS meta_key\n                                FROM {$wpdb->prefix}postmeta \n                                WHERE meta_key in ('_billing_email','_customer_user') \n                                AND post_id={$wpdb->_real_escape}({$obj->id})";
                $result_email = $wpdb->get_results($query_email, 'ARRAY_A');
                $email = "";
                $users = "";
                for ($i = 0; $i < sizeof($result_email); $i++) {
                    $meta_key = explode("###", $result_email[$i]['meta_key']);
                    $meta_value = explode("###", $result_email[$i]['meta_value']);
                    $postmeta[$i] = array_combine($meta_key, $meta_value);
                    $email[$i] = $postmeta[$i]['_billing_email'];
                    $users[$i] = $postmeta[$i]['_customer_user'];
                    unset($meta_key);
                    unset($meta_value);
                }
                $email = "'" . implode("','", $email) . "'";
                $users = implode(",", $users);
                //Query for getting al the post ids using the email id
                if ($users == 0) {
                    $query_ids = "SELECT post_id FROM {$wpdb->prefix}postmeta WHERE meta_value = {$email}";
                    $id = implode(", ", $wpdb->get_col($query_ids));
                }
                foreach ($obj as $key => $value) {
                    if (in_array($key, $editable_fields)) {
                        if ($users == 0) {
                            $query = "UPDATE {$wpdb->prefix}postmeta SET meta_value = '" . $wpdb->_real_escape($value) . "' WHERE post_id IN ({$id}) AND meta_key = '" . $wpdb->_real_escape($key) . "';";
                        } elseif ($users > 0) {
                            $key = substr($key, 1);
                            //removing the first underscore from the column name as the columns for p_usermeta are different from that of wp_postmeta
                            //Code for updating the email of the Customer in the wp_users Table
                            if ($key == "billing_email") {
                                $query = "UPDATE {$wpdb->prefix}users SET user_email = '" . $wpdb->_real_escape($value) . "' WHERE id IN ({$users}) ;";
                                $wpdb->query($query);
                            }
                            $query = "UPDATE {$wpdb->prefix}usermeta SET meta_value = '" . $wpdb->_real_escape($value) . "' WHERE user_id IN ({$users}) AND meta_key = '" . $wpdb->_real_escape($key) . "';";
                        }
                        $wpdb->query($query);
                    }
                }
            }
            if (empty($obj->id) || $obj->id == '') {
                if (!isset($result['inserted'])) {
                    $result['inserted'] = 1;
                    $result['insertCnt'] = 1;
                } else {
                    $result['insertCnt']++;
                }
            } else {
                if (!isset($result['updated'])) {
                    $result['updated'] = 1;
                    $result['updateCnt'] = 1;
                } else {
                    $result['updateCnt']++;
                }
            }
        }
    } else {
        $result = array('inserted' => 0, 'insertCnt' => 0, 'updated' => 0, 'updateCnt' => 0);
    }
    //Clearing the transients to handle the proper functioning of the widgets
    $woocommerce->clear_product_transients();
    return $result;
}
示例#2
0
文件: woo.php 项目: bulats/chef
function batchUpdateWoo($post)
{
    global $post_status_update, $table_prefix, $wpdb, $sql_results, $woocommerce;
    $_POST = $post;
    // Fix: PHP 5.4
    if (!empty($wpdb->prefix)) {
        $wp_table_prefix = $wpdb->prefix;
    }
    if (isset($_POST['edited'])) {
        $_POST['active_module'] = $_POST['activeModule'];
        $result = woo_insert_update_data($_POST);
    }
    $ids = json_decode(stripslashes($_POST['ids']));
    $radioData = '';
    // For WP_Debug
    $flag = '';
    // For WP_Debug
    if ($_POST['activeModule'] == 'Products') {
        $active_module = 'Products';
        $actions = json_decode($_POST['updateDetails']);
        $sel_records = json_decode($_POST['selected']);
        $radioData = $wpdb->_real_escape($_POST['radio']);
        $flag = $wpdb->_real_escape($_POST['flag']);
        // create an array of ids (newly added products & modified products)
        $count = isset($result['updateCnt']) ? $result['updateCnt'] : 0;
        //to skip updated & unselected records from batch update
        for ($i = 0; $i < count($ids); $i++) {
            if (strstr($ids[$i], 'ext-record') != '') {
                $ids_temp[$i] = $result['productId'][$count];
                $count++;
            }
        }
        if (isset($sel_records) && $sel_records != null) {
            //collectin the variation product's id
            foreach ($sel_records as $record) {
                if (isset($record->id) && !empty($record->id) && $record->id != '') {
                    if ($record->post_parent != 0) {
                        $children_ids[] = $record->id;
                    } else {
                        $parent_ids[] = $record->id;
                    }
                } else {
                    $parent_ids = $result['productId'];
                }
            }
        }
    } else {
        if ($_POST['activeModule'] == 'Customers') {
            $active_module = 'Customers';
        } else {
            $active_module = 'Orders';
        }
        $actions = json_decode($_POST['values']);
    }
    //$idLength = count ( $ids );
    $idLength = json_decode(stripslashes($_POST['fupdatecnt']));
    // code to handle the message for different number of max. records
    $length = count($actions);
    $all_ids = get_all_ids($sql_results);
    $_POST['actions_count'] = $length;
    // For distributing ids based on product type, will help in reducing number of queries
    if ($active_module == 'Products') {
        $variation_parent_id = array();
        $selected_id = array();
        $selected_id_variation = array();
        $all_id = array();
        $all_id_variation = array();
        foreach ($sel_records as $sel_record) {
            $terms = wp_get_object_terms($sel_record->id, 'product_type', array('fields' => 'names'));
            // woocommerce gets product_type using this method
            $post_parent = $wpdb->get_var("SELECT post_parent FROM {$wpdb->posts} WHERE ID = {$sel_record->id};");
            if (sanitize_title($terms[0]) == 'variable' && $post_parent == 0) {
                $variation_parent_id[] = $sel_record->id;
            } else {
                if ($post_parent > 0 && sanitize_title($terms[0]) == 'simple') {
                    $selected_id[] = $sel_record->id;
                } elseif ($post_parent > 0) {
                    $selected_id_variation[] = $sel_record->id;
                } else {
                    $selected_id[] = $sel_record->id;
                }
            }
        }
        $all_ids_grouped = array();
        // Array used for passing ids to function for processing variations
        $all_ids_grouped['selected_id'] = $selected_id;
        $all_ids_grouped['variation_parent_id'] = $variation_parent_id;
        $all_ids_grouped['selected_id_variation'] = $selected_id_variation;
        $all_ids_grouped['all_id'] = $all_id;
        $all_ids_grouped['all_id_variation'] = $all_id_variation;
        $parent_ids = array_merge($all_ids_grouped['selected_id'], $all_ids_grouped['variation_parent_id']);
        $results = $wpdb->get_results("SELECT attribute_name FROM {$wpdb->prefix}woocommerce_attribute_taxonomies", 'ARRAY_A');
        $attribute_names = array();
        $count = 0;
        foreach ($results as $result) {
            $attribute_names[] = $result['attribute_name'];
            $count++;
        }
        // For handling modification in attributes of parent product
        foreach ($parent_ids as $parent_id) {
            for ($i = 0; $i < count($actions); $i++) {
                $actions_colfilter = property_exists($actions[$i], 'colFilter') === true ? $actions[$i]->colFilter : '';
                // For WP_Debug
                if ($actions_colfilter == 'AttributeAdd') {
                    $action = $actions_colfilter;
                    $attribute_name = $actions[$i]->action;
                    $attribute_type = $wpdb->get_var("SELECT attribute_type FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_name LIKE '{$attribute_name}'");
                    if ($attribute_name == 'custom') {
                        $custom_attribute_name = $actions[$i]->colValue;
                        $custom_attribute_terms = $actions[$i]->unit;
                        process_custom_add_attribute($parent_id, $custom_attribute_name, $custom_attribute_terms, $action, $attribute_names);
                    } else {
                        if ($attribute_type == 'text') {
                            $terms = explode('|', $actions[$i]->unit);
                            if (is_array($terms) && count($terms) > 0) {
                                foreach ($terms as $term) {
                                    $term_details = term_exists($term, 'pa_' . $attribute_name);
                                    if (!is_array($term_details) && $term_details == 0) {
                                        $term_details = wp_insert_term($term, 'pa_' . $attribute_name);
                                    }
                                    $term_taxonomy_id = $term_details['term_taxonomy_id'];
                                    process_add_attribute($parent_id, $attribute_name, $term_taxonomy_id, $action, $attribute_names);
                                }
                            }
                        } else {
                            $term_taxonomy_id = $actions[$i]->colValue;
                            process_add_attribute($parent_id, $attribute_name, $term_taxonomy_id, $action, $attribute_names);
                        }
                    }
                } elseif ($actions_colfilter == 'AttributeRemove') {
                    $attribute_name = $actions[$i]->action;
                    $term_taxonomy_id = $actions[$i]->colValue;
                    process_remove_attribute($parent_id, $attribute_name, $term_taxonomy_id);
                }
            }
        }
        // For handling changes in attributes of product variation
        foreach ($all_ids_grouped['selected_id_variation'] as $c_id) {
            for ($i = 0; $i < count($actions); $i++) {
                $actions_colfilter = property_exists($actions[$i], 'colFilter') === true ? $actions[$i]->colFilter : '';
                // For WP_Debug
                if ($actions_colfilter == 'AttributeChange') {
                    $attribute_name = $actions[$i]->action;
                    $term_taxonomy_id = $actions[$i]->colValue;
                    $taxonomy = "pa_" . $attribute_name;
                    $select = "select t.slug from {$wpdb->prefix}terms as t join {$wpdb->prefix}term_taxonomy as tt on (t.term_id = tt.term_id) where tt.taxonomy = '{$taxonomy}' and t.term_id in ( ";
                    $select .= "select term_id from {$wpdb->prefix}term_taxonomy where term_taxonomy_id = '{$term_taxonomy_id}' ) ";
                    $results = $wpdb->get_results($select, 'ARRAY_A');
                    $term_name = array();
                    foreach ($results as $result) {
                        $term_name[] = $result['slug'];
                    }
                    process_change_attribute($c_id, $attribute_name, $term_taxonomy_id, $term_name);
                }
            }
        }
        // generating string of comma separated ids
        $variation_parent_id = $wpdb->_real_escape(implode(',', $variation_parent_id));
        $selected_id = $wpdb->_real_escape(implode(',', $selected_id));
        $selected_id_variation = $wpdb->_real_escape(implode(',', $selected_id_variation));
        $all_id = $wpdb->_real_escape(implode(',', $all_id));
        //This is commented as the implode function dosent work properly with very long list of ids.
        $product_type_grouped = "";
        $product_type = "";
        $no_product_type = "";
        $price_variation = "";
        //$all_id_variation 		= $wpdb->_real_escape ( implode ( ',', $all_id_variation ) );
        //Query for handling the grouped products updation
        $query_grouped = "SELECT id FROM `{$wpdb->prefix}posts`\n                                    WHERE post_parent IN (SELECT posts.id as id\n                                            FROM `{$wpdb->prefix}posts` AS posts\n                                                JOIN {$wpdb->prefix}term_relationships AS term_relationships \n                                                                ON term_relationships.object_id = posts.id\n                                                JOIN {$wpdb->prefix}term_taxonomy AS term_taxonomy \n                                                                ON term_taxonomy.term_taxonomy_id = term_relationships.term_taxonomy_id \n                                                JOIN {$wpdb->prefix}terms AS terms \n                                                                ON term_taxonomy.term_id = terms.term_id \n                                            WHERE posts.post_parent = 0 \n                                                AND posts.post_type IN ('product')\n                                                AND posts.post_status IN ('publish', 'draft')\n                                                AND terms.slug IN ('grouped'))\n                                        AND id IN (" . implode(",", $ids) . ")\n                                    GROUP BY id\n                                    ORDER BY id desc ";
        $product_type_grouped = implode(",", $wpdb->get_col($query_grouped));
        //Query to get the post_id type of all the simple products
        $query = "SELECT posts.id as id\n                                            FROM `{$wpdb->prefix}posts` AS posts\n                                                JOIN {$wpdb->prefix}term_relationships AS term_relationships \n                                                                ON term_relationships.object_id = posts.id\n                                                JOIN {$wpdb->prefix}term_taxonomy AS term_taxonomy \n                                                                ON term_taxonomy.term_taxonomy_id = term_relationships.term_taxonomy_id \n                                                JOIN {$wpdb->prefix}terms AS terms \n                                                                ON term_taxonomy.term_id = terms.term_id \n                                            WHERE posts.post_parent = 0 \n                                                AND posts.post_type IN ('product')\n                                                AND posts.post_status IN ('publish', 'draft')\n                                                AND terms.slug NOT IN ('variable','grouped','external')\n                                                AND posts.id IN (" . implode(",", $ids) . ")\n                                            GROUP BY posts.id\n                                            ORDER BY posts.id desc ";
        $product_type_result = $wpdb->get_col($query);
        //Query to handle the products which have no type
        $query = "SELECT object_id FROM {$wpdb->prefix}term_relationships\n                                    WHERE object_id IN (" . implode(",", $ids) . ")";
        $result = $wpdb->get_col($query);
        $no_product_type = array_values(array_diff($ids, $result));
        for ($i = 0, $j = sizeof($product_type_result); $i < sizeof($no_product_type); $i++, $j++) {
            //Code to exclude variations from the product type update
            $post_parent = $wpdb->get_var("SELECT post_parent FROM {$wpdb->prefix}posts WHERE ID = {$no_product_type[$i]}");
            if ($post_parent == 0) {
                $product_type_result[$j] = $no_product_type[$i];
                //Code for adding the product type as simple for products having no type
                $terms = wp_set_object_terms($no_product_type[$i], 'simple', 'product_type');
            }
        }
        $product_type = implode(",", array_filter($product_type_result));
        //Query to get the post_id of all the variations for price updation
        $query_variation = "SELECT posts.id as id\n                                            FROM `{$wpdb->prefix}posts` AS posts\n                                            WHERE posts.post_parent > 0 \n                                                AND posts.post_type IN ('product_variation')\n                                                AND posts.post_status IN ('publish', 'draft')\n                                                AND posts.id IN (" . implode(",", $ids) . ")\n                                            GROUP BY posts.id\n                                            ORDER BY posts.id desc ";
        $price_variation = implode(",", $wpdb->get_col($query_variation));
    }
    //Code to get all the term_names along with the term_taxonomy_id in an array
    $query_terms = "SELECT terms.name,term_taxonomy.term_taxonomy_id \n                                FROM {$wpdb->prefix}term_taxonomy AS term_taxonomy\n                                    JOIN {$wpdb->prefix}terms AS terms ON terms.term_id = term_taxonomy.term_id\n                                WHERE taxonomy LIKE 'shop_order_status'";
    $terms = $wpdb->get_results($query_terms, 'ARRAY_A');
    for ($i = 0; $i < sizeof($terms); $i++) {
        $terms_name[$terms[$i]['name']] = $terms[$i]['term_taxonomy_id'];
    }
    // Building queries
    for ($i = 0; $i < $length; $i++) {
        $selected_ids = "";
        if ($active_module == 'Products') {
            $actions_colfilter = property_exists($actions[$i], 'colFilter') === true ? $actions[$i]->colFilter : '';
            // For WP_Debug
            $actions_updatecolname = property_exists($actions[$i], 'updateColName') === true ? $actions[$i]->updateColName : '';
            // For WP_Debug
            $actions_colname = property_exists($actions[$i], 'colName') === true ? $actions[$i]->colName : '';
            // For WP_Debug
            if (substr($actions_colfilter, 0, 8) == 'Attribute') {
                continue;
            }
            $table_name = "`{$wpdb->_real_escape($actions[$i]->tableName)}`";
            $col_id = $wpdb->_real_escape($actions[$i]->colId);
            $is_category = strstr($col_id, 'group') != '' ? true : false;
            $column_name = "{$wpdb->_real_escape($actions_colname)}";
            $action_name = $wpdb->_real_escape($actions[$i]->action);
            $column_filter = $wpdb->_real_escape($actions_colfilter);
            if ($column_name == 'thumbnail') {
                for ($j = 0; $j < sizeof($ids); $j++) {
                    update_post_meta($ids[$j], '_thumbnail_id', $actions[$i]->colValue);
                }
            }
            // populating all ids based on column to be updated
            if ($column_name == "_regular_price" || $column_name == "_sale_price") {
                $all_ids = $all_id;
            } elseif ($column_name == "post_title" || $column_name == "post_status" || $column_name == "post_content" || $column_name == "post_excerpt" || $is_category == true || $column_name == "_tax_status") {
                $all_ids = $variation_parent_id;
                $all_ids .= isset($all_id) && $all_id != '' ? ',' . $all_id : '';
            } else {
                $all_ids = $variation_parent_id;
                // $all_ids .= ( isset($all_id_variation) && $all_id_variation != '' ) ? ',' . $all_id_variation : '';
                $all_ids .= !empty($all_id_variation) ? ',' . implode(",", $all_id_variation) : '';
                // For WP_Debug
                $all_ids .= isset($all_id) && $all_id != '' ? ',' . $all_id : '';
            }
            $all_ids = trim($all_ids, ',');
            $update_column = $actions_updatecolname != '' ? "{$wpdb->_real_escape($actions_updatecolname)}" : "{$wpdb->_real_escape($actions_colname)}";
            $col_filter = "{$wpdb->_real_escape($actions_colfilter)}";
            $drop_down3_value = "{$wpdb->_real_escape($actions[$i]->unit)}";
            //@todo for state code for customers
            $row_filter = '';
            $filter_col = '';
            if ($col_filter != '') {
                $col_filter_arr = explode(':', $col_filter);
                $filter_col = "{$col_filter_arr['0']}";
                $row_filter = $col_filter_arr[1];
            }
            $text_cmp_value = $wpdb->_real_escape($actions[$i]->colValue);
            $selected_ids = implode(',', $ids);
            //Added by Tarun to cater the function to update only for ids passed
        } else {
            $actions[$i][0] = explode(',', $actions[$i][0]);
            $action_index = 0;
            foreach ($actions[$i][0] as $action) {
                // trimming the field names & table names
                $actions[$i][0][$action_index] = trim($actions[$i][0][$action_index]);
                $action_index++;
            }
            // getting values from POST
            $action_name = $wpdb->_real_escape($actions[$i][1]);
            $column_name = $wpdb->_real_escape($actions[$i][0][0]);
            $table_name = $wpdb->_real_escape($actions[$i][0][1]);
            $drop_down3_value = isset($actions[$i][3]) ? $wpdb->_real_escape($actions[$i][3]) : '';
            $selected_ids = $wpdb->_real_escape(implode(',', $ids));
            if ($active_module == 'Customers') {
                //Query for getting the email id and the customer_user for the selected ids
                $query_email = "SELECT DISTINCT(GROUP_CONCAT( meta_value\n                                     ORDER BY meta_id SEPARATOR '###' ) )AS meta_value,\n                                     GROUP_CONCAT(distinct meta_key\n                                     ORDER BY meta_id SEPARATOR '###' ) AS meta_key\n                                     FROM {$wpdb->prefix}postmeta \n                                     WHERE meta_key in ('_billing_email','_customer_user') \n                                        AND post_id IN ({$selected_ids})\n                                     GROUP BY post_id";
                $result_email = $wpdb->get_results($query_email, 'ARRAY_A');
                $email = "";
                $users = "";
                $index = 0;
                $index1 = 0;
                for ($j = 0; $j < sizeof($result_email); $j++) {
                    $meta_key = explode("###", $result_email[$j]['meta_key']);
                    $meta_value = explode("###", $result_email[$j]['meta_value']);
                    $postmeta[$j] = array_combine($meta_key, $meta_value);
                    if ($postmeta[$j]['_customer_user'] == 0) {
                        $email[$index] = $postmeta[$j]['_billing_email'];
                        $index++;
                    } elseif ($postmeta[$j]['_customer_user'] > 0) {
                        $users[$index1] = $postmeta[$j]['_customer_user'];
                        $index1++;
                    }
                    unset($meta_key);
                    unset($meta_value);
                }
                //For Guest Customers
                if ($email != "") {
                    $email = "'" . implode("','", $email) . "'";
                    //Query for getting all the post_ids w.r.to the email id of the edited customer record
                    $query_ids = "SELECT DISTINCT(post_id) FROM {$wpdb->prefix}postmeta WHERE meta_key='_billing_email' AND meta_value IN ({$email})";
                    $id = implode(", ", $wpdb->get_col($query_ids));
                    $selected_ids = $id;
                }
                //For Registered Customers
                if ($users != "") {
                    $users = implode(",", $users);
                }
            }
            $text_cmp_value = '';
            if ($column_name == '_billing_country' || $column_name == '_shipping_country') {
                $region = !empty($actions[$i][4]) ? $wpdb->_real_escape($actions[$i][4]) : $wpdb->_real_escape($actions[$i][2]);
                // For WP_Debug
                $text_cmp_value = $drop_down3_value;
                $state_column = $column_name == '_billing_country' ? '_billing_state' : '_shipping_state';
                $region_query = "UPDATE " . $wpdb->_real_escape($table_name) . " SET meta_value = '" . $wpdb->_real_escape($region) . "' WHERE post_id IN ( " . $wpdb->_real_escape($selected_ids) . " ) AND meta_key = '{$state_column}'";
                $result = $wpdb->query($region_query);
                // if ( $result < 1 ) {
                // 	$updated_rows_cnt = _e('Batch Updation of Region not successful','smart-manager');
                // }
            } else {
                if ($table_name == "`{$wpdb->prefix}term_relationships`" && $actions[$i][4] != '') {
                    $term_id = $terms_name[$actions[$i][4]];
                    $query = "UPDATE `{$wpdb->prefix}term_relationships` SET term_taxonomy_id = {$term_id} \n                                                WHERE object_id IN ( " . $wpdb->_real_escape($selected_ids) . " )";
                    $result = $wpdb->query($query);
                    continue;
                } else {
                    $text_cmp_value = $actions[$i][2] == '' ? $drop_down3_value : $wpdb->_real_escape($actions[$i][2]);
                }
            }
        }
        if ($table_name == "`{$wpdb->prefix}postmeta`" || $table_name == "`{$wpdb->prefix}usermeta`") {
            $update_column = 'meta_value';
            $reference_column = 'meta_key';
        }
        $flag_query = 0;
        //Flag for handling the 'Set To Sales Price' and 'Set To Regular Price' batch update actions
        switch ($action_name) {
            case 'SET_TO':
                if ($table_name == "{$wpdb->prefix}posts" || $table_name == "`{$wpdb->prefix}postmeta`" || $table_name == "`{$wpdb->prefix}usermeta`") {
                    //version 3.8
                    //condition for handling the decimal places
                    if (!empty($text_cmp_value) && ($column_name == '_regular_price' || $column_name == '_sale_price')) {
                        $update_value = $update_column . ' = ROUND(' . $text_cmp_value . ',' . get_option('woocommerce_price_num_decimals') . ')';
                    } else {
                        if (!empty($text_cmp_value)) {
                            $update_value = $update_column . ' = \'' . $text_cmp_value . '\'';
                            //is array for weight
                        } else {
                            $update_value = $update_column . ' = ""';
                        }
                    }
                } else {
                    if ($is_category) {
                        $delete_query = "DELETE FROM " . $table_name . " WHERE `object_id` in (";
                        $insert_query = "INSERT INTO " . $table_name . " (object_id,`" . $update_column . "`) VALUES ";
                        $delete_query .= $selected_ids;
                        $sub_query = array();
                        $category_selected_ids = explode(',', $selected_ids);
                        foreach ($category_selected_ids as $category_selected_id) {
                            $sub_query[] = "(" . $category_selected_id . "," . $text_cmp_value . ")";
                        }
                        $insert_query .= implode(',', $sub_query);
                        $delete_query .= ") AND `term_taxonomy_id` IN ( SELECT term_taxonomy_id FROM {$wpdb->prefix}term_taxonomy WHERE taxonomy = 'product_cat' )";
                        $delete_sql_result = $wpdb->query($delete_query);
                        $insert_sql_result = $wpdb->query($insert_query);
                    }
                }
                break;
            case 'PREPEND':
                if ($table_name == "{$wpdb->prefix}posts" || $table_name == "`{$wpdb->prefix}postmeta`" || $table_name == "`{$wpdb->prefix}usermeta`") {
                    //version 3.8
                    $update_value = $update_column . ' = concat(\'' . $text_cmp_value . '\',' . $update_column . ')';
                }
                break;
            case 'APPEND':
                if ($table_name == "{$wpdb->prefix}posts" || $table_name == "`{$wpdb->prefix}postmeta`" || $table_name == "`{$wpdb->prefix}usermeta`") {
                    //version 3.8
                    $update_value = $update_column . ' = concat(' . $update_column . ',\'' . $text_cmp_value . '\')';
                }
                break;
            case 'INCREASE_BY_NUMBER':
                if ($table_name == "{$wpdb->prefix}postmeta") {
                    //condition for handling the decimal places
                    if (!empty($text_cmp_value) && ($column_name == '_regular_price' || $column_name == '_sale_price')) {
                        $update_value = $update_column . ' = ROUND(' . $update_column . '+' . $text_cmp_value . ',' . get_option('woocommerce_price_num_decimals') . ')';
                    } else {
                        if (!empty($text_cmp_value)) {
                            $update_value = $update_column . ' = ' . $update_column . '+' . $text_cmp_value;
                        } else {
                            $text_cmp_value = "0";
                            $update_value = $update_column . ' = ' . $update_column . '+' . $text_cmp_value;
                        }
                    }
                }
                break;
            case 'DECREASE_BY_NUMBER':
                if ($table_name == "{$wpdb->prefix}postmeta") {
                    //condition for handling the decimal places
                    if (!empty($text_cmp_value) && ($column_name == '_regular_price' || $column_name == '_sale_price')) {
                        $update_value = $update_column . ' = ROUND(' . $update_column . '-' . $text_cmp_value . ',' . get_option('woocommerce_price_num_decimals') . ')';
                    } else {
                        if (!empty($text_cmp_value)) {
                            $update_value = $update_column . ' = ' . $update_column . '-' . $text_cmp_value;
                        } else {
                            $text_cmp_value = "0";
                            $update_value = $update_column . ' = ' . $update_column . '-' . $text_cmp_value;
                        }
                    }
                }
                break;
            case 'INCREASE_BY_%':
                if ($table_name == "{$wpdb->prefix}postmeta") {
                    //condition for handling the decimal places
                    if (!empty($text_cmp_value) && ($column_name == '_regular_price' || $column_name == '_sale_price')) {
                        $update_value = $update_column . ' = ROUND(' . $update_column . '+' . ($update_column . '*' . $text_cmp_value / 100) . ',' . get_option('woocommerce_price_num_decimals') . ')';
                    } else {
                        if (!empty($text_cmp_value)) {
                            $update_value = $update_column . ' =' . $update_column . '+' . ($update_column . '*' . $text_cmp_value / 100);
                        } else {
                            $update_value = $update_column . ' =' . $update_column;
                        }
                    }
                }
                break;
            case 'DECREASE_BY_%':
                if ($table_name == "{$wpdb->prefix}postmeta") {
                    //condition for handling the decimal places
                    if (!empty($text_cmp_value) && ($column_name == '_regular_price' || $column_name == '_sale_price')) {
                        $update_value = $update_column . ' = ROUND(' . $update_column . '-' . ($update_column . '*' . $text_cmp_value / 100) . ',' . get_option('woocommerce_price_num_decimals') . ')';
                    } else {
                        if (!empty($text_cmp_value)) {
                            $update_value = $update_column . ' =' . $update_column . '-' . ($update_column . '*' . $text_cmp_value / 100);
                        } else {
                            $update_value = $update_column . ' =' . $update_column;
                        }
                    }
                }
                break;
            case 'YES':
                if ($column_name == 'post_status') {
                    $update_value = $update_column . ' = \'publish\'';
                } elseif ($column_name == '_stock') {
                    $update_value = $update_column . ' = 0';
                } else {
                    $update_value = $update_column . ' = 1';
                }
                break;
            case 'NO':
                if ($column_name == 'post_status') {
                    $update_value = $update_column . ' = \'draft\'';
                } elseif ($column_name == '_stock') {
                    $update_value = $update_column . ' = ""';
                } else {
                    $update_value = $update_column . ' = 0';
                }
                break;
            case 'ADD_TO':
                $sub_query = array();
                if (!$is_category) {
                    // Need to be reworked
                    for ($j = 0; $j < count($ids); $j++) {
                        $sub_query[] = "( " . $wpdb->_real_escape($ids[$j]) . "," . $text_cmp_value . ")";
                    }
                    $sub_query = implode(',', $sub_query);
                    $query = "INSERT INTO " . $table_name . " (object_id,`" . $update_column . "`) VALUES " . $sub_query;
                    $sql_result = $wpdb->query($query);
                } else {
                    $delete_query = "DELETE FROM " . $table_name . " WHERE `object_id` in (";
                    $insert_query = "INSERT INTO " . $table_name . " (`object_id`,`" . $update_column . "`) VALUES ";
                    $delete_query .= $selected_ids;
                    $sub_query = array();
                    $category_selected_ids = explode(',', $selected_ids);
                    foreach ($category_selected_ids as $category_selected_id) {
                        $sub_query[] = "(" . $category_selected_id . "," . $text_cmp_value . ")";
                    }
                    $insert_query .= implode(',', $sub_query);
                    $delete_query .= ") AND `term_taxonomy_id`=" . $text_cmp_value;
                    $delete_sql_result = $wpdb->query($delete_query);
                    $insert_sql_result = $wpdb->query($insert_query);
                }
                break;
            case 'REMOVE_FROM':
                if (!$is_category) {
                    // Need to be reworked
                    $query = "DELETE FROM " . $table_name . " WHERE object_id in (" . $wpdb->_real_escape(implode(',', $ids)) . ")\n\t\t\t\t\t\t              AND `" . $update_column . "` = " . $text_cmp_value;
                    $sql_result = $wpdb->query($query);
                } else {
                    $delete_query = "DELETE FROM " . $table_name . " WHERE `object_id` in (";
                    $delete_query .= $selected_ids;
                    $delete_query .= ") AND `term_taxonomy_id` = {$text_cmp_value}";
                    $delete_sql_result = $wpdb->query($delete_query);
                }
                break;
            case 'CATALOG & SEARCH':
                if ($table_name == "{$wpdb->prefix}postmeta") {
                    $update_value = $update_column . ' = \'visible\'';
                }
                break;
            case 'CATALOG':
                if ($table_name == "{$wpdb->prefix}postmeta") {
                    $update_value = $update_column . ' = \'catalog\'';
                }
                break;
            case 'SEARCH':
                if ($table_name == "{$wpdb->prefix}postmeta") {
                    $update_value = $update_column . ' = \'search\'';
                }
                break;
            case 'HIDDEN':
                if ($table_name == "{$wpdb->prefix}postmeta") {
                    $update_value = $update_column . ' = \'hidden\'';
                }
                break;
            case 'SET_TO_SALES_PRICE':
                for ($j = 0; $j < sizeof($ids); $j++) {
                    $type = wp_get_object_terms($ids[$j], 'product_type', array('fields' => 'slugs'));
                    $query = "SELECT post_parent FROM `{$wpdb->prefix}posts` WHERE ID =" . $ids[$j];
                    $result_parent = $wpdb->get_col($query);
                    if (!empty($result_parent)) {
                        $product_type_parent = wp_get_object_terms($result_parent, 'product_type', array('fields' => 'slugs'));
                    }
                    if ($type[0] == 'simple' && $result_parent[0] == 0 || $product_type_parent[0] == "grouped" || $_POST['SM_IS_WOO16'] == "false") {
                        $flag_success = 1;
                        $query = "SELECT meta_value FROM `{$wpdb->prefix}postmeta`\n                                            WHERE meta_key = '_sale_price' AND post_id = " . $ids[$j];
                        $result = $wpdb->get_col($query);
                        $result[0] = trim($result[0]);
                        // For handling when both price and sales price are null
                        if (!empty($result[0])) {
                            $query = "UPDATE `{$wpdb->prefix}postmeta` SET meta_value = ROUND(" . $result[0] . ',' . get_option('woocommerce_price_num_decimals') . ')' . " WHERE meta_key = '_regular_price' AND post_id = " . $ids[$j];
                        } else {
                            $query = "UPDATE `{$wpdb->prefix}postmeta` SET meta_value = '' WHERE meta_key = '_regular_price' AND post_id = " . $ids[$j];
                        }
                        $result1 = $wpdb->query($query);
                    } else {
                        if ($result_parent[0] > 0 && $_POST['SM_IS_WOO16'] == "true") {
                            $flag_success = 1;
                            $query = "SELECT meta_value FROM `{$wpdb->prefix}postmeta`\n                                            WHERE meta_key = '_sale_price' AND post_id = " . $ids[$j];
                            $result = $wpdb->get_col($query);
                            $result[0] = trim($result[0]);
                            // For handling when both price and sales price are null
                            if (!empty($result[0])) {
                                $query = "UPDATE `{$wpdb->prefix}postmeta` SET meta_value = ROUND(" . $result[0] . ',' . get_option('woocommerce_price_num_decimals') . ')' . " WHERE meta_key = '_price' AND post_id = " . $ids[$j];
                            } else {
                                $query = "UPDATE `{$wpdb->prefix}postmeta` SET meta_value = '' WHERE meta_key = '_price' AND post_id = " . $ids[$j];
                            }
                            $result1 = $wpdb->query($query);
                        }
                    }
                }
                $flag_query = 1;
                break;
            case 'SET_TO_REGULAR_PRICE':
                for ($j = 0; $j < sizeof($ids); $j++) {
                    $type = wp_get_object_terms($ids[$j], 'product_type', array('fields' => 'slugs'));
                    $query = "SELECT post_parent FROM `{$wpdb->prefix}posts` WHERE ID =" . $ids[$j];
                    $result_parent = $wpdb->get_col($query);
                    if (!empty($result_parent)) {
                        $product_type_parent = wp_get_object_terms($result_parent, 'product_type', array('fields' => 'slugs'));
                    }
                    if ($type[0] == 'simple' && $result_parent[0] == 0 || $product_type_parent[0] == "grouped" || $_POST['SM_IS_WOO16'] == "false") {
                        $query = "SELECT meta_value FROM `{$wpdb->prefix}postmeta`\n                                            WHERE meta_key = '_regular_price' AND post_id = " . $ids[$j];
                        $result = $wpdb->get_col($query);
                        $result[0] = trim($result[0]);
                        // For handling when both price and sales price are null
                        if (!empty($result[0])) {
                            $query = "UPDATE `{$wpdb->prefix}postmeta` SET meta_value = ROUND(" . $result[0] . ',' . get_option('woocommerce_price_num_decimals') . ')' . " WHERE meta_key = '_sale_price' AND post_id = " . $ids[$j];
                        } else {
                            $query = "UPDATE `{$wpdb->prefix}postmeta` SET meta_value = '' WHERE meta_key = '_sale_price' AND post_id = " . $ids[$j];
                        }
                        $result1 = $wpdb->query($query);
                    } else {
                        if ($result_parent[0] > 0 && $_POST['SM_IS_WOO16'] == "true") {
                            $query = "SELECT meta_value FROM `{$wpdb->prefix}postmeta`\n                                            WHERE meta_key = '_price' AND post_id = " . $ids[$j];
                            $result = $wpdb->get_col($query);
                            $result[0] = trim($result[0]);
                            // For handling when both price and sales price are null
                            if (!empty($result[0])) {
                                $query = "UPDATE `{$wpdb->prefix}postmeta` SET meta_value = ROUND(" . $result[0] . ',' . get_option('woocommerce_price_num_decimals') . ')' . " WHERE meta_key = '_sale_price' AND post_id = " . $ids[$j];
                            } else {
                                $query = "UPDATE `{$wpdb->prefix}postmeta` SET meta_value = '' WHERE meta_key = '_sale_price' AND post_id = " . $ids[$j];
                            }
                            $result1 = $wpdb->query($query);
                        }
                    }
                }
                $flag_query = 1;
                break;
        }
        if ($table_name != "`{$wpdb->prefix}term_relationships`") {
            if ($flag_query == 0) {
                if (is_array($update_value)) {
                    $update_value = implode(',', $update_value);
                }
                $update_price_meta = false;
                $query = "UPDATE " . $table_name . " SET " . $update_value;
                if ($table_name == "{$wpdb->prefix}posts") {
                    if ($active_module == 'Products' && $update_column == 'post_status') {
                        $query .= " WHERE `post_type` IN ('product') AND `ID` in (" . $selected_ids . ")";
                    } else {
                        $query .= ' WHERE `ID` in (' . $selected_ids . ')';
                    }
                } else {
                    if ($table_name == "`{$wpdb->prefix}postmeta`") {
                        if ($column_name == '_regular_price') {
                            //Query for updating the price for the simple products
                            if (!empty($product_type)) {
                                sm_insert_metakey($product_type, '_regular_price');
                                // Code for inserting the meta_key if not present
                                $query_simple = $query;
                                $query_simple = $query_simple . " WHERE meta_key LIKE '_regular_price' AND post_id IN ({$product_type})";
                                $result = $wpdb->query($query_simple);
                                if (empty($price_variation)) {
                                    $query = "";
                                }
                            }
                            //                                                    $query = "INSERT INTO ". $table_name . "VALUES"
                            //Query for updating the price for the grouped products
                            if (!empty($product_type_grouped)) {
                                sm_insert_metakey($product_type_grouped, '_regular_price');
                                // Code for inserting the meta_key if not present
                                $query_grouped = $query;
                                $query_grouped = $query_grouped . " WHERE meta_key LIKE '_regular_price' AND post_id IN ({$product_type_grouped})";
                                $result_grouped = $wpdb->query($query_grouped);
                                if (empty($price_variation)) {
                                    $query = "";
                                }
                            }
                            //                                                    $query .= " WHERE meta_key LIKE '_price' AND post_id IN (" . $selected_ids . ")";
                            //Woo 2.0 Compatibility check
                            if ($_POST['SM_IS_WOO16'] == "true") {
                                if (!empty($price_variation)) {
                                    sm_insert_metakey($price_variation, '_price');
                                    // Code for inserting the meta_key if not present
                                    $query .= " WHERE meta_key LIKE '_price' AND post_id IN ({$price_variation})";
                                } else {
                                    $query = "";
                                }
                            } else {
                                if (!empty($price_variation)) {
                                    sm_insert_metakey($price_variation, '_regular_price');
                                    // Code for inserting the meta_key if not present
                                    $query .= " WHERE meta_key LIKE '_regular_price' AND post_id IN ({$price_variation})";
                                } else {
                                    $query = "";
                                }
                            }
                        } else {
                            if (!empty($selected_ids)) {
                                sm_insert_metakey($selected_ids, $column_name);
                                // Code for inserting the meta_key if not present
                                $query .= " WHERE `post_id` in (" . $selected_ids . ") AND meta_key = '" . $column_name . "'";
                            }
                        }
                    }
                }
                if (!empty($query) && $flag_query == 0) {
                    $result = $wpdb->query($query);
                }
            }
            // Code for Updating the '_price' for All Products
            if ($column_name == '_regular_price' || $column_name == '_sale_price') {
                $simple_ids = explode(",", $product_type);
                $grouped_ids = explode(",", $product_type_grouped);
                $variation_ids = explode(",", $price_variation);
                if (!empty($product_type) && !empty($product_type_grouped)) {
                    $final_ids = array_merge($simple_ids, $grouped_ids);
                } else {
                    if (!empty($product_type)) {
                        $final_ids = $simple_ids;
                    } else {
                        $final_ids = $grouped_ids;
                    }
                }
                if (!empty($price_variation) && $_POST['SM_IS_WOO16'] == "false") {
                    if (!empty($final_ids)) {
                        $final_ids = array_merge($final_ids, $variation_ids);
                    } else {
                        $final_ids = $variation_ids;
                    }
                }
                update_price_meta(implode(",", array_filter($final_ids)));
                // For Updating Variable Parent Price
                if (!empty($price_variation)) {
                    variable_price_sync($variation_ids);
                }
            }
            //Condition for handling the Batch Update for the registered Customers
            if ($active_module == 'Customers' && $users != "") {
                $table_name = "`{$wpdb->prefix}usermeta`";
                $column_name = substr($column_name, 1);
                $user_ids = $users;
                if ($column_name == 'billing_email') {
                    $update_column = 'user_email';
                    switch ($action_name) {
                        case 'SET_TO':
                            $user_value = $update_column . ' = \'' . $text_cmp_value . '\'';
                            break;
                        case 'PREPEND':
                            $user_value = $update_column . ' = concat(\'' . $text_cmp_value . '\',' . $update_column . ')';
                            break;
                        case 'APPEND':
                            $user_value = $update_column . ' = concat(' . $update_column . ',\'' . $text_cmp_value . '\')';
                            break;
                    }
                    $query_users = "UPDATE `{$wpdb->prefix}users` SET " . $user_value . "WHERE `id` in (" . $user_ids . ")";
                    $result_users = $wpdb->query($query_users);
                }
                if ($column_name == 'billing_country') {
                    $region = !empty($actions[$i][4]) ? $wpdb->_real_escape($actions[$i][4]) : $wpdb->_real_escape($actions[$i][2]);
                    $region_query = "UPDATE " . $wpdb->_real_escape($table_name) . " SET meta_value = '" . $wpdb->_real_escape($region) . "' WHERE user_id IN ( " . $wpdb->_real_escape($user_ids) . " ) AND meta_key = 'billing_state'";
                    $result = $wpdb->query($region_query);
                    if ($result < 1) {
                        $updated_rows_cnt = _e('Batch Updation of Region not successful', 'smart-manager');
                    }
                }
                $query = "UPDATE " . $table_name . " SET " . $update_value . "WHERE `user_id` in (" . $user_ids . ") AND meta_key = '" . $column_name . "'";
                $result = $wpdb->query($query);
            }
        } elseif ($table_name == "`{$wpdb->prefix}term_relationships`") {
            if ($active_module != 'Products') {
                $term_taxonomy_id = get_term_taxonomy_id($text_cmp_value);
                $query = "UPDATE " . $table_name . " SET term_taxonomy_id = " . $wpdb->_real_escape($term_taxonomy_id) . " WHERE object_id IN (" . $selected_ids . ") ";
                $result = $wpdb->query($query);
                $order_ids = explode(',', $selected_ids);
                if ($text_cmp_value == 'processing' || $text_cmp_value == 'completed') {
                    foreach ($order_ids as $order_id) {
                        $order = new WC_Order($wpdb->_real_escape($order_id));
                        $order->update_status($text_cmp_value);
                    }
                }
            }
        }
        $update_value = '';
    }
    // Handled with a different ajax request
    if ($radioData == 2 && $flag == 1) {
        $updated_rows_cnt = 'All';
    } else {
        $updated_rows_cnt = $idLength;
    }
    //Clearing the transients to handle the proper functioning of the widgets
    $woocommerce->clear_product_transients();
    return $updated_rows_cnt;
}