Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

WooCommerce product categories float into products

  • purevelvetdesign

    Hi,

    here I have the case that the product categories of WooCommerce float into product columns.
    Is there a fix for that?

    Thanks
    André

  • Hi there,

    To separate the woocommerece categories from the products on the shop page requires some PHP.
    Woo hooks in the woocommerce_maybe_show_product_subcategories function to the product loop.
    Which you can unhook from loop and then re-hook before the loop, using this snippet:

    
    // remove the subcategories from the product loop
    remove_filter( 'woocommerce_product_loop_start', 'woocommerce_maybe_show_product_subcategories' );
    
    // add subcategories before the product loop 
    add_action( 'woocommerce_before_shop_loop', 'show_product_subcategories', 10 );
    
    function show_product_subcategories() {
        $subcategories = woocommerce_maybe_show_product_subcategories();
            if ($subcategories) {
              echo '<ul class="subcategories products columns-4">',$subcategories,'</ul>';
        }
    }
    

    Note this line:

    echo '<ul class="subcategories products columns-4">',$subcategories,'</ul>';

    The columns-4 defines the number of columns being display for the categories. Change the 4 to whatever you require.

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