usvi4me
usvi4me

Reputation: 21

WooCommerce Rest API

The below code looks for categories in the products directory. How can I change this code to first look in products/categories and if null, look in shop/categories.

I need this to work in products/categories as well as shop/categories.

The code below works great on a WooCommerce website. However when the Dokan Plugin is installed, Dokan redirects product/categories to shop/categories.

Can anyone point me in the right direction?

echo json_encode($response);

} elseif ($tag == 'viewCategoryList') {

    try {

       echo json_encode($woocommerce->get('products/categories'));

    } catch (Exception $e) {

        $response["error"] = 1;

        $response["success"] = 0;

        $response["message"] = "Invalid Product Id";

        echo json_encode($response);
    }

Upvotes: 1

Views: 431

Answers (2)

usvi4me
usvi4me

Reputation: 21

Finally got it working. This is what worked!

} elseif ($tag == 'viewCategoryList') {

        try {
            if (!empty($response['product_categories']))
            {
                echo json_encode($woocommerce->get('shop/categories'));       
            }           
        }

        catch (Exception $e) {

            $response["error"] = 1;

            $response["success"] = 0;

            $response["message"] = "Invalid Product Id";

            echo json_encode($response);
        }

Upvotes: 1

Benoti
Benoti

Reputation: 2200

With the links you provide in comments, I found one mistake about the protocol of the url if the form action, as your domain is https, http must be https

<form action="https://vimarketplace.com/?getrequest" method="post">

You need to set up your script to enable ssl_verify (but if you didn't touch the value is true).

When you active Dokkan, in the wizard, leave the first field empty (you maybe setted up to shop, default is store). Maybe...

Upvotes: 0

Related Questions