Support » Plugin: WooCommerce » [Plugin: WooCommerce] Reorder content on single product

Viewing 5 replies - 1 through 5 (of 5 total)
  • Steve



    Did you have any luck with this?
    I’m trying to do the exact same thing, I’m pretty sure hooks need to be added to the functions.php file.

    I have been testing how to move bits and bobs but can’t find out how to reorder the shop page so the “orderby” drop down menu appears at the top rather than the bottom.

    My progress so far is here:

    I’ve just figured out how to do this (mostly) with hooks. Add the following to functions.php (add it as all one line):

    add_action('woocommerce_before_main_content','woocommerce_catalog_ordering', 20 );

    This puts the orderby drop-down menu even with the breadcrumbs (breadcrumbs align left, orderby aligns right). I’d really like to have it between the page title and the product grid, but I haven’t been able to find the right hook for that.

    Take a look at the archive-product.php template in the Woocommerce templates folder to get a sense of what hooks are available where. Woocommerce code is extremely well-commented. Not sure about the current version, but in the archive-product.php of the 1.7 beta, but there is this patch of code:

    		<h1 class="page-title"><?php woocommerce_page_title(); ?></h1>
    		<?php do_action( 'woocommerce_archive_description' ); ?>
    		<?php if ( is_tax() ) : ?>
    			<?php do_action( 'woocommerce_taxonomy_archive_description' ); ?>
    		<?php elseif ( ! empty( $shop_page ) && is_object( $shop_page ) ) : ?>
    			<?php do_action( 'woocommerce_product_archive_description', $shop_page ); ?>
    		<?php endif; ?>
    		<?php if ( have_posts() ) : ?>
    				 * woocommerce_pagination hook
    				 * @hooked woocommerce_pagination - 10
    				 * @hooked woocommerce_result_count - 20
    				 * @hooked woocommerce_catalog_ordering - 30
    				do_action( 'woocommerce_before_shop_loop' );

    so the woocommerce_archive_description hook would come right after the page title. Or if you have posts then woocommerce_before_shop_loop would come after the archive title+descriptions.

    Both the woocommerce_archive_description and the woocommerce_before_shop_loop hooks put the orderby drop-down below the h1 title in such a way that the product grid is squeezed to the left to make room for a new column containing just the orderby drop-down. I’ve tried moving it with CSS, but it seems locked in a block div. What I really need is a hook in the same div as the h1 title; that is, a hook between woocommerce_before_main_content and woocommerce_archive_description. But I don’t see one either in the archive-product.php or in the WooCommerce docs.

    Any ideas about a way to add the code to archive-product.php in my child theme? I suspect I need to add a function and an if statement, but I have very minimal php skills, so I would need the actual snippet.

    Jmek, I have the exact same need as you. I want the order-by dropdown to be placed next to the title, on the right side. Seems illogical to do it any other way.

    For the time being, you may want to use Javascript. I added this to
    my_theme_wrapper_end (the link explains what that function does):

    echo '<script style="javascript">';
    echo 'document.getElementsByClassName("page-title")[0].appendChild (document.getElementsByClassName("woocommerce_ordering")[0])';
    echo '</script>';

    I also modified the css style of the thing:

    .woocommerce_ordering {float: right; margin:0; margin-top:6px}

    Don’t forget, you will need that css code to run after the woocommerce css so as to over-ride the margins on woocommerce_ordering — it originally has a margin-bottom of 2em.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Plugin: WooCommerce] Reorder content on single product’ is closed to new replies.