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.

Read More

Is there a way I can achieve that ?

Related posts

5 comments

  1. 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.

  2. /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?

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

    require __DIR__ . '/vendor/autoload.php';
    
    use AutomatticWooCommerceClient;
    
    $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>";
    
    
  4. 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

Comments are closed.