• Hi support team,
    I registered a custom product type which extends WC_Product_Variable class.

    In the backend, I can create custom product and set its attributes and variations.

    But on the front-end, I am getting

    This product is currently out of stock and unavailable.

    Here is my class:

    <?php
    
    class KNL_SHOP_WC_GIFTCARD_PROD_TYPE extends WC_Product_Variable {
    	public function __construct( $product = 0 ) {
    		parent::__construct( $product );
    	}
    
    	public function get_type() {
    		return 'knl_shop_giftcard';
    	}
    
    	/*public function is_purchasable() {
    		return apply_filters( 'woocommerce_is_purchasable', true, $this );
    	}*/
    
    	public function knl_shop_giftcard_add_to_cart() {
    		global $product;
    
    		$get_variations = count( $product->get_children() ) <= apply_filters( 'woocommerce_ajax_variation_threshold', 30, $product );
    		
    		wc_get_template('single-product/add-to-cart/giftcard.php',
    			$args = array(
    					'available_variations' => $get_variations ? $product->get_available_variations() : false,
    					'attributes'           => $product->get_variation_attributes(),
    					'selected_attributes'  => $product->get_default_attributes(),
    			),
    			$template_path = '',
    			KNL_SHOP_PATH . '/woocommerce/'
    		);
    	}
    }
    

    For template, I copied and renamed variable.php template.

    Any help will be appreciated.

    • This topic was modified 4 years, 4 months ago by assadnazar. Reason: template info added
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Custom Variable Product Type’ is closed to new replies.