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.
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.
you can still use a shortcode inside of php if you aren't customizing the output. see https://docs.woocommerce/document/woocommerce-shortcodes/#scenario-5-specific-categories and https://developer.wordpress/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/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();
}
?>
Assuming woocommerce plugin is in place:
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) )
{
$args = array('category' => array( 'Your category name' ), );
$products = wc_get_products( $args );
foreach ($products as $product)
{
DebugLog('Title: '. $product->get_name() . ' Price: ' . $product->get_price()) ;
}
}
$product->get_title(), does not always seem to display the product name.