Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Req] WooCommerce Bootstrap Grid #313

Closed
GuerrillaCoder opened this issue May 15, 2017 · 12 comments
Closed

[Feature Req] WooCommerce Bootstrap Grid #313

GuerrillaCoder opened this issue May 15, 2017 · 12 comments

Comments

@GuerrillaCoder
Copy link

I am making a WooCommerce theme using Understrap and one thing that struck me is that WooCommerce use their own grid that doesn't give any control over how columns are displayed on different viewports. Their shortcodes have a single column param and then the rest is worked out by the CSS and often isn't right for where the grid is displaying to make it nice on all screens.

I have been thinking about the best way to handle this and thought I might be able to make a PR out of what I come up with so thought it prudent to ask advice here first (hope that is OK),

I saw another project that overwrites all of the WooCommerce shortcodes with alternate methods that produce a bootstrap grid. I wasn't sure if this was a good approach to take so I played safe and made a copy of class-wc-shortcodes.php and renamed the class & shotcodes. Then I added additional fields to each method for the number of columns on each viewport and made my own product_loop that outputs a bootstrap 4 grid.

I'm not sure if this is a good approach because if a user of my theme uses woocommerce normal shortcode it will output the default grid still. Overwriting all the shortcodes seems more consistent but I am wondering if that will cause compatibility issues or be harder to maintain?

Seeing as understrap is a bootstrap theme I think having option to display woocommerce products in a bootstrap grid is inline with the project. Is this something you would like to add? What are your thoughts on how best to do it?

@coldfusion411
Copy link

coldfusion411 commented May 15, 2017 via email

@GuerrillaCoder
Copy link
Author

What is best practice for handling woocommerce product grid in bootstrap theme? I must admit I am a bit confused what approach to take here to style products and make properly mobile responsive. I am new to the woocommerce css but know bootstrap well so my first thought is to make the grid bootstrap. How do you do it?

@ZacharyElkins
Copy link
Collaborator

ZacharyElkins commented Jun 1, 2018

@GuerrillaCoder The way I would go about it is to modify the WooCommerce template files. They have areas for their grid that can be edited.

It depends on how much you'd like it to be Bootstrapified. If it's just the product listings it's pretty simple, but there are multiple ways of doing it.

Bootstrap WooCommerce product listings

WooCommerce has a built-in grid system, which has been improved lately. This will be a very brief guide on how to make the product listings work with the Bootstrap grid instead. If you want to dig further it will be beneficial, as you can then start removing the WooCommerce styles from WordPress and use the styles already included in Bootstrap. If you choose to go further, it will mean reworking the single-product layout, and then you'll have all your billing and user templates as well. Nearly all of the work will be achieved by editing the templates provided by WooCommerce. There are some examples you can find by digging through repo's on Github, as people have already worked on this same goal. Most are outdated though.

1. Add row to product loop

woocommerce/loop/loop-start.php

https://github.com/woocommerce/woocommerce/blob/56acb05521e25b17765514e5ea7407aa7682316e/templates/loop/loop-start.php#L23

Change this line to:

<ul class="products row">

2. Change product content in loop to Bootstrap columns

woocommerce/content-product.php

https://github.com/woocommerce/woocommerce/blob/56acb05521e25b17765514e5ea7407aa7682316e/templates/content-product.php#L27

Change this line to:

<li <?php wc_product_class('col-12'); ?>>

Use whatever column classes you want in place of col-12

Notes

This will remove the WooCommerce grid features. If you want to remove the bloat of WooCommerce styles you will have to do a more intensive amount of customization, like formatting the single-product layout and other areas as well.

This could be included into Understrap, but I doubt that it is in-line with the goal of keeping Understrap lightweight and aimed at developers.

@Thomas-A-Reinert
Copy link
Contributor

@ZacharyElkins would you be so kind to commit that info to the documentation project? Thanks in advance!

@ZacharyElkins
Copy link
Collaborator

ZacharyElkins commented Jun 2, 2018

@Thomas-A-Reinert A whole lot more can be said about replacing Woo styles with Bootstrap. Is that something we really want to add though?

At that point we could be replacing it and including it in Understrap, which may be less than ideal for some users. Including it in Understrap would also add more upkeep and troubleshooting/documentation. Removing WooCommerce styling and replacing it with Bootstrap is something that the developers should learn if they want their site to launch well, in the case where they are using Bootstrap styling instead.

I don’t mind either way, just asking the question. My vote would be for having it in the docs, as you suggested, if it were one or the other.

@Thomas-A-Reinert
Copy link
Contributor

Yo @ZacharyElkins. Thats not an easy one.
Once you make "Bootstrap4" a project premise, that´s not a decision anymore. And I guess that goes with the majority of US-Users, if I´m not all wrong.

  1. Yes - it needs maintainance. More than we want, actually.
  2. But - better have it updated through the parent than by WooCommerce itself. Because. I made a (child) based pon UnderStrap and HEAVILY adjusted almost any file to fit UnderStrap styles etc. With every other Woo-Update I have to inspect almost every single file again. Which is a real PITA.
  3. Including EVERY template into UnderStrap will mean that we´ll have to be responsible for ANY change in Woo´s files. Pain in the *ss again. But less pain in my opionion. This will also make a (positive) impact on child themes.

Sidenote: This may not be the smartest solution and I may think over it tomorrow as like on the past fridays, i´ll try to keep up ;)

@ZacharyElkins
Copy link
Collaborator

ZacharyElkins commented Jun 7, 2018

@Thomas-A-Reinert I've read through that a few times. Not sure if that is a clear yes, maybe, or no?

I think the largest issue, beyond upkeep, will be that WooCommerce has its own stylesheets. I don't remember if they directly interfere when changing it to a Bootstrap grid or not. If they do, we will have to get rid of some of the Woo classes to avoid that issue, or directly include a function which removes the Woo styling by default. This can be done because WooCommerce has a separate stylesheet for their grid.

The documentation will also have to include information on how to change the grid, or possibly adding the option into customizer, again with supporting documentation.

All decisions which I don't feel comfortable making myself, as it affects a lot of people.

@GuerrillaCoder
Copy link
Author

I think the alternate shortcode method might be easiest. Then you can have a choice of using defualt grid if there is compatibility issue or bootstrap grid if you want one easy to style. Then we have to make a custom walker that has filters to allow control of the columns at different break points. Someone out there already did one but it didn't have the filters I wanted. I started writing my own back when I first made this post but it was taking a while so I just built my own loop to get the project finished.

https://wordpress.org/plugins/woocommerce-twitterbootstrap/

I went over the code in detail at the time but it was a year ago so I can't really remember anything other than deciding it would be better to do it differently.

I'm stuck on a demanding Magento template re-design atm but I have a Woocommerce project in my queue so if no one has done anything by time I finish I'll have another crack at doing some solution that is flexible.

We could possibly make it an admin setting for default templates to use the standard grid or bootstrap grid.

@ZacharyElkins
Copy link
Collaborator

ZacharyElkins commented Jun 7, 2018

@GuerrillaCoder Interesting. The issue with shortcodes to generate the loop is that pagination doesn’t work out of the box. In fact getting pagination to work with shortcode loops (for Woo) is a pain.

WC templates have a spot for the columns to go in, then it would just be a matter of pulling in the desired col-X-X through PHP, preferably from the customizer. We could also have the option to switch from WC grid to BS grid as well. All relatively easy to get going, not including testing and any issues that may arise.

Seems a lot easier than working with an alternate shortcode, and will be easier for the user as well. Unless I’m misunderstanding what you mean.

@GuerrillaCoder
Copy link
Author

GuerrillaCoder commented Jun 7, 2018 via email

@Eagerbob
Copy link

Eagerbob commented Feb 7, 2019

WooCommerce has a built-in grid system, which has been improved lately.

The thing is that it not half as flexible as the BS grid. The BS grid is pretty ideal for a products page. For instance have 4 columns on a superwide screen, 3 on a laptop, 2 on a portrait tablet and 1 on a mobile. You can't do this with WC, and it is not designed to do that. WC wants you to select a number of columns from the customizer, and that's it.

1. Add row to product loop

woocommerce/loop/loop-start.php

2. Change product content in loop to Bootstrap columns

woocommerce/content-product.php

Notes
This will remove the WooCommerce grid features.

Did you test this? I did exactly this before I came here looking for solutions. WooCommerce still injects it classes through the customizer, resulting in all kinds of weirdness.

I have a page with separate rows of three products in a category. I want the columns to stack on xs screens. Easy to do with BS, not so with Understrap and WC. Or is the WP customizer the culprit here? Anyway, I would welcome a better integration of WC with the BS grid that Understrap uses.

@Thomas-A-Reinert
Copy link
Contributor

Assume this has been fixed by now. In case it hasn´t, please reopen this topic as I´m closing it due to the time there hasn´t been any update to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants