Forked from twoelevenjay/woocommerce-give-subcat-list-items-their-own-ul.php
Created
June 1, 2020 16:52
-
-
Save AntonLitvin/92e932a090429ff36b8fe38acdfc64dd 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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment