Order product by AdvancedCustomField value

This topic has 4 replies, 3 voices, and was last updated 5 months, 2 weeks ago ago by Andrew Mitchell

  • Avatar: Graziano
    Graziano
    Participant
    June 5, 2024 at 14:41

    Good morning, I managed to sort the products based on the date entered in a custom field and it works on this page:
    https://staging.sviluppomanageriale.it/catalogo-corsi/

    However, I can’t get it to work in list mode, like on this page:
    https://staging.sviluppomanageriale.it/lista-corsi-test/

    This is the script I placed in functions.php. Can you help me make it work in list mode as well?

    add_filter('woocommerce_get_catalog_ordering_args', 'woocommerce_catalog_orderby');
    function woocommerce_catalog_orderby( $args ) {
            $args['order']    = 'ASC'; 
            $args['meta_key'] = 'data_corso'; // ACF
            $args['orderby']  = 'meta_value';
    
        return $args;
    }

    Thank you.
    Graz

    Please, contact administrator
    for this information.
    3 Answers
    Avatar: Justin
    Luca Rossi
    Support staff
    June 5, 2024 at 16:16

    Hi @Graziano,

    Please also take a look at this file: /wp-content/plugins/et-core-plugin/app/controllers/elementor/general/product-list.php on the line 3184

    
    return new \WP_Query( apply_filters( 'woocommerce_products_widget_query_args', $query_args ) );
    

    So you have to hook to this filter also, the full code maybe like this:

    
    add_filter('woocommerce_get_catalog_ordering_args', 'woocommerce_catalog_orderby');
    add_filter('woocommerce_products_widget_query_args', 'woocommerce_catalog_orderby');
    function woocommerce_catalog_orderby( $args ) {
            $args['order']    = 'ASC'; 
            $args['meta_key'] = 'data_corso'; // ACF
            $args['orderby']  = 'meta_value';
    
        return $args;
    }
    

    Please note that the customization codes are out of scope our support standard. Should you require any further assistance or have additional questions, please do not hesitate to contact us.

    If you require personal customization services, we invite you to submit a request through our customization panel at: https://www.8theme.com/account/#etheme_customization_panel , and continue conversations with the technicians team directly.

    Best Regards,
    The 8Theme Team

    Avatar: Graziano
    Graziano
    Participant
    June 7, 2024 at 10:41

    It works!
    Thanks! I really appreciate!

    Have a nice day
    Graz

    Avatar: Andrew Mitchell
    Andrew Mitchell
    Support staff
    June 7, 2024 at 10:41

    Dear Graziano,

    Choosing our theme reflects your commitment to quality, and for that, we’re genuinely grateful. As we constantly strive to elevate your experience, your feedback is an invaluable gift. Could you kindly take a moment to rate our product with 5 stars on ThemeForest?

    Click here to share your insights: https://themeforest.net/downloads

    Your support fuels our journey, and we appreciate it more than words can express.

    Best Regards,
    The 8Theme Team

  • Viewing 4 results - 1 through 4 (of 4 total)

The issue related to '‘Order product by AdvancedCustomField value’' has been successfully resolved, and the topic is now closed for further responses

8theme customization service
We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.