woocommerce rest API request for purchase single product - wordpress

New to woocommerce ,i develop a sale file app , i decide to use woocommerce rest API i can show products
/wc-api/v2/products
I know how can add to order
/wc-api/v2/orders
How can add product to cart and checkout and connect to bank gateway?

The cart is part of a session and is saved in the MySQL table wp_woocommerce_sessions. This table is accessed using a WC_Session_Handler object. AFAIK the WooCommerce REST API does not provide access to WC_Session_Handler objects.
I don't understand exactly what you are trying to do but if you want to access the cart through the REST API I think you will need to implement your own REST controller for the wp_woocommerce_sessions table. This isn't that difficult to do as you can modify one of the existing WooCommerce REST controllers to work with WC_Session_Handler objects to access the wp_woocommerce_sessions table.
But, beware a WooCommerce session is bound to a browser session through cookies and you need to handle that binding.

Related

Is it possible to filter the orders that are visible via WooCommerce REST API?

We are running a WooCommerce shop and want to make our orders available to an external shipping contractor via the WooCommerce REST API.
However, not all orders are relevant to this contractor and he should not be able to access orders with only virtual products due to security and privacy reasons.
Is there a filter available where I can hide these orders from the REST API? I know how to do the filter, I just don't know if the right filter hooks exists to only filter posts (orders) accessed via the REST API. The WooCommerce Docs are not very clear on that subject. Thanks!

WooCommerce Subscriptions: Changing payment method of existing subscription

A client of mine wants to change payment service provider in his WooCommerce store. He has a few hundred existing subscriptions that need to be transferred to this new PSP. Basically, everything is done in order to do this, except for the configuration in WooCommerce. WooCommerce needs to know to use the new payment plugin's code to renew subscriptions. I know of the existence of this integration method but that's not the issue. That integration allows you to add the required metadata to orders (like credit card tokens) in the WooCommerce UI. That has already been done. I changed the _payment_method post meta of a test subscription to my payment method identifier and I set _requires_manual_renewal identifier to false however, for some reason in the UI it still says Manual Renewal under payment method.
What things do I have to change in the database in order to change the payment method?

React + Wordpress + Woocommerce REST API 401 - get products without AUTH

I am building a webshop with React, Wordpress v4 and Woocommerce Rest api v2.
I am a bit confused on how to proceed with authentication. I understand that for some requests like place an order or create a new product I need to authenticate.
But I also need to be able to just retrieve all products for a customer who visits the site for the first time and just wants to browse through all our products.
What is the best practice here?
My thoughts are:
Create a public, separate layer with PHP or Node which securely stores the Woocommerce API keys and provides public endpoints (only GET, i.e. GET /products)
Access those endpoints via JS/React and render the products
Create another separate layer for placing orders which requires the costumer to authenticate (i.e. POST /orders)
Also, instead of adding a separate layer I could use the Wordpress function add_action( 'rest_api_init',...
Is there a better way to do it or am I missing something? Or can I retrieve the Woocommerce Products somehow via the Wordpress API endpoints without api keys?
Okay, somehow I was thinking the wrong way. As wordpress lists all products which were created in woocommerce as a regular Wordpress post with post-type product, I just have to make a request to the Wordpress API (NOT the Woocommerce API!), in my example:
http://laflor.wordpress.local/wp-json/wp/v2/product

How to notify .net api from WordPress WooCommerce when there is a new order

I have .net webapi that also integrated with WooCommerce .NET wrapper. Also I have a WordPress store runs on WooCommerce.
What I am trying to do is, as soon as there is a new order on the website, I want to notify my webapi with that order so I can save that order on other application.
I am able to use WooCommerce api to get orders, products etc.. but I want that the WooCommerce api post me the data when there is a sale. Or at least notify me with order id so I can go ahead and get that order with that order id from my .net application.
I have searched a lot but all I find is consuming the WooCommerce api. But I couldn't find anything that WooCommerce notifies my api.
I also checked the web hooks, but I didn't get it. There is a delivery url. From my understanding, for a created action, it hits that delivery url, but what it posts? Json object? I couldn't find any explanation for that. I am kind of new to WooCommerce.
Is this possible? Is there any example for this or any documentation about what I am trying to do.
You can use the following code in your WooCommerce store/setup (theme's functions.php preferable).
// add the action
add_action( 'woocommerce_new_order', 'action_woocommerce_new_order', 10, 3 );
function action_woocommerce_new_order($order_id){
// Do what ever with the order id, send mail or call your API
}

Add user on UrBackup server after order on Woocommerce site

I have wordpress site with woocommerce shop and I’m selling among others UrBackup client accounts on my server.
Do you have any idea how to automatically add UrBackup user after order in woocommerce?
Or maybe easier will be create shop based on different engine?
Any advice, tips? :)
After poking around a bit, it looks like UrBackup has an API you can use, that most likely has a 'create account' endpoint. I didn't see it immediately in their not-so-great documentation, but you'd think it'd HAVE to be there somewhere! There's also a PHP API kit you could integrate into your WordPress site here:
https://bitbucket.org/opensaucesystemsdevelopment/urbackup-api.git
So, you could load in this class, and after a WooCommerce order is placed, call the API endpoint to create a user. To do this with WooCommerce, you'd need to create a function on the "woocommerce_order_status_completed" hook.
http://hookr.io/actions/woocommerce_order_status_completed/
This would let you run any custom code you'd like after an order's payment has completed. Thus, you could check an order for if it contains the UrBackup product, and if so call the UrBackup API to create an account based on the current user's data.
Should work!

Resources