studioworks
studioworks

Reputation: 87

Wordpress REST API search products

Hope that you can help me.

I have a website that runs wooccommerce. I am using the woocommerce rest api. Now on another website what I want to do is create a simple search field where I type something and the search form needs to search through the woocommerce website and return results.

Is there a way I can achieve that ?

Upvotes: 8

Views: 10242

Answers (5)

Devner
Devner

Reputation: 7255

This works for me in 2021:

/wp-json/wc/v3/products?search={{productName}}

productName - refers to the input that you enter in the Search box

Upvotes: 2

Nantenaina
Nantenaina

Reputation: 11

If you use a wc-api-php (PHP library), please follow like this :

require __DIR__ . '/vendor/autoload.php';

use Automattic\WooCommerce\Client;

$woocommerce = new Client(
    'http://mydomain', // Your store URL
    'ck_****', // Your consumer key
    'cs_****', // Your consumer secret
    [
        'wp_api' => true, // Enable the WP REST API integration
        'version' => 'wc/v3' // WooCommerce WP REST API version
    ]
);

echo "<pre>";
print_r($woocommerce->get('products', ['search' => 'key word']));
echo "</pre>";

Upvotes: 1

Alex Rubio
Alex Rubio

Reputation: 1

/wp-json/wc/v2/products?search={{product_name}}

Is this function working if you are looking a exact product?

If you have a product like MR2050 and another with MR2050K, the result is not as you may expected, cause API rest will return 2 products, not just ONE?

Upvotes: 0

Amr Ezzat
Amr Ezzat

Reputation: 401

Try this:

/wp-json/wc/v2/products?search={{product_name}}

Works for me.

Upvotes: 11

Shankar Thiyagaraajan
Shankar Thiyagaraajan

Reputation: 1815

I think no. The New Version of WooCommerce API (v2) is supports id based calls. so instead you can get a list of abstract product details in your 2nd website and call back via product id.

Upvotes: 0

Related Questions