-
Notifications
You must be signed in to change notification settings - Fork 17
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
WooCommerce integration #1
Comments
Here's something Mehidi Hassan did on the WPGraphQL slack: /**
* Add offset pagination to products.
*/
function theme_prefix_add_offset_pagination_to_products() {
register_graphql_field(
'RootQueryToProductConnectionWhereArgs',
'offsetPagination',
array(
'type' => 'OffsetPagination',
'description' => 'Paginate content nodes with offsets',
)
);
}
add_action( 'graphql_register_types', 'theme_prefix_add_offset_pagination_to_products' );
/**
* Add offset pagination to products.
*
* @param array $query_args query args.
* @param array $where_args where query args.
*/
function theme_prefix_filter_map_offset_to_wp_query_args(
array $query_args,
array $where_args
) {
if ( isset( $where_args['offsetPagination']['offset'] ) ) {
$query_args['offset'] = $where_args['offsetPagination']['offset'];
}
if ( isset( $where_args['offsetPagination']['size'] ) ) {
$query_args['posts_per_page'] =
intval( $where_args['offsetPagination']['size'] ) + 1;
}
return $query_args;
}
add_filter( 'graphql_map_input_fields_to_product_query', 'theme_prefix_filter_map_offset_to_wp_query_args', 10, 2 ); The thread: |
From the solution mentioned in the comment above Only the following part is needed:
The filter
wp-graphql-offset-pagination/src/Loader.php Line 148 in 2ac1b2f
|
As of today on: This worked: |
Why I want it
Is it worth it?
how?
I'd like to see what you would think, seeing as you created this and I'm fairly new to all this, all I am trying to do is get some input if this makes any sense or not. I personally forked it and implemented the WooCommerce feature here.
Thank you for this awesome work!
The text was updated successfully, but these errors were encountered: