-
-
Notifications
You must be signed in to change notification settings - Fork 131
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
Help using the checkout
mutation to create orders.
#147
Comments
I recommend doing query validation of some kind and not just returning |
Thanks @kidunot89 for your reply but when I query on checkout I got this. |
I have been stuck on this for 2 days. I am experienced JS person and it is my first time interacting with wordpress |
Also, I haven't done much in the way of documentation, but I create detailed PR summaries. Here a list of a the major ones. Click the link at the end of bullet point to be taken to any sub PR with example and more details |
Hi @khuramdogar & @kidunot89 , I'm facing same issue, Please let me know if you find any solution. |
@khuramdogar, have you found anything? I am facing some similar issues. Please post if you find anything. |
@khuramdogar @umairraza101 @AliHussainciit the |
@kidunot89 Thank you very much. Is there any way I can test this with Postman or any other rest client. |
Hmm, I don't believe so. The header value is sent in GraphQL response of any mutations that change that data, this current includes |
Even after having those rights, its showing me the error having no rights to make that change :/ |
@Dksami sorry, about the trouble. I found a bug related to user capabilities, it been patched on the |
It looks like it works on the older versions and doesn't work on the recent one. Is there an alternative? |
@Dksami @topheroes the filter name changed on the newer versions. Now it's called So it would end up looking like this: // functions.php
function authorized( $authorized ) {
$authorized = true;
return $authorized;
}
add_filter( 'graphql_woocommerce_authorized_to_create_orders', 'authorized' ); Hope that helps :) UPDATEHere is how I force the logged user to create orders with their customerID, only if they are logged in. // functions.php
function authorized($authorized, $order_id = null, $input) {
if (!$authorized) {
$user = wp_get_current_user();
if (!empty($user)) {
$user_id = $user->data->ID;
$customer_id = $input['customerId'];
if (!isset($customer_id) || $customer_id === $user_id) {
return true;
}
}
}
return $authorized;
}
add_filter('graphql_woocommerce_authorized_to_create_orders', 'authorized', 1, 3);
function assign_customer_id_to_current_user($order){
$user = wp_get_current_user();
if (!empty($user)) {
$user_id = $user->data->ID;
$customer_id = $order->get_customer_id();
if (!$customer_id) {
$order->set_customer_id($user_id);
$order->save();
}
}
return $order;
}
add_filter('graphql_woocommerce_after_order_create', 'assign_customer_id_to_current_user'); |
@jonlovera Thanks so much for catching that i should have made some notes on the hook name changes in the release summary. 😅 |
checkout
mutation to create orders.
Hi @jonlovera , does this solution of yours solve the problem of orders being linked only to a guest account? |
Hi @felipepxavier, are you using wp-graphql-jwt-authentication? Might be worth checking what does |
@jonlovera, thanks for the feedback! |
Hello, I have a specific rule if customer wants to checkout. My current WP settings require Delivery date as well as the time to place the order. But I couldn't find any docs related to these fields. Any help? Thanks in advance |
Hello, in our case, we were using the |
Is there a way to specify currency in |
Have you specified the currency in the WooCommerce settings? |
Yes I did, default currency for my WC is USD but I need to allow also EUR. |
@jonlovera I'm new to wpgraphql. And confuse how to usecreateOrder for guest checkout. do we also need jwt for this? do you mind to explain how to do it step by step? Because currently the documentation from @kidunot89 on this matter just give a clue it can be done without relying on WooCommerce's session management but doesnt explain how: https://github.com/wp-graphql/wp-graphql-woocommerce/blob/develop/docs/using-checkout-mutation-and-order-mutations.md#using-the-createorder-mutation |
Describe the bug
I am using graphql for create orders from the postman. queries are working fine but I can't run any mutations there is always customer capability error. I am also sending the Bearer token in header to authenticate the customer
To Reproduce
Steps to reproduce the behavior:
Content-Type:application/graphql Authorization:Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvd29vZ3JhcGhxbC5heGlzdGF5bG9yLmNvbSIsImlhdCI6MTU3MDAyMTg1OCwibmJmIjoxNTcwMDIxODU4LCJleHAiOjE1NzAwMjIxNTgsImRhdGEiOnsidXNlciI6eyJpZCI6IjMifX19.7drzb9beicfl-SqbPZvzseBGoY4Cf30eoS0x1wyGQIE
Expected behavior
The order should be created
Screenshots
Request Screenshot
Screenshot 2
Screenshot 3
The text was updated successfully, but these errors were encountered: