How to do it...

Follow these steps to register a new product type with WooCommerce:

  1. Open the wpcookbookchapter9.php file of the new WPCookbook Chapter 9 plugin in the code editor.
  2. Add the following code to register a new WooCommerce product type called Support Packages:
add_action( 'plugins_loaded', 'wpccp_chapter9_register_product_type');function wpccp_chapter9_register_product_type() {    if(class_exists('WC_Product')){        class WC_Product_Simple_WPCCP_Support_Package extends          WC_Product {            public function __construct( $product ) {                $this->virtual = 'yes';                $this->downloadable = 'yes';                parent::__construct( $product );            }            public function get_type( ) {                return 'simple_wpccp_support_package';            }        }    }}// Step 3 code should be placed after this line

Get WordPress 5 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.