Register WooCommerce new product type within a class

Viewed 15

This is the action that registers a new product type in woocomerce:

// Register product type
add_action( 'init', 'register_new_product_type' );
function register_new_product_type() {

    class WC_Product_Demo extends WC_Product {  
      
        public function __construct( $product ) {
            $this->product_type = 'the_new_type';
            parent::__construct( $product );
        }

    }

}

I am trying to wrap this action in class like this:

// Register product type
class __register_product_type{

    function __construct(){
        add_action( 'init', array( $this, 'register_new_product_type' ) );      
    }
    
    function register_new_product_type() {

        class WC_Product_Demo extends WC_Product {   
     
            public function __construct( $product ) {
                $this->product_type = 'the_new_type';
                parent::__construct( $product );
            }

        }

    }

}

But it is throwing a fatal error. How could I wrap the registration action inside the class?

0 Answers
Related