Sync Data

Woocommerce: Sync Data

Customising product data #

In WooCommerce you can add custom product attributes through the WooCommerce backend, or through the Clerk.io plugin in code, if needed.

Adding Simple Attributes #

If the attributes you want to send are already available as simple attributes in your WooCommerce admin, they can easily be added on the Plugin page.

1. In your WooCommerce backend, start by going to Products -> Attributes

2. In here, find the slug of the attribute you want to add.

3. Now go to Clerk -> Settings .

4. Under Additional Fields, add the attribute slug. You can also add several different ones, separated by comma:

5. Scroll to the bottom of the page and click Save Settings:

6. After implementing your attributes, go to my.clerk.io->System Status -> Data Sync and click Start New Data Sync in the upper right corner.

If the attributes you want to send are already available as part of your configurable/grouped products data in your WooCommerce admin, they can easily be synced on the latest version of your plug-in. They will appear as child_attribute, for example, child_color, child_skus etc.

Adding attributes through code #

Attributes in WooCommerce can also be added in code, through two files, as they are used to sync products manually and automatically when changes are made in the webshop.

These are the files:

wp-content->plugins->clerkio->includes->class-clerk-product-sync.php

in the function add_product

wp-content->plugins->clerkio->includes->class-clerk-rest-api-php

in the function product_endpoint_callback in $productArray

Each attribute is structured like this:

'sku'   => $product->get_sku(),

where ‘sku’ defines the name you want it to have in Clerk.io, and => $product->get_sku(), is a WooCommerce logic for pulling the attribute.

Adding Product Data Using functions.php #

New attributes can also be added to Clerk.io by changing the file functions.php, and will not be overwritten when the plugin is updated.

Add the following code to the WooCommerce backend to Appearance > Theme Editor > functions.php :

// Alters clerk parameters
add_filter( 'clerk_product_sync_array', 'clerk_change_params', 10, 2 );
add_filter( 'clerk_product_array', 'clerk_change_params', 10, 2 );

function clerk_change_params( $params, $product ) {

// Used to hide hidden products from search
   $params['catalog_visibility'] = $product->get_catalog_visibility();

// We only use short_description
   $params['description'] = $product->get_short_description();

    return $params;
}

Finally, go to my.clerk.io -> System Status -> Data sync and click Start New Data Sync to import your new attributes.

Choosing products to import #

Per standard, Clerk.io’s WooCommerce plugin only imports Published products.

This can be changed if needed.

The following file controls which products are imported to Clerk.io:

wp-content->plugins->clerkio->includes->class-clerk-rest-api.php.

In the file, locate the function called product_endpoint_callback.

In the $products list, under ‘status’ simply add any Status that you want to include, separated by commas:

If you do this, we strongly recommend that you also add an extra attribute which indicates when a product is not saleable, so you can show it in your Design. Assuming you create an attribute called is_saleable which is either true or false, you can use it like this in Designs:

{% raw %}
{% if product.is_saleable %}
   <div class="in-stock">In Stock</div>
{% else %}
  <div class="not-in-stock">Not In Stock</div>
{% endif %}
{% endraw %}

Then go to my.clerk.io -> Data and click Start New Sync to import the new products.

Deactivate order sync #

After the first data sync has run successfully, order sync from WooCommerce can be deactivated as the sales-tracking from the extension takes over.

To deactivate order sync, go into your Wordpress backend, go to Clerk in the left bar menu and click Clerk Settings:

Next, scroll down to the headline called Synchronization (in your language) and tick the box next to “Deactivate Order Synchronization”, like this:

To make the changes take effect, scroll to the bottom of the page and press Save:

Syncing content pages when using other webshop platforms #

From v4.1.7 of our WordPress Plugin you have the ability to sync pages, posts and other blog content to any Clerk store.

Since a store in Clerk.io is primarily connected to your e-commerce platform in order to share information on catalogs, orders and customers, it can be challenging to keep your blogging content in sync with Clerk if it is not managed on that platform.

Because of this, we now provide a no-code solution for keeping this content in sync with any Clerk store regardless of primary platform, if you manage your blogs through WordPress/WooCommerce.

In order to use the feature, simply install our plugin on your WordPress site. In the module settings you should then configure your API keys, taken from the store in my.clerk.io you wish to sync your content with.

Since we only want to import written content in this case, you should only need to enable Use Real-time Updates in the Data Sync: Pages section.

After saving the settings you will see a button to the right of the checkbox, with the text Sync Pages. You can press this to immediately push all the pages to the my.clerk.io store.

You can also enter additional attributes you wish to retrieve for the pages in question, as well as the inclusion of custom page types you may have created using third party plugins.

You should only need to press the Sync Pages button once, as any change to a page, publication of a new page, archival or deletion of one will be caught by our plugin and updated in the my.clerk.io store automatically.

If you wish to ensure that no pages are pulled from any other source during the nightly sync for the store, we also recommend turning the full sync for pages off in my.clerk.io.

This can be done in System Status -> Data Sync, by turning Import Pages off.