Setting Up a WooCommerce Catalog Using a Custom Post Type

In a recent Business Bloomer Club Slack thread, a member asked about setting up a WooCommerce store using a custom post type (CPT) for products. The goal was to create a display-only catalog for an existing site, where the products had been initially structured as a custom post type instead of WooCommerce’s standard product post type.

While WooCommerce typically uses its built-in product post type for compatibility with its functionalities, adapting a CPT for product display can be beneficial for certain catalog-style setups. Here’s a guide on how to achieve this configuration and considerations to keep in mind.

Why Use a Custom Post Type for Products?

Some sites may already have products or catalog items as custom post types before WooCommerce integration was needed. In these cases, transitioning to WooCommerce’s built-in product post type could be a significant undertaking, especially if the existing CPT is deeply embedded within the site’s architecture or content strategy.

By setting up WooCommerce to recognize an alternative post type for products, you can retain the existing content structure while gaining WooCommerce’s display and catalog capabilities.

Implementing a Custom Post Type for WooCommerce Products

Step 1: Modify the WooCommerce Data Store

WooCommerce uses a specific data store class, WC_Product_Data_Store_CPT, to manage product data as a custom post type. To link WooCommerce with a different post type:

  1. Extend the Data Store Class: Use WC_Product_Data_Store_CPT as a foundation and modify it to recognize the desired custom post type. This involves duplicating or extending the class and adjusting the post_type attribute within the code.
  2. Specify the New Data Store: Register the custom data store with WooCommerce to replace the standard product post type. This can often cover around 80-90% of the work, allowing WooCommerce to interact with your CPT as though it were its own product type.

Step 2: Consider Plugin Compatibility

While this approach may work well with WooCommerce itself, many plugins and themes are hard-coded to expect the default product post type. Plugins like page builders or certain WooCommerce add-ons may not recognize custom data stores or post types without additional modifications.

Step 3: Configure a Display-Only Catalog

If your client needs a display-only catalog (i.e., no purchasing), plugins can achieve this without changing the underlying post type. Alternatively, setting WooCommerce to catalog mode or using code snippets can disable the purchase functionality while keeping the display intact.

Final Considerations

Working with custom post types in WooCommerce requires careful testing to ensure compatibility with existing plugins, themes, and WooCommerce’s core functionality. This approach can offer flexibility for catalogs and unique product displays, provided the WooCommerce data store and potential plugin conflicts are managed effectively.

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

Reply

Your email address will not be published. Required fields are marked *