Hi Colorlib team, firstly a heads up… I’ve always had good experience with your support.
Secondly, my brief set up which MAY help:
- Dazzling theme
- Have a 'dazzling-child' theme installed. I'm under the impression the child theme is being used, since any custom CSS I've done, takes effect.
Woocommerce - I need to change the coding specifically for the shortcode [product_categories] so that it returns all categories except a few.
I tried copying the below code/function, which I get from the woocommerce/includes folder, to functions.php and even tried copying the whole ‘class-wc-shortcodes.php’ file into the child theme folder using the same folder structure ‘/dazzling-child/woocommerce/includes’. When I do any of the above, it either doesn’t take effect or if I copy/paste into functions.php, it crashes the site.
Any ideas here? I’m not even sure if this involves your theme or woocommerce, or I just don’t understand the structure of things yet.
Looking forward to your reply, thanks.
/**
* List all (or limited) product categories
*
* @param array $atts
* @return string
*/
public static function product_categories( $atts ) {
global $woocommerce_loop;
$atts = shortcode_atts( array(
'number' => null,
'orderby' => 'name',
'order' => 'ASC',
'columns' => '4',
'hide_empty' => 1,
'parent' => '',
'ids' => ''
), $atts );
if ( isset( $atts['ids'] ) ) {
$ids = explode( ',', $atts['ids'] );
$ids = array_map( 'trim', $ids );
} else {
$ids = array();
}
$hide_empty = ( $atts['hide_empty'] == true || $atts['hide_empty'] == 1 ) ? 1 : 0;
// get terms and workaround WP bug with parents/pad counts
$args = array(
'orderby' => $atts['orderby'],
'order' => $atts['order'],
'hide_empty' => $hide_empty,
'include' => $ids,
'pad_counts' => true,
'child_of' => $atts['parent']
);
$product_categories = get_terms( 'product_cat', $args );
if ( '' !== $atts['parent'] ) {
$product_categories = wp_list_filter( $product_categories, array( 'parent' => $atts['parent'] ) );
}
if ( $hide_empty ) {
foreach ( $product_categories as $key => $category ) {
if ( $category->count == 0 ) {
unset( $product_categories[ $key ] );
}
}
}
if ( $atts['number'] ) {
$product_categories = array_slice( $product_categories, 0, $atts['number'] );
}
$columns = absint( $atts['columns'] );
$woocommerce_loop['columns'] = $columns;
ob_start();
// Reset loop/columns globals when starting a new loop
$woocommerce_loop['loop'] = $woocommerce_loop['column'] = '';
if ( $product_categories ) {
woocommerce_product_loop_start();
foreach ( $product_categories as $category ) {
wc_get_template( 'content-product_cat.php', array(
'category' => $category
) );
}
woocommerce_product_loop_end();
}
woocommerce_reset_loop();
return '<div class="woocommerce columns-' . $columns . '">' . ob_get_clean() . '</div>';
}