• Resolved sembarelds

    (@sembarelds)


    Hi!

    I am trying to programmatically add a woocomerce product to my bundle based on certain conditions, my guess was using the “woocommerce_bundled_items” filter and adding a WC_Bundled_Item object to the bundled_items variable, but i can not figure out how to convert a WC_Product class into a WC_Bundled_Item class. Is this even possible?

    Example:

    // First we hook our own function with the_content event
    add_filter( 'woocommerce_bundled_items', 'wpb_content_filter', 10, 2 );
      
    // Now we define what our function would do.
    // In this example it displays an image if a post is in news category.
    function wpb_content_filter( array $bundled_items, WC_Product_Bundle $bundle ) {
        $product = wc_get_product( 180 );
        $t = new WC_Bundled_Item($product);
        $bundled_items[] = $product;
        // Returns the content.
        return $bundled_items;
    }
    • This topic was modified 1 year, 6 months ago by sembarelds.
Viewing 1 replies (of 1 total)
  • Hi there @sembarelds ??

    Thank you for contacting Woo support!

    Programatically add woocommerce product to bundle

    array $bundled_items, WC_Product_Bundle $bundle

    From what I gather, you are referring to Product Bundles. Correct?

    Feel free to check out the filter reference (linked here), as a first step, along with the developer resources section in the documentation (linked here).

    Per this pinned thread, if you are needing help with customizations or troubleshooting WooCommerce and do not have a developer or company you can depend on, then we’ve got recommendations for you.

    Visit https://woocommerce.com/customizations/ to find the right agency or developer for your specific needs.

    I trust that points you in the right direction, but if you have more questions, let us know.

    We’re happy to help.

Viewing 1 replies (of 1 total)
  • The topic ‘Programatically add woocommerce product to bundle’ is closed to new replies.