How to add a new product type on woocommerce product types? [closed]

The add to cart template is only 1 of the many things you’ll need to do. Each product type has it’s own class in the /includes/ folder. Each one extends the WC_Product class.

To add items to the list you’ve screencapped (which is on the admin side and not the front-end, unlike the add-to-cart.php template, you will need to filter product_type_selector.

add_filter( 'product_type_selector', 'wpa_120215_add_product_type' );
function wpa_120215_add_product_type( $types ){
    $types[ 'your_type' ] = __( 'Your Product Type' );
    return $types;
}

then you’ll need to declare your product class. The standard naming system is WC_Product_Type_Class so in this example it would be:

class WC_Product_Your_Type extends WC_Product{
    /**
     * __construct function.
     *
     * @access public
     * @param mixed $product
     */
    public function __construct( $product ) {
        $this->product_type="your_type"; // Deprecated as of WC3.0 see get_type() method
        parent::__construct( $product );
    }

     /**
     * Get internal type.
     * Needed for WooCommerce 3.0 Compatibility
     * @return string
     */
    public function get_type() {
        return 'your_type';
    }
}

You are asking a very complicated question and I can’t provide a more complete answer. Hopefully this sets you on the right path. I highly encourage you to read the code in WooCommerce. It is very well commented and you can see how they are handling the different product types.

Edit Added WC3.0 compatibility to product type class.

Leave a Comment