Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1468987

    Hi all,
    I need to order posts in the Woocommerce Slider integrated in Enfold by a custom meta, which happens a date.
    I am not sure I understand the filter capability, but I tried the short plugin below, with no effect. The custom ordering is not appearing in the dropdown menu. I am overiding the priority of Enfold ordering by a priority, but I would be more than happy to use more elegant solution if possible, and this does not work anyway…

    <?php
    
    // Add custom sorting option to Enfold's sorting dropdown
    add_filter( 'avf_wc_product_order_dropdown_frontend', 'add_custom_sorting_option' );
    
    function add_custom_sorting_option( $product_order ) {
        $product_order['course_date'] = __( 'Sort by course date', 'woocommerce-course-date-sorting' );
        return $product_order;
    }
    
    // Modify the ordering arguments after Enfold's modifications
    add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_catalog_ordering_args', 30 );
    
    function custom_catalog_ordering_args( $args ) {
        if ( isset( $_GET['product_order'] ) && 'course_date' === $_GET['product_order'] ) {
            $order = isset( $_GET['product_sort'] ) ? strtoupper( $_GET['product_sort'] ) : 'ASC';
            $args['orderby'] = 'meta_value';
            $args['order'] = $order;
            $args['meta_key'] = '_course_date';
            $args['meta_type'] = 'DATE';
        }
        return $args;
    }
    
    // Modify the product query to include only products with '_course_date' meta key
    add_action( 'woocommerce_product_query', 'custom_woocommerce_product_query' );
    
    function custom_woocommerce_product_query( $query ) {
        if ( ! is_admin() && $query->is_main_query() && is_shop() ) {
            if ( isset( $_GET['product_order'] ) && 'course_date' === $_GET['product_order'] ) {
                $meta_query = $query->get( 'meta_query' );
                if ( ! is_array( $meta_query ) ) {
                    $meta_query = array();
                }
                $meta_query[] = array(
                    'key'     => '_course_date',
                    'compare' => 'EXISTS',
                );
                $query->set( 'meta_query', $meta_query );
            }
        }
    }
    

    Can you please guide me on how to tackle this properly? Thanks, Jakub

    #1469195

    Hey jakubc15,

    Thank you for the inquiry.

    What do you mean by “Woocommerce Slider integrated in Enfold by a custom meta”? Please provide a screenshot and the link to the page containing the slider so that we can check it.

    Best regards,
    Ismael

    #1471732

    What I meant is “Product slider”, that is located in “Avia builder ” -> Plugins addons -> Product slider. The integrated filter is useful to define which products are to be displayed, but I was unsuccesfully trying to sort these filtered data by a custom meta, which I have availble for my products (e.g. date).
    Anyway, if this not useful for anyone else, we can close the topic, as I have approached this by a small plugin which I based on swiper.js which I can fully control.

    #1472099

    Hi,

    Great! Glad to know that you’ve found a working solution. Please feel free to open another thread if you have more questions about the theme.

    Have a nice day.

    Best regards,
    Ismael

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Custom ordering of the Enfold Woocommerce slider’ is closed to new replies.