Wordpress_intergration

1. Prerequisites

WooCommerce 3.5+.

WordPress 4.4+.

Dokan 2.8+

2. Wordpress Components (New)

├── pages
   ├── ...
   ├── account
   ├── blog
   ├── shop
   ├── index.jsx
├── wp-components
   ├── account
   ├── blog
   ├── elements
      ├── posts
      ├── products
         ├── ...
         ├── WPProduct.jsx
   ├── homepage
   ├── ...
├── utilities
   ├── WPhelpers.js
├── repositories
   ├── WP
      ├── WPPostRepository.js
      ├── WPProductRepository.js
      ├── WPRespository.js
      ├── WPVendorRepository.js
├── store
   ├── wp
      ├── action.js
      ├── reducer.js
      ├── saga.js

For wordpress, we used elements in wp-components

3. Data feching

3.1 Get data

NOTED: From now, we used React Hook instead. Please refer: React Hooks document

For example, if you want to get data for a section, do the following:

[...]
async function getSectionProducts(queries) {
        const queries = {
            per_page: 20
        }

        const WPProducts = await WPProductRepository.getProducts(queries);
        setProductItems(WPProducts.items);
    }

    useEffect(() => {
        getSectionProducts();
    }, []);

WPProductRepository.getProducts(queries) will send a request to Wordpress server, then receive the data.

In WPProductRepository, It used some enpoint, like this: 'wp-json/wc/v3/products'

It's Woocomerce parameters. You can refer it in Woocomerce API Document

3.2 Change API URL:

To change your server information, you need to edit it in the file: repositories/WPRespository.js, then change:

export const WPDomain = 'https://yourdomain.com';

Currently, we use basicAuth, it need usename/password. For generate it, please refer: Woocomerce API Authentication

4. Vendor with Dokan

Similar as Wordpress, please Dokan API document:

Dokan API Authentication

Last updated