Please submit a private ticket if you need to share sensitive information, such as license details and admin credentials.

Okay
  Public Ticket #3711724
Compatibility between WPC composite products and WPC grouped products
Open

Comments

  • Martina started the conversation

    I’m trying to use both plugins WPC composite products and WPC grouped products in combination with each other. Specifically, I would need to be able to insert some composite products into a grouped product, but at the moment this option is not working.

    Could you tell me how to proceed to resolve the problem?

  •  1,226
    Dustin replied

    Hi Martina,

    You can add composite products to a group by adding the custom code below. (How to add custom code? ↗):

    add_filter( 'woosg_product_types', function ( $types ) {
        unset( $types['composite'] );
        unset( $types['wooco'] );
        return $types;
    } );

    However, you can't add a grouped product to the composite. Each component product in a composite must be purchasable so that the buyer can choose.

    Best regards,
    Dustin

  •   Martina replied privately
  •  1,226
    Dustin replied

    I've updated the snippet, and it works fine now: https://inbusta.altervista.org/prodotto/menu-benessere-prova/

    However, composite products are required to have selected component products before being added to the cart. So, it would be best if you didn't show the add-to-cart button on the grouped products:

    2607036788.png

    Please recheck it https://inbusta.altervista.org/prodotto/menu-benessere-prova/

    -----

    Updated snippet:

    add_filter( 'woosg_product_types', function ( $types ) {
        return array_diff( $types, [ 'composite', 'wooco' ] );
    } );

    Best regards,
    Dustin

  • Martina replied

    Perfect, thank you very much, I see it works now!

    However, within the groped product I would like to give the user the possibility to vary the ingredient of the composite product, as shown in the photo of your plugin screenshots (I attach it)

    Can you update it so that the view looks like that? 

    Thank you

    Attached files:  Screenshot 2024-08-29 alle 20.45.24.png

  •  1,226
    Dustin replied

    Adding a variable product to a group will show an attributes selector like that (https://demo.wpclever.net/woosg/product/smart-grouped-product-01/). However, we can't implement the same behavior for composite products. A composite has a products selector—not an attributes selector.

    Our plugins do not support combining grouped and composite product types. We can only display selected composite products in a group so buyers can open and buy them individually. You can also use the WPC Smart Quick View (https://wordpress.org/plugins/woo-smart-quick-view/), and buyers can open these composite products in a quick view popup without being redirected to another page.

    Best regards,
    Dustin

  •   Martina replied privately
  •  1,226
    Dustin replied

    Please add the custom code below. (How to add custom code? ↗):

    add_filter( 'woocommerce_get_price_html', function ( $price, $product ) {
        if ( class_exists( 'WPCleverWooco' ) && $product->is_type( 'composite' ) && ( $components = $product->get_components() ) ) {
            $product_id   = $product->get_id();
            $custom_price = stripslashes( get_post_meta( $product_id, 'wooco_custom_price', true ) );
            if ( ! empty( $custom_price ) ) {
                return $custom_price;
            }
            if ( $product->get_pricing() !== 'only' ) {
                $price = $product->get_pricing() === 'include' ? wc_get_price_to_display( $product ) : 0;
                foreach ( $components as $component ) {
                    if ( ( $component['optional'] === 'no' ) && ! empty( $component['default'] ) ) {
                        // required and has default product
                        if ( is_numeric( $component['default'] ) ) {
                            // id
                            $product_default = wc_get_product( $component['default'] );
                        } else {
                            // sku
                            $product_default = wc_get_product( wc_get_product_id_by_sku( $component['default'] ) );
                        }
                        if ( ! empty( $component['price'] ) ) {
                            // has new price
                            $price += wc_get_price_to_display( $product_default, [
                                'qty'   => $component['qty'],
                                'price' => WPCleverWooco::get_new_price( $product_default->get_price(), $component['price'] )
                            ] );
                        } else {
                            $price += wc_get_price_to_display( $product_default, [
                                'qty' => $component['qty']
                            ] );
                        }
                    }
                }
                return wc_price( $price );
            }
        }
        return $price;
    }, 999, 2 );

    Then, the composite's price will be calculated from the default product that you set in each required component:

    1773713415.png


    Best regards,
    Dustin