• Resolved Howdy_McGee

    (@howdy_mcgee)


    Hello,

    I’m trying to extend WC_Product_Variable to create my own variable product type but am having trouble. I can show attributes on the custom product type but it doesn’t show the checkbox to “Use for Variations”. Looking at the WooCommerce code, it specifically has static a class show_if_variable which, while my product type is variable it’s not specifically called “variable”. Is there a resource, tutorial, or do you have any guidance on what I’m doing wrong when creating my own Variable product type? Here’s the code I’m using below:

    /* Create new product type class */
    function custom_product_types() {
    	
    	Class Item_Registration_Variable extends \WC_Product_Variable {
    		
    		public function __construct( $product = 0 ) {
    			
    			$this->product_type = 'item_registration_variable';
    			parent::__construct( $product );
    			
    		}
    		
    		public function get_type() {
    			return $this->product_type;
    		}
    		
    	}
    	
    }
    add_action( 'init', 'custom_product_types' );
    
    /* Append product type to select */
    function append_custom_product_types( $product_types ) {
    	
    	return array_merge( $product_types, array(
    		'item_registration_variable' => esc_html__( 'Item Registration' ),
    	) );
    	
    }
    add_filter( 'product_type_selector', 'append_custom_product_types' );
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom Variable Product Type’ is closed to new replies.