Skip to content

Conversation

@mikejolley
Copy link
Contributor

@mikejolley mikejolley commented Mar 22, 2018

Adds basic WooCommerce support in the 3rd party scripts directory for WooCommerce.

This branch was branched from #9112 which will need reviewing and merging first.

The following changes are all related to WooCommerce and other plugin compatibility and are hence grouped into this single PR.


Posts per page changes

The current system is quite odd; it uses a fixed number of 7 or the 'posts per page' setting in WP Admin. This isn't suitable for custom post types where they have their own posts_per_page setting or preference. WC is a perfect example whereby posts_per_page is set to match our products grid.

To make this more robust we pass through the posts per page setting from the original query and use this instead.

If the theme defines a different posts_per_page value, we can default to that.


Render callbacks

The previous system relied on a setting, and a fallback, for the render callback. One could also use infinite_scroll_render action.

There are a few problems with this:

  • When the render setting is loaded, the action is immediately hooked in
  • Multiple 'things' can attach to infinite_scroll_render action, and the only way to prevent other callbacks outputting things is to remove_action
  • Sites can have multiple types of content e.g. posts and products, so a single callback is unlikely to be able to cover all use cases unless it's specifically handled by the theme.

Our solution is to have a filter of registered callbacks which get ran in sequence. If a callback returns nothing (perhaps wrong post type is being shown?), it continues to the next until content is returned. Callbacks registered through theme support are still called, and the final fallback is the default render method in infinite scroll class.

The filter is infinite_scroll_render_callbacks. So example use:

add_filter( 'infinite_scroll_render_callbacks', 'register_some_custom_render_callbacks' );

function register_some_custom_render_callbacks( $callbacks ) {
$callbacks[] = 'my_post_render_callback';
$callbacks[] = 'my_product_render_callback';
return $callbacks;
}

With this example it would call the following functions/methods in this order until content is returned:

  1. my_post_render_callback()
  2. my_product_render_callback()
  3. Whatever was added via add_theme_support
  4. The_Neverending_Home_Page::render()

WooCommerce compatibility

All we need to do on this side is use the correct template for the content and render our wrappers. This should be fairly standard to any theme.

jetpack_woocommerce_infinite_scroll_render does the rendering of this loop, and jetpack_woocommerce_infinite_scroll_render_callback registers this renderer using the system outlined above.

jetpack_woocommerce_infinite_scroll_style simply hides the default numbered pagination WooCommerce outputs with CSS.

@mikejolley mikejolley requested a review from a team as a code owner March 22, 2018 12:08
@jeherve jeherve added [Type] Bug When a feature is broken and / or not performing as intended [Feature] Infinite Scroll [Status] Needs Review This PR is ready for review. [Pri] Normal [Status] In Progress and removed [Status] Needs Review This PR is ready for review. labels Mar 22, 2018
@ghost ghost removed the [Status] In Progress label Mar 22, 2018
@mikejolley mikejolley added [Status] Needs Design Review Design has been added. Needs a review! [Status] Needs Testing We need to add this change to the testing call for this month's release [Status] Needs Review This PR is ready for review. and removed [Status] Needs Design Review Design has been added. Needs a review! labels Mar 22, 2018
@jeherve jeherve added this to the 6.0 milestone Mar 22, 2018
Copy link
Contributor

@zinigor zinigor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! Testing this, looks like it really fixes the old IS problem with custom post types and sorting. Well done!

@zinigor zinigor added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review This PR is ready for review. labels Mar 27, 2018
@ghost ghost removed the [Status] Ready to Merge Go ahead, you can push that green button! label Mar 27, 2018
@mikejolley
Copy link
Contributor Author

mikejolley commented Mar 27, 2018

Added a commit to fix a theme conflict reported by @jeffikus and .com themes.

@dereksmart dereksmart merged commit 9dd5ccc into master Mar 27, 2018
@dereksmart dereksmart deleted the update/infinite-scroll-woocommerce-compat branch March 27, 2018 20:37
@jeffikus
Copy link

Thanks @mikejolley busy testing now.

@jeffikus
Copy link

Update:
I've tested this with the WC fix branch as well as with Storefront and all the free .org versions of the .com themes.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants