$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>hooks - How to output woocommerce products to a page, style and modify the html structure|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

hooks - How to output woocommerce products to a page, style and modify the html structure

matteradmin9PV0评论

I am a complete noob when it comes to woocommerce so bear with me. I have added 6 products into woo. I have a cart and a checkout page that are using shortcodes to output the php/html to those respective pages, now I know I can Edit files in an upgrade-safe way using overrides per the woo documentation. I have successfully modified these pages using that technique.

Also I am using the understrap-child theme, since it is custom do I need to add add_theme_support in my functions.php? as described in the woo docs.

Now getting to what I want to achieve. I want to create a new page in wordpress, lets call it all-products I want to loop through all my products and display them on the page, I also want to access the php file that I can overide html and php for that page, How would I do this. I don't see a shortcode to output all my products. This is where I am stuck. I can clarify this question if it is not clear enough. Would I create a page-products in my theme and use a theming snippet like below?

<ul class="products">
    <?php
        $args = array(
            'post_type' => 'product',
            'posts_per_page' => 12
            );
        $loop = new WP_Query( $args );
        if ( $loop->have_posts() ) {
            while ( $loop->have_posts() ) : $loop->the_post();
                wc_get_template_part( 'content', 'product' );
            endwhile;
        } else {
            echo __( 'No products found' );
        }
        wp_reset_postdata();
    ?>
</ul><!--/.products-->

Also is it better to use hooks to overide certain templates as described here could someone explain how do this hooks thing, I don't quite get where the code ends up.

Thanks! ahead of time.

I am a complete noob when it comes to woocommerce so bear with me. I have added 6 products into woo. I have a cart and a checkout page that are using shortcodes to output the php/html to those respective pages, now I know I can Edit files in an upgrade-safe way using overrides per the woo documentation. I have successfully modified these pages using that technique.

Also I am using the understrap-child theme, since it is custom do I need to add add_theme_support in my functions.php? as described in the woo docs.

Now getting to what I want to achieve. I want to create a new page in wordpress, lets call it all-products I want to loop through all my products and display them on the page, I also want to access the php file that I can overide html and php for that page, How would I do this. I don't see a shortcode to output all my products. This is where I am stuck. I can clarify this question if it is not clear enough. Would I create a page-products in my theme and use a theming snippet like below?

<ul class="products">
    <?php
        $args = array(
            'post_type' => 'product',
            'posts_per_page' => 12
            );
        $loop = new WP_Query( $args );
        if ( $loop->have_posts() ) {
            while ( $loop->have_posts() ) : $loop->the_post();
                wc_get_template_part( 'content', 'product' );
            endwhile;
        } else {
            echo __( 'No products found' );
        }
        wp_reset_postdata();
    ?>
</ul><!--/.products-->

Also is it better to use hooks to overide certain templates as described here could someone explain how do this hooks thing, I don't quite get where the code ends up.

Thanks! ahead of time.

Share Improve this question asked Dec 18, 2018 at 5:52 Anders KitsonAnders Kitson 1571 silver badge9 bronze badges 1
  • you need to learn woocommerce tamplate and hook to design and manipulate woocommerce customization from woocommerce docs. thanks – user147874 Commented Dec 18, 2018 at 6:23
Add a comment  | 

1 Answer 1

Reset to default 1

To create a product listing page on your site, you just create a normal page in the admin. Then in the admin go to WooCommerce > Settings > Products > General and select that page for the "Shop Page" setting.

If you want a custom product page you could do basically what your saying above. Create a new page in the admin, say its called My Products. Then you could use a page template called page-my-products.php and you could include your query in that template.

Post a comment

comment list (0)

  1. No comments so far