Želite li opciju filtiranja izdvojenih (featured) proizvoda u Woo administraciji, možete u functions.php datoteku dodati sljedeći kod:

/* Filter featured products in admin */
 
function mx_featured_dropdown( $output ) {
   
  global $typenow, $wp_query;

    if ($typenow=='product') :

        $output .= "<select name='featured_status' id='featured_filter_dropdow'>";
        $output .= '<option value="">'.__( 'Svi statusi', 'woocommerce' ).'</option>';

        $output .="<option value='featured' ";
        if ( isset( $_GET['featured_status'] ) ) $output .= selected('featured', $_GET['featured_status'], false);
        $output .=">".__( 'Izdvojeno', 'woocommerce' )."</option>";

        $output .="<option value='normal' ";
        if ( isset( $_GET['featured_status'] ) ) $output .= selected('normal', $_GET['featured_status'], false);
        $output .=">".__( 'Normalno', 'woocommerce' )."</option>";

        $output .="</select>";

    endif;
   
  return $output;
}
add_filter( 'woocommerce_product_filters', 'mx_featured_dropdown' );

function mx_featured_products_query( $query ) {
	
    global $typenow;

    if ( $typenow == 'product' ) {

        if ( ! empty( $_GET['featured_status'] ) ) {
            if ( $_GET['featured_status'] == 'featured' ) {
                $query->query_vars['tax_query'][] = array(
                    'taxonomy' => 'product_visibility',
                    'field'    => 'slug',
                    'terms'    => 'featured',
                );
            } elseif ( $_GET['featured_status'] == 'normal' ) {
                $query->query_vars['tax_query'][] = array(
                    'taxonomy' => 'product_visibility',
                    'field'    => 'slug',
                    'terms'    => 'featured',
                    'operator' => 'NOT IN',
                );
            }
        }

    }

}
add_filter( 'parse_query', 'mx_featured_products_query' );

Odgovori

Vaša email adresa neće biti objavljena. Obavezna polja su označena s *

Post comment