Changing Bundles Rendering Behaviour – WC Product Bundles

WC Product Bundles ( wcpb ) is a worpress plugin for woocommerce, which allows you to combine two or more products together and sell them at a discounted rate.

By default Bundles will be displayed under product’s short description in the product’s single view. Wcpb allows you to configure certain option like you can determine whether to thumbnail for bundled items, overriding Title & short description.

Usually wcpb renders bundles item with the following skeleton.

<table class="wcpb-bundled-product">
    <tr>
        <!-- bundled product's thumbnail section -->        
        <td class="wcpb-thumbnail-td">				
            <!-- display thumnail -->
        </td>
        
        <!-- bundled product's summary section -->
        <td>
            <a href="" class="wcpb-bundled-product-title"><h1><!-- bundle title --></h1></a>
            <p class="wcpb-bundled-product-desc"><!-- short desc --></p>
            <p class="wcpb-bundled-product-stock"><!-- stock status --></p>
        </td>
    </tr>
</table>

Most of the time it’s enough, but what if you want to change the way of how wcpb rendering the bundles.? for that wcpb has an action called ‘wcpb/bundle/rendering’, before it starts to render bundled items, it check for a hook for that action, if it finds one then it triggers the action and stop rendering the bundles.

So this is where we override the bundles rendering behavior the way we want. ‘wcpb/bundle/rendering’ triggered along with the one parameter called ‘$bundles’ it’s an array of bundles, each bundle has the following properties.

{
    "quantity" : true,
    "price" : true,
    "thumbnail" : true,
    "tax_included" : true,
    "title" : true,
    "desc" : true,
}

by using ‘wcpb/bundle/rendering’ action you can render bundles like the following.

function my_custom_bundles_renderer( $bundles ) {

    foreach ( $bundles as $key => $value ) {
        $bundle = wc_get_product( $key ); 
        $product_url = "";
        if ( get_post_type( $key ) == 'product_variation' ) {
            $product_url = get_the_permalink( wp_get_post_parent_id( $key ) );
        } else {
            $product_url = get_the_permalink( $key );
        }
    ?>
    
    <ul>
        <li>
            <!-- bundled product's thumbnail section -->
            <?php if( $value["thumbnail"] == "yes" ) : ?>				
            
            <a href="<?php echo $product_url; ?>" title="<?php echo $value['title']; ?>" class="wcpb-featured"><?php echo $bundle->get_image( 'thumbnail' ); ?></a>					
            
            <?php endif; ?>
            
        </li>
            <!-- bundled product's summary section -->            
            <a href="<?php echo $product_url; ?>" class="wcpb-bundled-product-title"><h1><?php echo $value['quantity'] ." x ". $value['title']; ?></h1></a>
            <p class="wcpb-bundled-product-desc"><?php echo $value['desc']; ?></p>
            <p class="wcpb-bundled-product-stock"><?php echo ( $bundle->has_enough_stock( $value['quantity'] ) ) ? '<span class="wcpb-in-stock-label">instock</span>' : '<span class="wcpb-out-of-stock-label">out of stock</span>';  ?></p>            
        </li>
    </table>
    
    <?php

}
add_action( 'wcpb/bundle/rendering', 'my_custom_bundles_renderer' );

Happy Coding.!

Leave a Reply to johanna75 Cancel reply

Your email address will not be published.

 

13 Comment(s)

  1. Bill Jensen September 9, 2017

    I don’t know php and the above leaves out many details. I have tried out the plug in and there are several things that don’t work for me. We sell software – a base system plus four optional modules that I want to bundle at a reduced price. So I don’t want “In stock” to show. There will obviously only be one of each module in the bundle so I don’t want the quantities of each bundled product to show. (I tried leaving the quantity blank but an ugly X still shows.) The title of each of the parts of the bundle is the same size as the title of the bundle. It looks ugly. The description of each component includes http markup but the description is showing in plain text (showing the underlying coding.) I like this plug in and I would be willing to pay for a premium version if all of the above issues were addressed.

  2. Nick July 25, 2017

    Hello Saravana!
    This is an awesome plugin, although it seems that on our homepage the bundles products can’t be added to cart directly and instead it shows ‘Read More’.
    I would like to change the ‘Read More’ button to ‘Add to Cart’ if possible.
    What would I need to do?
    Thank you in advance.
    Kind regards!

  3. Rani June 13, 2017

    Hi,
    Am using this plugin .
    am getting 500 internal server error when adding variable product in bundles.

  4. Gerardo January 12, 2017

    This coding is to be added to functions.php? I can’t get it to work in my site.

  5. johanna75 January 10, 2017

    Hi,
    your plugin is fantastic!

    Just a question is it possible on the bundle product front end page to hide quantity of each child product?

  6. Scott December 29, 2016

    Hello, Saravana,

    This plugin is really great, help me a lot when setting my products, many thanks.

    Recently, I found there is a little problem. When a product, which is in my combo product, is out of stock, it still shows “in stock” in combo product page, and the combo product is still can be purchased. My woocommerce version is 2.6.11, wordpress version is 4.6.1.

    Could you tell me where and how I can fix this, or just wait for your next release? Thanks.

  7. Heinrich December 8, 2016

    I’m using this plugin along with the ‘WooCommerce Serial Key’ plugin, but I don’t get Serials when I bundle two downloadable products.
    Any Ideas?

  8. Veter November 26, 2016

    Hi ,

    is it possible to make customer unable to check out if either one product is Out of Stock ?

    Thanks You .

  9. Brian April 6, 2016

    Is it possible to add a variable product, not just one variation?

    1. Saravana Kumar K April 6, 2016

      HI brian, that support yet be added, we are preparing for next release with many upgrades. will be available soon.

      1. Andrew September 23, 2017

        Has this variable ability become available?

  10. Filipe July 7, 2015

    Hi, Saravana.

    Great extension.
    Have you already tried giving the user an option to set the product quantity? So, instead of the admin set the quantity, the user would be able to set it, using field, for example…
    I will try to code it.
    Do you think it is possible?

    Thank you.

    1. Saravana Kumar K July 9, 2015

      Filipe, yes that is possible, point noted, will try to include it in the next version.