Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #646395

    I have the correct code to add “Random” as a sorting option. It used to work for the product grid and show up. I just noticed now it doesn’t. Did something change? I did search this forum and found a thread for a while ago about editing a file to add Random in, but I’m looking for an update proof solution. Below is what I have and what was working for quite a while.

    // adds an extra option for sorting product listings randomly
    add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' );
    function custom_woocommerce_get_catalog_ordering_args( $args ) {
      $orderby_value = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
    	if ( 'random_list' == $orderby_value ) {
    		$args['orderby'] = 'rand';
    		$args['order'] = '';
    		$args['meta_key'] = '';
    	}
    	return $args;
    }
    add_filter( 'woocommerce_default_catalog_orderby_options', 'custom_woocommerce_catalog_orderby' );
    add_filter( 'woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby' );
    function custom_woocommerce_catalog_orderby( $sortby ) {
    	$sortby['random_list'] = 'Random';
    	return $sortby;
    }
    #647826

    Hey Kahil!

    Thank you for using Enfold.

    If you’re using the product grid element, add this in the functions.php file:

    add_filter('avia_product_slide_query', 'avia_product_slide_query_mod', 10, 2);
    function avia_product_slide_query_mod($params, $grid, $test) {
    	$params['orderby'] = 'rand';
    	return $params;
    }

    Cheers!
    Ismael

    #844494

    Hi Ismael,

    I was searching for a solution to get the Option “random” available to my product grid.
    This filter, mentioned above, does not add the random Option to my product grid sorting Dropdown.
    Is there another solution, or do I have to use the shortcode directly?

    Regards,
    Michael

    #844717

    Hi,

    I have noticied that you created this thread more than one year ago, so, ensure that you`re using our latest version of the theme and plugins and provide to us your WP credentials and website link if this issue persists.

    Best regards,
    John Torvik

    #844725

    Hi John,

    sorry, this was not my thread actually. But since here a solution for my current problem was provided, I replied to this thread!
    Or should I open a new thread?

    Please feel free to log into my page.

    Regards,
    Michael

    #845772

    Hi Michael,

    Here is where the setting appears from the code above
    http://imgur.com/a/k4lmW

    The code works fine on my instance. SO you set it in WooCommerce settings and then choose it in the product grid setting.

    If you need further assistance please let us know.
    Best regards,
    Victoria

    • This reply was modified 6 years, 7 months ago by Victoria.
    #845820

    Hi Victoria,

    thank you for your answer.
    Yes, this Option is available now and I already saw and testet it. But changing this would influence all the product listings.
    I want to get the Random Option only for a Special product grid, not for woocommerce product queries.

    Hopefully you can see my Problem now?

    Best Regards,
    Michael

    #845915

    @zwachm I have been requesting that for a long time. The last time I asked, a nod told me that they weren’t responsible for and don’t support added code and offered me to buy their support time. As the code came from the team and is on their website as a snippet, I called them out in it. Been radio silence ever since. The random code seems to work fine the way you and I want it to IF you’re using it on portfolios and image galleries. But not for product grids. I know it is possible to do since they donl it with the related product and up sell listings on a single product page. So it can be done.

    For me, the only way I could get it to work the way I wanted was to use the random code for the grid where I needed to, then when I needed to put things in a specific order I manually did each listing using the single product shortcode. Until they fix their code, that is the only way to do this.

    #845952

    @Kahil: thank you for your Response!

    I already have a solution for it, but it is a source Code Change in ENFOLD. So my Intention was to get it solved/added in the next update, since it IS NOT a big deal!!

    With this Code Change you will have the Dropdown for the product grid Extended by the random Option:

    File:
    enfold/config-templatebuilder/avia-shortcodes/product_grid.php

    simply add the ‘random’=>’rand’,

    
        "name"  => __("Sorting Options", 'avia_framework' ),
                                                    "desc"  => __("Here you can choose how to sort the products. Default setting can be set at Woocommerce -&gt Setting
                                                    "id"    => "sort",
                                                    "type"  => "select",
                                                    "std"   => "dropdown",
                                                    "no_first"=>true,
                                                    "subtype" => array( __('Let user pick by displaying a dropdown with sort options (default value is defined at Defau
        __('Use defaut (defined at Woocommerce -> Settings -&gt Default product
        __('Sort alphabetically', 'avia_framework' ) =>'title',
        __('Sort by most recent', 'avia_framework' ) =>'date',
        __('Sort by price', 'avia_framework' ) =>'price',
        'random'=>'rand',
        __('Sort by popularity', 'avia_framework' ) =>'popularity')),
    
    • This reply was modified 6 years, 7 months ago by zwachm.
    #847419

    Hi,

    @zwachm
    thanks for sharing your solution.

    Best regards,
    Mike

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.