Halloween Sale 15% off Ends in See the plans
PHP

"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.

Don’t have WPIDE yet? Install it on your site

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

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.