$item ) : if ( ( ( 'woocommerce' ) == $item ) ) : $woocommerce_menu_order[] = 'separator-woocommerce'; unset( $menu_order[$woocommerce_separator] ); endif; if ( !in_array( $item, array( 'separator-woocommerce' ) ) ) : $woocommerce_menu_order[] = $item; endif; endforeach; // Return order return $woocommerce_menu_order; } function woocommerce_admin_custom_menu_order() { if ( !current_user_can( 'manage_options' ) ) return false; return true; } add_action('admin_menu', 'woocommerce_admin_menu', 9); add_action('menu_order', 'woocommerce_admin_menu_order'); add_action('custom_menu_order', 'woocommerce_admin_custom_menu_order'); /** * Admin Head * * Outputs some styles in the admin
to show icons on the woocommerce admin pages */ function woocommerce_admin_head() { ?> post_type !== 'product') die; $product = new woocommerce_product($post->ID); if ($product->is_featured()) update_post_meta($post->ID, 'featured', 'no'); else update_post_meta($post->ID, 'featured', 'yes'); $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), wp_get_referer() ); wp_safe_redirect( $sendback ); } add_action('wp_ajax_woocommerce-feature-product', 'woocommerce_feature_product'); /** * Returns proper post_type */ function woocommerce_get_current_post_type() { global $post, $typenow, $current_screen; if( $current_screen && @$current_screen->post_type ) return $current_screen->post_type; if( $typenow ) return $typenow; if( !empty($_REQUEST['post_type']) ) return sanitize_key( $_REQUEST['post_type'] ); if ( !empty($post) && !empty($post->post_type) ) return $post->post_type; if( ! empty($_REQUEST['post']) && (int)$_REQUEST['post'] ) { $p = get_post( $_REQUEST['post'] ); return $p ? $p->post_type : ''; } return ''; } /** * Categories ordering scripts */ function woocommerce_categories_scripts () { if( !isset($_GET['taxonomy']) || $_GET['taxonomy'] !== 'product_cat') return; wp_register_script('woocommerce-categories-ordering', woocommerce::plugin_url() . '/assets/js/categories-ordering.js', array('jquery-ui-sortable')); wp_print_scripts('woocommerce-categories-ordering'); } add_action('admin_footer-edit-tags.php', 'woocommerce_categories_scripts'); /** * Ajax request handling for categories ordering */ function woocommerce_categories_ordering() { global $wpdb; $id = (int)$_POST['id']; $next_id = isset($_POST['nextid']) && (int) $_POST['nextid'] ? (int) $_POST['nextid'] : null; if( ! $id || ! $term = get_term_by('id', $id, 'product_cat') ) die(0); woocommerce_order_categories( $term, $next_id ); $children = get_terms('product_cat', "child_of=$id&menu_order=ASC&hide_empty=0"); if( $term && sizeof($children) ) { echo 'children'; die; } } add_action('wp_ajax_woocommerce-categories-ordering', 'woocommerce_categories_ordering'); /** * Search by SKU ro ID for products. Adapted from code by BenIrvin (Admin Search by ID) */ if (is_admin()) : add_action('parse_request', 'woocommerce_admin_product_search'); add_filter( 'get_search_query', 'woocommerce_admin_id_search_label' ); endif; function woocommerce_admin_product_search( $wp ) { global $pagenow, $wpdb; if( 'edit.php' != $pagenow ) return; if( !isset( $wp->query_vars['s'] ) ) return; if ($wp->query_vars['post_type']!='product') return; if( '#' == substr( $wp->query_vars['s'], 0, 1 ) ) : $id = absint( substr( $wp->query_vars['s'], 1 ) ); if( !$id ) return; unset( $wp->query_vars['s'] ); $wp->query_vars['p'] = $id; elseif( 'SKU:' == substr( $wp->query_vars['s'], 0, 4 ) ) : $sku = trim( substr( $wp->query_vars['s'], 4 ) ); if( !$sku ) return; $id = $wpdb->get_var('SELECT post_id FROM '.$wpdb->postmeta.' WHERE meta_key="sku" AND meta_value LIKE "%'.$sku.'%";'); if( !$id ) return; unset( $wp->query_vars['s'] ); $wp->query_vars['p'] = $id; $wp->query_vars['sku'] = $sku; endif; } function woocommerce_admin_id_search_label($query) { global $pagenow; if( 'edit.php' != $pagenow ) return; $s = get_query_var( 's' ); if($s) return $query; $sku = get_query_var( 'sku' ); if($sku) { global $wp; $post_type = get_post_type_object($wp->query_vars['post_type']); return sprintf(__("[%s with SKU of %s]", 'woothemes'), $post_type->labels->singular_name, $sku); } $p = get_query_var( 'p' ); if($p) { global $wp; $post_type = get_post_type_object($wp->query_vars['post_type']); return sprintf(__("[%s with ID of %d]", 'woothemes'), $post_type->labels->singular_name, $p); } return $query; } add_filter('query_vars', 'woocommerce_add_sku_var'); function woocommerce_add_sku_var($public_query_vars) { $public_query_vars[] = 'sku'; return $public_query_vars; }