I need to display New Arrivals in a section of my homepage, I have created a new arrivals category and would like to display the products in this category on a page, I don’t want to use the shortcode as I am writing the html & php for this page.

Any help would be appreciated, thanks.

2 Answers
2

you can still use a shortcode inside of php if you aren’t customizing the output. see https://docs.woocommerce.com/document/woocommerce-shortcodes/#scenario-5-specific-categories and https://developer.wordpress.org/reference/functions/do_shortcode/

<?php
echo do_shortcode('[products category="new-arrivals"]');
?> 

Alternatively, If you need to customize the output of the products then just use wc_get_products to get a list of products and iterate through it. See https://github.com/woocommerce/woocommerce/wiki/wc_get_products-and-WC_Product_Query

<?php
$args = array(
    'category' => array( 'new-arrivals' ),
);
$products = wc_get_products( $args );
foreach ($products as $product) {
    echo $product->get_title() . ' ' . $product->get_price();
}
?>

Leave a Reply

Your email address will not be published. Required fields are marked *