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
        }
    }
}
                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);  
                        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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With