Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter jahau1234

    (@jahau1234)

    Actually when checking the query mentioned in the link, it doesn’t work at all. It filters out everything, no matter what is the sale from/to date. Any ideas how to fix? Thanks.

    Thread Starter jahau1234

    (@jahau1234)

    Any ideas?

    Are you using the first block of code or the second?

    D Smith a11n

    (@dsmithweb)

    Automattic Happiness Engineer

    Hi @jahau1234!

    Since we haven’t heard anything from you in a while, I’m going to mark this thread as resolved. However, if you need any further assistance with this issue, please let us know. Thanks!

    Thread Starter jahau1234

    (@jahau1234)

    The code is this one. Does this work / is it supposed to work? Thank you very much!

    function custom_meta_query( $meta_query ){
    $today = current_time('Ymd');
     $args = array (
        'numberposts' => -1,
        'meta_query' => array(
        'relation' => 'AND',
        'start_clause' => array(
            'key'=>'flash_sale_start',
            'value' => $today,
            'compare'=> '<=',
         'type' => 'DATE'
        ),
             'end_clause' => array(
             'key' => 'flash_sale_end',
         'value' => $today,
             'compare' => '>=',
         'type' => 'DATE'
         ),
           ));
    
    return $args;
    }
    
    // The main shop and archives meta query
    add_filter( 'woocommerce_product_query_meta_query', 'custom_product_query_meta_query', 10, 2 );
    function custom_product_query_meta_query( $meta_query, $query ) {
        if( ! is_admin() )
            return custom_meta_query( $meta_query );
    }
    
    // The shortcode products query
    add_filter( 'woocommerce_shortcode_products_query', 'custom__shortcode_products_query', 10, 3 );
    function custom__shortcode_products_query( $query_args, $atts, $loop_name ) {
        if( ! is_admin() )
            $query_args['meta_query'] = custom_meta_query( $query_args['meta_query'] );
        return $query_args;
    }
    
    // The widget products query
    add_filter( 'woocommerce_products_widget_query_args', 'custom_products_widget_query_arg', 10, 1 );
    function custom_products_widget_query_arg( $query_args ) {
        if( ! is_admin() )
            $query_args['meta_query'] = custom_meta_query( $query_args['meta_query'] );
        return $query_args;
    }
    Thread Starter jahau1234

    (@jahau1234)

    Anyone, please?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘WooCommerce: display only products between two dates when defined’ is closed to new replies.