Hello MJ,
The “Subscription” product type doesn’t exist in WooCommerce basic plugin. It must have been added by another plugin, and unfortunatly Booking Activities doesn’t support it.
I will add hooks to allow third parties to set their own product type as “Activity”. But there is no guarantee it will be working since each product type may have its own way of processing things.
You will need to wait for Booking Activities 1.7.8 to go further. Else, you can use a development version:
1. Download a development release here
2. Extract it
3. Rename the folder from “booking-activities-dev” to “booking-activities”
4. Replace the old “booking-activities” folder via FTP in wp-content/plugins
5. Clean your browser cache
Then, add this code to your child theme’s functions.php:
// Allow 'simple_subscription', 'variable_subscription' and 'variation_subscription' product types to be flagged as "Activity"
function my_theme_product_is_activity( $is_activity, $product ) {
if( ! is_object( $product ) ) { return false; }
if( $product->is_type( 'simple_subscription' ) ) {
$is_activity = get_post_meta( $product->get_id(), '_bookacti_is_activity', true ) === 'yes';
} else if( $product->is_type( 'variation_subscription' ) ) {
$is_activity = get_post_meta( $product->get_id(), 'bookacti_variable_is_activity', true ) === 'yes';
} else if( $product->is_type( 'variable_subscription' ) ) {
$variations = $product->get_available_variations();
foreach( $variations as $variation ) {
if( empty( $variation[ 'bookacti_is_activity' ] ) ) { continue; }
$is_activity = $variation[ 'bookacti_is_activity' ];
break;
}
}
return $is_activity ? true : false;
}
add_filter( 'bookacti_product_is_activity', 'my_theme_product_is_activity', 10, 2 );
function my_theme_product_booking_form_id( $form_id, $product_id, $is_variation ) {
$product = wc_get_product( $product_id );
if( ! $product ) { return $form_id; }
if( $product->get_type() === 'variation_subscription' ) {
$form_id = get_post_meta( $product_id, 'bookacti_variable_form', true );
} else if( $product->get_type() === 'simple_subscription' || $product->get_type() === 'variable_subscription' ) {
$form_id = get_post_meta( $product_id, '_bookacti_form', true );
}
return $form_id;
}
add_filter( 'bookacti_product_booking_form_id', 'my_theme_product_booking_form_id', 10, 3 );
function my_theme_product_form_attributes( $form_atts, $product ) {
if( $product->is_type( 'simple_subscription' ) ) {
$form_atts[ 'id' ] = 'product-' . $product->get_id();
}
else if( $product->is_type( 'variable_subscription' ) ) {
$default_attributes = bookacti_get_product_default_attributes( $product );
if( $default_attributes ) {
$form_atts[ 'data-variation-id' ] = bookacti_get_product_variation_matching_attributes( $product, $default_attributes );
$form_atts[ 'data-default-variation-id' ] = $form_atts[ 'data-variation-id' ];
if( $form_atts[ 'data-default-variation-id' ] ) {
$form_id = get_post_meta( $form_atts[ 'data-default-variation-id' ], 'bookacti_variable_form', true );
if( $form_id ) {
$form_atts[ 'id' ] = 'product-variation-' . $form_atts[ 'data-default-variation-id' ];
}
}
}
} else if( $product->is_type( 'variation_subscription' ) ) {
$form_atts[ 'data-variation-id' ] = $product->get_id();
$form_id = get_post_meta( $form_atts[ 'data-variation-id' ], 'bookacti_variable_form', true );
if( $form_id ) {
$form_atts[ 'id' ] = 'product-variation-' . $form_atts[ 'data-variation-id' ];
}
}
return $form_atts;
}
add_filter( 'bookacti_product_form_attributes', 'my_theme_product_form_attributes', 10, 2 );
This code assume that:
– The “Simple subscription” product type has for ID: simple_subscription
– There are also “Variable subscription” product types and their IDs are ‘variable_subscription’ for the product, and ‘variation_subscription’ for the variations
– The “Simple subscription” product type works like a “Simple” product, the “Variable subscription” product type works like a “Variable” product and its variations too
If the product types IDs are incorrects, you just need to replace them in the code.
Regards,
Yoan Cutillas