West Pro Child theme's functions.php not working with WooCommerce Shop


#1

Hi,
I created a Child theme for West Pro.
Trying to change the number of columns showing on the ‘Shop’ page, by inserting this code in my child theme’s functions.php doesn’t work.
The code is a standard way of controlling the number of columns WooCommerce displays on the Shop page :

 /**
 * Number of columns per row
 */
  function westchild_shop_columns() {
    return 1;
   }
   add_filter('loop_shop_columns', 'westchild_shop_columns');

On the other hand, if I do that same change in the West Pro parent theme’s : west-pro/woocommerce/woocommerce.php , with the function that is already there :

/**
 * Number of columns per row
 */
function west_shop_columns() {
    return 1;
}
add_filter('loop_shop_columns', 'west_shop_columns');

then the change in the code is reflected on the Shop page.
I understand that I could modify the parent West Pro theme this way, but my first choice is to do this via my child theme.

Can you please explain why is this happening ?

The Child theme is enqueued properly, and the functions.php is showing as an active script on the front , so it appears that everything is set right.

Thanks,

Zoran


#2

Hello Zoran,

Please check the following article.

Please feel free to ask any other questions that you might have.

Kind Regards, Roman.


#3

Hi Roman,

Yes, thank you. That helped.
I had a foggy notion about how the functions.php of the parent and the child theme work together,
but this article really put the things in place for me.
The parent theme’s functions.php will always run last, so it is the code that is applied, unless specifically over-ridden by the child theme’s functions.php

All I did in this case, is to add a higher priority number to my Child Theme’s filter hook, 20,
which is higher than the default WordPress priority ( 10 ) .

/**
 * Number of columns per row
 */
function west_shop_columns() {
    return 1;
}
add_filter('loop_shop_columns', 'west_shop_columns', 20 );

and now it works fine.

Thanks,

Zoran


#4

You are welcome Zoran,

It’s great that now it works fine!

Have a nice day :slight_smile:

Kind Regards, Roman.