"Keep Shopping" Category Links Below the Cart
Lists your most popular product categories as buttons below the cart, giving shoppers an easy way to add more before checking out.
Opens WPIDE on
Code
$count = 5; // Number of categories to show.
$terms = get_terms( array(
'taxonomy' => 'product_cat',
'hide_empty' => true,
'orderby' => 'count',
'order' => 'DESC',
'number' => $count,
'exclude' => array( (int) get_option( 'default_product_cat' ) ),
) );
if ( $terms && ! is_wp_error( $terms ) ) {
echo '<div class="wpide-keep-shopping" style="margin-top:32px;"><p style="font-weight:600;">Keep shopping</p><p>';
foreach ( $terms as $term ) {
printf( '<a class="button" style="margin:0 8px 8px 0;" href="%1$s">%2$s</a>', esc_url( get_term_link( $term ) ), esc_html( $term->name ) );
}
echo '</p></div>';
}
Notes
Change $count to show more or fewer categories. Categories are ordered by number of products.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.