function wooc_apto_order_update_hierarchical($data)
{
    global $wpdb, $blog_id;
    $sort_view_id = $data['sort_view_id'];
    $sort_view_settings = APTO_functions::get_sort_view_settings($sort_view_id);
    $sort_view_data = get_post($sort_view_id);
    $sortID = $sort_view_data->post_parent;
    //return if not woocommerce
    if (APTO_functions::is_woocommerce($sortID) === FALSE) {
        return;
    }
    // Clear product specific transients
    $post_transients_to_clear = array('wc_product_children_ids_', 'wc_product_children_');
    foreach ($post_transients_to_clear as $transient) {
        delete_transient($transient . $data['post_id']);
        $wpdb->query($wpdb->prepare("DELETE FROM `{$wpdb->options}` WHERE `option_name` = %s OR `option_name` = %s", '_transient_' . $transient . $data['post_id'], '_transient_timeout_' . $transient . $data['post_id']));
    }
    clean_post_cache($data['post_id']);
}
 function nottice_similar_sorts($interface)
 {
     if ($interface->sortID == '' || $interface->current_sort_view_ID == '') {
         return;
     }
     //check if autsort Yes, oterwise we don't care about similar sorts.
     if ($interface->sort_settings['_autosort'] != 'yes') {
         return;
     }
     $apto_system_nottices = array();
     //get all sorts
     $args = array('post_type' => 'apto_sort', 'post_parent' => 0, 'orderby' => 'ID', 'order' => 'ASC', 'posts_per_page' => -1, 'post__not_in' => array($interface->sortID), 'ignore_custom_sort' => TRUE);
     $custom_query = new WP_Query($args);
     if ($custom_query->have_posts()) {
         global $post;
         $_wp_query_post = $post;
         while ($custom_query->have_posts()) {
             $custom_query->the_post();
             $found_similar = TRUE;
             $sort_settings = APTO_functions::get_sort_settings($post->ID);
             //check if autosort is turned on
             if ($sort_settings['_autosort'] != 'yes') {
                 continue;
             }
             //check if same post types rules
             if (count($interface->sort_settings['_rules']['post_type']) != count($sort_settings['_rules']['post_type']) || count(array_diff($interface->sort_settings['_rules']['post_type'], $sort_settings['_rules']['post_type'])) > 0) {
                 continue;
             }
             //check if same taxonomy settings
             if ($interface->sort_settings['_rules']['taxonomy_relation'] != $sort_settings['_rules']['taxonomy_relation'] || count($interface->sort_settings['_rules']['taxonomy']) != count($sort_settings['_rules']['taxonomy']) || $this->taxonomy_settings_diff_exist($interface->sort_settings['_rules']['taxonomy'], $sort_settings['_rules']['taxonomy']) === TRUE) {
                 continue;
             }
             //check if same author rules
             if (count($interface->sort_settings['_rules']['author']) != count($sort_settings['_rules']['author']) || count(array_diff($interface->sort_settings['_rules']['author'], $sort_settings['_rules']['author'])) > 0) {
                 continue;
             }
             //check for same conditionals
             if (count($interface->sort_settings['_conditionals']) != count($sort_settings['_conditionals']) || $this->conditional_settings_diff_exist($interface->sort_settings['_conditionals'], $sort_settings['_conditionals']) === TRUE) {
                 continue;
             }
             if ($found_similar === TRUE) {
                 $link_argv = array('sort_id' => $post->ID);
                 $link_argv['page'] = 'apto_' . sanitize_title($sort_settings['_location']);
                 $link_argv['base_url'] = admin_url($sort_settings['_location']);
                 $url = APTO_interface_helper::get_item_link($link_argv);
                 $message = __("Notice: There is", 'apto') . ' <b><a href="' . $url . '">' . __("another", 'apto') . '</a></b> ' . __("similar sort", 'apto');
                 if ($post->ID < $interface->sortID) {
                     $message .= ' which will be used instead.';
                 } else {
                     $message .= ', however current list will be used.';
                 }
                 $apto_system_nottices[] = $message;
             }
         }
         //wp_reset_postdata();
         //use this instead as using a setup_postdata() without any query will reset to nothing
         $post = $_wp_query_post;
     }
     if (count($apto_system_nottices) > 0) {
         echo "<div id='notice' class='updated fade'><p>" . implode("</p><p>", $apto_system_nottices) . "</p></div>";
     }
 }
 /**
  * Add _view_language to taxonomy view selection to allow WPML untranslated taxonomies to be sorted for different languages
  *     
  */
 static function update_V3_5_4()
 {
     global $wpdb;
     if (defined('ICL_LANGUAGE_CODE') && defined('ICL_SITEPRESS_VERSION')) {
         global $sitepress;
         $default_language = $sitepress->get_default_language();
     } else {
         $default_language = APTO_functions::get_blog_language();
     }
     $mysql_query = "SELECT ID FROM " . $wpdb->posts . " AS pt\n                                        JOIN " . $wpdb->postmeta . " AS pm ON pm.post_id = pt.ID\n                                        WHERE pt.post_type = 'apto_sort' AND pm.meta_key = '_view_selection' AND pm.meta_Value = 'taxonomy'";
     $results = $wpdb->get_results($mysql_query);
     foreach ($results as $result) {
         $sort_view_id = $result->ID;
         $_view_language = get_post_meta($sort_view_id, '_view_language', TRUE);
         if (!empty($_view_language)) {
             continue;
         }
         $_taxonomy = get_post_meta($sort_view_id, '_taxonomy', TRUE);
         $_term_id = get_post_meta($sort_view_id, '_term_id', TRUE);
         //check if WPML is active
         if (defined('ICL_LANGUAGE_CODE') && defined('ICL_SITEPRESS_VERSION')) {
             $_language_details = $sitepress->get_element_language_details($_term_id, 'tax_' . $_taxonomy);
             if (!is_object($_language_details) || empty($_language_details->language_code)) {
                 $language_term_is = $default_language;
             } else {
                 $language_term_is = $_language_details->language_code;
             }
         } else {
             $language_term_is = $default_language;
         }
         update_post_meta($sort_view_id, '_view_language', $language_term_is);
     }
 }