Programatically add woocommerce product to bundle
-
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; }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Programatically add woocommerce product to bundle’ is closed to new replies.