Support » Plugin: WooCommerce Extra Product Sorting Options » possible sort on sale variable

  • Resolved stvnzion

    (@stvnzion)


    great plugin…. is this possible i saw this code if i insert this would sort on sale variable

    add_filter( ‘pre_get_posts’, ‘catalog_filters’ );
    function catalog_filters( $query ) {
    if ( $query->is_main_query() && $query->post_type = ‘product’ ) {
    if(isset($_GET[‘onsale’])) {
    $meta_query = array(
    ‘relation’ => ‘OR’,
    array( // Simple products type
    ‘key’ => ‘_sale_price’,
    ‘value’ => 0,
    ‘compare’ => ‘>’,
    ‘type’ => ‘numeric’
    ),
    array( // Variable products type
    ‘key’ => ‘_min_variation_sale_price’,
    ‘value’ => 0,
    ‘compare’ => ‘>’,
    ‘type’ => ‘numeric’
    )
    ); $query->set(‘meta_query’, $meta_query); d($query);
    }
    if(isset($_GET[‘bestsellers’])) {
    $meta_query = array(
    array(
    ‘key’ => ‘total_sales’,
    ‘value’ => 0,
    ‘compare’ => ‘>’,
    ‘type’ => ‘numeric’
    )
    );
    }
    }

    return $query;
    }

    • This topic was modified 4 years, 8 months ago by stvnzion.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter stvnzion

    (@stvnzion)

    c

    • This reply was modified 4 years, 8 months ago by stvnzion.
    Thread Starter stvnzion

    (@stvnzion)

    : )

    • This reply was modified 4 years, 8 months ago by stvnzion. Reason: there was an option to edit on top
    Plugin Author SkyVerge

    (@skyverge)

    Hey @stvnzion, at first glance I don’t seen any issues with that snippet, but I’m afraid it’s not something we plan to include in this plugin, as we’re using the pre-built query object from WooCommerce for this plugin, so that sort of meta key comparison isn’t possible.

    Sorry I don’t have better news for you here!

    Cheers, Beka

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘possible sort on sale variable’ is closed to new replies.