Last active
November 9, 2023 15:30
-
-
Save twoelevenjay/a2195b052c4feb046d7f71fcae5c4d1b to your computer and use it in GitHub Desktop.
Move WooCommerce subcategory list items into their own <ul> separate from the product <ul>.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Move WooCommerce subcategory list items into | |
* their own <ul> separate from the product <ul>. | |
*/ | |
add_action( 'init', 'move_subcat_lis' ); | |
function move_subcat_lis() { | |
// Remove the subcat <li>s from the old location. | |
remove_filter( 'woocommerce_product_loop_start', 'woocommerce_maybe_show_product_subcategories' ); | |
add_action( 'woocommerce_before_shop_loop', 'msc_product_loop_start', 40 ); | |
add_action( 'woocommerce_before_shop_loop', 'msc_maybe_show_product_subcategories', 50 ); | |
add_action( 'woocommerce_before_shop_loop', 'msc_product_loop_end', 60 ); | |
} | |
/** | |
* Conditonally start the product loop with a <ul> contaner if subcats exist. | |
*/ | |
function msc_product_loop_start() { | |
$subcategories = woocommerce_maybe_show_product_subcategories(); | |
if ( $subcategories ) { | |
woocommerce_product_loop_start(); | |
} | |
} | |
/** | |
* Print the subcat <li>s in our new location. | |
*/ | |
function msc_maybe_show_product_subcategories() { | |
echo woocommerce_maybe_show_product_subcategories(); | |
} | |
/** | |
* Conditonally end the product loop with a </ul> if subcats exist. | |
*/ | |
function msc_product_loop_end() { | |
$subcategories = woocommerce_maybe_show_product_subcategories(); | |
if ( $subcategories ) { | |
woocommerce_product_loop_end(); | |
} | |
} |
Do you have a link to your site?
@EchoA331 Try to add this to your custom CSS code:
#main .products.row { justify-content: center; }
Thanks a lot !!
It works!!
Have a great weekend !!
kind regards
e.a
Στις Τρί 12 Ιουλ 2022 στις 1:26 π.μ., ο/η fkoomek ***@***.***>
έγραψε:
… ***@***.**** commented on this gist.
------------------------------
@EchoA331 <https://github.com/EchoA331> Try to add this to your custom
CSS code:
#main .products.row { justify-content: center; }
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/a2195b052c4feb046d7f71fcae5c4d1b#gistcomment-4228652>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AZ74CS74AEVRV4XOWKGVCULVTSNQNANCNFSM4HLYMPTQ>
.
You are receiving this because you were mentioned.Message ID:
<twoelevenjay/woocommerce-give-subcat-list-items-their-own-ul.
***@***.***>
@fkoomek thank you for your help, I will test it and I let you know about!!
…On Tue, Jul 12, 2022, 01:26 fkoomek ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
@EchoA331 <https://github.com/EchoA331> Try to add this to your custom
CSS code:
#main .products.row { justify-content: center; }
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/a2195b052c4feb046d7f71fcae5c4d1b#gistcomment-4228652>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AZ74CS74AEVRV4XOWKGVCULVTSNQNANCNFSM4HLYMPTQ>
.
You are receiving this because you were mentioned.Message ID:
<twoelevenjay/woocommerce-give-subcat-list-items-their-own-ul.
***@***.***>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks for your reply, unfortunately I do not know how !
I found many similar examples on the web, but none was working. Thanks anyway ! Have a nice day !