I thought I’d share my solution for anyone working on a similar problem. I ended up switching to node-wpapi and using REST Autodiscovery to enable use of the WooCommerce & WordPress APIs from a single library. This can be done like so:
const wpapi = require('wpapi')
let wp = new wpapi({
endpoint: 'http://your.wp.site/wp-json/',
username: 'user',
password: 'pass',
auth: true,
routes: routes
})
let woo = wp.namespace('wc/v2')
Where routes
is a JSON representation of the REST API routes. See here for information on bootstrapping the API wrapper.
I’m then able to use both APIs side-by-side
wp.users()
.search('foo') // Search by (for example) username
.param('context', 'edit') // Get additional fields
.then(result => {
let user = result[0]
woo.customers().id(user.id) // Get WooCommerce specific fields
.then(customer => {
console.log('woo.customer', customer)
})
})
Related Posts:
- How to stop a Gutenberg Block from firing multiple GET Requests?
- List of JS events in the WooCommerce frontend
- WooCommerce: Can’t use wc_get_products for custom REST API endpoints
- Process checkout using WC REST API
- How to build a plugin that supports authenticated POST requests to the REST API from external servers?
- Extend Woocommerce rest api routes fails
- Hide Add to Cart Button
- using woocommerce_template_single_add_to_cart in shop-loop – javascript issues [closed]
- How to filter Post using Meta Data REST API
- Output JSON object with woocommerce products
- Problem with cURL and rest API
- Woo API REST : product variation price is read-only?
- “Cannot read property ‘replace’ of undefined” Javascript error when trying to add attribute terms from add product page [closed]
- Category Tree In WooCommerce Product API
- How to upload Woocommerce product images via API? [closed]
- Javascript / Ajax Error After Migrating To New Domain Name
- How can i stop woocommerce checkout event based on api request result?
- How to handle Woocommerce API credentials
- What will make Woocommerce REST API to issue 401 [closed]
- adding a script with type=”module” to woocommerce admin area
- Woocommerce custom endpoints
- Woocommerce REST API – updating an order changes custom tax calculations
- Force uppercase on some WooCommerce checkout fields input
- Woocommerce Rest Api Categories problem [closed]
- API returns blank response after installing & uninstalling WP-rest-api plugin
- woocommerce axios react
- Get specific values in Woocommerce Rest API
- Javascript error when adding an item to the cart [closed]
- wc_get_products() not return the images details
- WooCommerce – Add product with image via REST API
- Tax are not showing on order while placing order with REST API
- JWT on Woocommerce cannot work with “Customer” role user
- Woocommerce REST API – add filter to set maximum query per page for product brands [closed]
- WooCommerce – Create multiple product tags via rest api endpoint
- Add to cart – button should be disabled
- Retrieve Data from Custom Endpoint
- Woocommerce variable product’s total amount by javascript
- Ajax add to cart not updating Elementor mini cart totals
- Trying to run Javascript on AJAX call
- List of JS events in the WooCommerce frontend
- Woocommerce Checkout Page Total Price Inside Google Pay Script
- Running JavaScript after using WooCommerce Filter Plugin
- Deregister dequeue JS scripts except on 1 product page
- How to solve `Error getting remote image` in woocommerce rest api script?
- woocommerce deposit Form with AJAX and shortcode won’t update but add to previous output
- Getting in an exception for get product detail by id in woocommerce REST api
- How to make wocommerce shop products same heigt
- Impossible to create a new WooCommerce customer using Rest API
- Woocommerce API security concerns
- How can I send information when a order is completed to my own POS?
- Format number to 2 decimal places
- Woocommerce Rest API: woocommerce_product_invalid_image_id
- WC Booking query bookings with date ranges
- “error_message”: “Sorry, you cannot list resources.” using WooCommerce API
- currentURL is not defined
- Retrieve Woocommerce Cart Url with javascript/jquery [closed]
- Woocommerce REST API: creating variations
- Woocommerce REST API not considering discounts and coupons
- How to insert link, with lightbox, that opens specific page content only
- Woocommerce custom product with JS script, can’t understand how it works [closed]
- WooCommerce REST API endpoints don’t exist
- Removing ‘woocommerce-no-js’ class from body
- Fetch products with filter by similar categories at same time
- Send data to external websites when there is an update or create a post
- Auto generating API keys using the Application Authentication Endpoint [closed]
- GET woocommerce order request is not showing meta data [closed]
- How do I fix this “Uncaught ReferenceError: woodmartThemeModule is not defined”?
- Woocommerce My Account Endpoint – how to get ID parameter from URL?
- How to add Woocomrce cart page shipping calculator to my country state list
- Button to update order status Woocommerce with WC Marketplace
- Variation name in $product->get_name()
- WordPress keeps moving my widgets to other widget areas
- How to add material design css in wordpress and woocommerce
- how to remove or disable woocommerce order review in checkout page?
- WordPress and WooCommerce – How many products are too many? [closed]
- How to get woocommerce selected variation from order object
- Woocommerce cart is not clear after logout
- WooCommerce event works in jQuery but not in JavaScript
- Customizing WooCommerce
- Get Post ID from attachment ID (Redirect to product page)
- Woocommerce product tab is not showing probably
- How to list best seller products in woocommerce
- Sharing data between filters on a snippet (user specific) for Woocommerce
- How to add custom checkboxes from loop to WooCommerce product variation options?
- Woocommerce doesn’t work with theme, header missing and css messed up
- Woocommerce Product Variation – Add Price Logic
- Update block once an API request returns with a value
- Can’t update WooCommerce payment method title
- Set Post Thumbnail to external URL
- WooCommerce related products load random posts per page
- how to show product custom taxonomies in woocommerce rest api
- WooCommerce: Adding a setup fee to certain products
- Adding more than one item to Woocommerce cart
- Woocommerce – get product in category with specific attribute
- How to add a menu page for options in wordpress for user that has the role of vendor?
- Testimonials/Reviews for Products
- Override function
- Updating order meta to have a meta entry from an item in the order
- Change variants URL
- Use a woocommerce hook to create a table and populate it with a query