Site logo

Archived topic

Change number of Cross Sells columns on WooCommerce cart page

9 replies · Started by Debra on November 30, 2022

Viewing posts 1–10 of 10

My WooCommerce cart is set to show 2 columns for Cross Sells. I'm not sure if this is something I set somewhere or not (I cannot find a setting option). I want to change this to 1 column. Any suggestions?

Hi Fernando,

Thanks for the response. Changing that setting to 1 still formats the cross-sells in the cart with 2 columns. However, it does change the columns on my Single Product display.

If possible, I would like to keep the number of columns on my Single Product pages set to something different than on the cart page.

When I inspect the CSS on the cart page I see: <div class="cross-sells"><ul class="products columns-2">. (This is the same regardless of what number I set in the Appearance > Customize > Layout > WooCommerce > Single Product > Related/Upsell Columns value.)

I see. Sorry, I misunderstood. The column setting for that section is controlled by WooCommerce.

To alter it, you can try adding this PHP snippet:

add_filter( 'woocommerce_cross_sells_columns', 'change_cross_sells_columns' );
 
function change_cross_sells_columns( $columns ) {
    return 1;
}

Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets

This should turn columns-2 to columns-1.

Let us know how it goes.

That changes the CSS to show <div class="cross-sells"><ul class="products columns-1"> However, I was hoping my product would resize to fill that column. Instead, it still displays as if it's in a 2 column format.

I see. Try adding this through Appearance > Customize > Additional CSS:

.cross-sells ul.products.columns-1 > li {
    width: 100% !important;
    text-align: center;
}

.cross-sells ul.products.columns-1 > li .inside-wc-product-image {
    width: 100%
}
.cross-sells ul.products.columns-1 > li .star-rating {
    margin-left: auto;
    margin-right: auto;
}

That works perfectly! Is there a tip jar here for outstanding support?

Perfect! Thanks, David!

Thank you ! It is much appreciated :)

This archived topic is closed to new replies.