Override Avada Catalog sorting hook back to default in Woocommerce

别来无恙 提交于 2019-12-04 17:12:12

Update 2:

I think that if you add a highest priority than Avada's theme hook it will work (here I have set it to 100), and the only change to do in this function is $args['orderby'] = 'menu_order date'; to get the similar change you have done on Avada's files.

The code:

add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_catalog_ordering_args', 100 );
function custom_woocommerce_get_catalog_ordering_args( $args ) {
    $args['orderby'] = 'menu_order date';
    return $args;
}

This code goes in function.php file of your active child theme.

It should work


The very strange thing is that woocommerce_get_catalog_ordering_args is a filter hook, but NOT an action hook (so I have changed my code)…

Then something is wrong in the Avada's theme code and you should report it to the support.

You just need to increase your hooked function, so it will override Avada's:

add_action('after_setup_theme', 'remove_avada_function' );
function remove_avada_function(){
    remove_action( 'woocommerce_before_shop_loop', 'catalog_ordering', 30 );
    add_action( 'woocommerce_before_shop_loop', 'custom_catalog_ordering', 30 );
}

There is nothing wrong with the Avada Code.

Avada intentionally unhooks the filter 'woocommerce_get_catalog_ordering_args' and writes its own filter "catalog_ordering" in '/wp-content/themes/Avada/includes/class-avada-woocommerce.php'

That calls

'/wp-content/themes/Avada/templates/wc-catalog-ordering.php'

Please overwrite the template by using your child theme and copying the contents of wc-catalog-ordering.php.

i.e. "/wp-content/themes/Avada-Child-Theme/templates/wc-catalog-ordering.php"

You'll be able to handle the orders however you'd like once complete.

Previously mentioned, the function "remove_avada_function" is hooked on 'after_setup_theme' and is used to remove the hook. However since 'remove_avada_function' is called before the action 'pre_get_post' is called, 'remove_avada_function' won't remove the action that does not currently exist.

Happy Coding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!