4

I'm trying to create a custom variable product type from woocommerce for a booking form, which has different pricing based on a set of variables.

I've successfully added a custom product type. But how do i duplicate the same option that the variable product has for different attribute pricing. Can't seem to find any resources related with variable product types.

// add a product type
add_filter( 'product_type_selector', 'cpt_add_custom_product_type' );
function cpt_add_custom_product_type( $types ){
    $types[ 'booking_product' ] = __( 'Booking Product' );
    return $types;
}
add_action( 'plugins_loaded', 'cpt_create_custom_product_type' );
function cpt_create_custom_product_type(){
     // declare the product class
     class WC_Product_Wdm extends WC_Product_Variable {
        public function __construct( $product ) {
           $this->product_type = 'booking_product';
           parent::__construct( $product );
           // add additional functions here
        }
    }
}

2 Answers 2

5

I've managed to get part way - by adding back in the variation and attribute tabs. Next step is to add back in "Add as a Variation" option.

add_filter('woocommerce_product_data_tabs', function($tabs) {

            array_push($tabs['attribute']['class'], 'show_if_variable show_if_membership');
            array_push($tabs['variations']['class'], 'show_if_membership');

            return $tabs;

        }, 10, 1);  
Sign up to request clarification or add additional context in comments.

Comments

3

Dan Needham's answer is the first step you should follow and after that you should use this

function producttype_custom_js() {

if ( 'product' != get_post_type() ) :
    return;
endif;

?><script type='text/javascript'>
    jQuery( document ).ready( function() {
        jQuery( '.enable_variation' ).addClass( 'show_if_cus_producttype' ).show();
    });

</script><?php 
} 

add_action( 'admin_footer', 'producttype_custom_js' );

This will add the checkbox option Dan Needham has said is missing.

1 Comment

How to set template for custom product type?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.