-
Notifications
You must be signed in to change notification settings - Fork 22
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
add_post_type_fields for language is not working for woocomerce products #70
Comments
@PeteKoda can you explain a bit more about the workaround? I'm also facing the same issue. |
Hey @brianpereradap , i tried adding the translations field to the product connection but it stopped working for me so I just created an API call that fetches the available translations for a single product. So it's a workaround but not a proper one, I will investigate this in more depth for a new project of mine, if I find a better solution I will let you know! |
@PeteKoda thanks for the insight |
Hi @PeteKoda, I'm trying to use this plugins to fetch all the products in one particular language. |
Hi @H-Nguyenx. You can fetch all the products of a particular language with this plugin by using the product category query and the language as the where parameter. If you want to fetch it from the root product query you need to register the language fields to it. If you describe exactly the problem you are facing I might be able to help you! I am attaching a screenshot of what I am referring in the fist comment of the issue, if it is what you need let me know! |
Hi all, it's true that fetching the products via the Product Category query with a Language parameter works, however this shouldn't be the preferred way of querying by language in my opinion. As this brings a few complications:
|
@PeteKoda @brianpereradap @H-Nguyenx I just inspected the code and basicly the plugin makes the "where: (language: XX)" clause available for the post types that are supported by default by the WPGraphQL plugin (via the get_allowed_post_types() function or "graphql_post_entities_allowed_post_types" filter hook). We basicly just have to hook the "product" post type in there and the "where: language = xx" clause will be available in the Products query without having to query Product Category first! A very simple solution would be to install the "WPGraphQL Enable All Post Types" plugin! This allows for querying products via the following scheme:
|
I do not know how to register the language fields to root query products. Please show me how to do it! |
Thank you! It works. I wonder if installing this plugin is going to have an impact on wordpress server. |
add_post_type_fields(get_post_type_object('product')); function add_post_type_fields(\WP_Post_Type $post_type_object)
} This is what I am doing to expose the language to the product query, it is basically a copy paste from the plugin |
@PeteKoda thank you. It works. |
@PeteKoda I found a solution for this. So as you can see you added a type to support the post type "product" but you also need to query into products so here is an example : function addProductLanguage(){
}
}
} |
I am trying to access the translations of products and the current language but its not working. I searched for the get_allowed_post_types and I think there is a timing error so the product post type is not fetched. I don't know if this is a wp-graphql-polylang problem or a wp-graphql-woocomerce but I had to call again the add_post_type_fields in my function theme to make the language and the translation work for them.
The text was updated successfully, but these errors were encountered: