• Resolved -MJ-

    (@mj-3)


    Hello

    I have the problem that if I place a product as a subscription product, I can not assign a booking form.

    Image: https://aviva24.de/ba-subscription-problem.png

    Is there a solution or is the problem known? What can I do, is there an approach?

    Many Thanks,
    MJ

    • This topic was modified 5 years, 4 months ago by -MJ-.
    • This topic was modified 5 years, 4 months ago by -MJ-.
    • This topic was modified 5 years, 4 months ago by -MJ-.
    • This topic was modified 5 years, 4 months ago by -MJ-. Reason: Typos and added image link
Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author yoancutillas

    (@yoancutillas)

    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

    Thread Starter -MJ-

    (@mj-3)

    Hello Yoan,

    thank you for quick response. I will give it a try and will reply later.

    Best wishes, MJ.

    Thread Starter -MJ-

    (@mj-3)

    Everything works at first glance in the backend. The ‘Activity’ tab is now available.

    However, the calendar will not load on the product page. I will take a closer look at this point.

    Plugin Author yoancutillas

    (@yoancutillas)

    The product types IDs are critical,
    I had no way to tell what they really are so I just used those placeholders: “simple_subscription”, “variable_subscription”, “variation_subscription”.

    This is basically the value returned by $product->get_type().
    For example,
    – for WooCommerce “Simple product” the product type ID is “simple” (woocommerce/includes/class-wc-product-simple.php line 33)

    You can find the value you needs in your subscription add-on code, or you can simply ask the add-on author.

    Regards,
    Yoan Cutillas

    Thread Starter -MJ-

    (@mj-3)

    Thank you very much Yoan.

    It works very well now.

    Can I install the next update (1.7.8) or should I wait and leave the developer version first?

    Best wishes, MJ.

    Plugin Author yoancutillas

    (@yoancutillas)

    Hello MJ,

    Ok perfect! thank you for your feedback.

    Yes you can install the next versions, the hooks are set up for good now.
    You may need to maintain this code in the future, but just like any custom codes.

    Regards,
    Yoan Cutillas

    Thread Starter -MJ-

    (@mj-3)

    Great, thank you.

    Only for the sake of completeness and for all later visitors the product_types here (in my shop) are:

    * Einfaches Produkt (simple product) – simple
    * Gruppiertes Produkt – grouped
    * Externes/Affiliate-Produkt – external
    * Variables Produkt – variable
    * Einfaches Abonnement – subscription
    * Variables Abonnement – variable-subscription

    (sry, only in german but it’s easily recognizable)

    MJ

    Plugin Author yoancutillas

    (@yoancutillas)

    Hello MJ,

    Thank you for that,

    However, the “variation” subscription product type is missing (it is different from the “variable-subscription” product type) (maybe “variation-subscription”?).
    I am afraid that it won’t work with variable subscription products if you don’t configure it too.

    Regards,
    Yoan Cutillas

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Booking Activities and WooCommerce Subscriptions Products’ is closed to new replies.