WooCommerce Fix Featured Wordpress Plugin - Rating, Reviews, Demo & Download

WooCommerce Fix Featured Preview Wordpress Plugin - Rating, Reviews, Demo & Download
No ratings yet
Free
Follow for free plugins, new theme releases and theme news

Plugin Description

Remember when you could sort product by their featured status? WooCommerce Fix Featured makes that possible again.

WooCommerce Fix Featured restores the _featured meta data. This allows you to:
* Sort the list of products by featured in the admin panel like you were able to before WC 3.1
* Use the meta data in your plugin or code snippet to sort the products displayed on the front-end by featured

Once the plugin is activated, it will process all of the products and add the _featured meta data to the wp_post_meta table. It will keep this information up-to-date while it is activated. If it is deactivated and later reactivated, it will process all of the products again if a new product was added after deactivation.

Sort Products on the Front End By Featured

To sort products on the front end by featured, add the following code snippet to your functions.php file or, my preference, Code Snippets:

if( !is_admin )
  add_action( 'pre_get_posts', 'ltz_pre_get_posts', 999 );

function ltz_pre_get_posts( $query ) {
  if(
    !empty($query->query_vars[ 'wc_query' ]) &&
    $query->query_vars[ 'wc_query' ] == 'product_query'  &&
    $query->query_vars[ 'orderby' ] == 'menu_order title'
  ) {
    $query->set('meta_query',
    [
     'relation' => 'AND',
     'featured' =>
     [
       'key' => 'featured'
     ],
     /*
     'total_sales' =>
     [
       'key' => 'total_sales'
     ]
     */
    ]);

    $query->set('orderby',
      [
      'featured' => 'DESC',
      //'total_sales' => 'DESC',
      'menu-order' => 'ASC',
      'title' => 'ASC',
      ]);
  }

  return $query;
}

Screenshots


Reviews & Comments