Ecommerce Shopify WordPress Discussion

What shortcode will see the WooCommerce product I'm viewing and return the value/products inside the bundle-sells field?

I need to create a short code that access the WooCommerce product I'm currently viewing and fetches the products inside the Bundle-sells field so that I may insert the short code into a custom theme I am building. I started a short code, but it is not working, where am I going wrong? Now each product has a product data table and one of the menu tabs is "linked products". Inside exists the bundle-sells field which at the moment is filled with 3 other related products I want to display along with the original product once it's being view. Because I'm using a custom template this option doesn't work just by filling out the fields therefore, I have to manually bring them in by creating a short code and inserting this short code into my template. These are the 2 short codes I've come up with and don't work. 1st shortcode: function fetch_bundle_sells_products() { // Get the global product object global $product; // Get the current product ID $product_id = $product->get_id(); $product_object = wc_get_product( $product_id ); // Get the bundle-sells data $bundled_items = new WC_Bundled_Item_Data( $product_object ); // Check if there are any bundled items if ( ! $bundled_items->get_items() ) { return 'No bundled products found.'; } // Fetch each product in the bundle-sells array and generate HTML $bundled_products_html = '<ul>'; foreach ( $bundled_items->get_items() as $bundled_item ) { $bundled_product = $bundled_item->get_product(); if ( $bundled_product ) { // Generate an HTML list item with the product's name $bundled_products_html .= '<li>' . esc_html( $bundled_product->get_name() ) . '</li>'; } } $bundled_products_html .= '</ul>'; // Return the HTML list of bundled product names return $bundled_products_html; } // Register the shortcode with WordPress add_shortcode( 'bundle_sells', 'fetch_bundle_sells_products' ); 2nd shortcode: function fetch_bundle_sells() { // Get the global product object global $product; // Get the current product ID $product_id = $product->get_id(); $type = $product->get_type(); $output = ''; if($type == 'bundle'){ $name = $product->get_name(); $regular_price = $product->get_price(); $price = $product->get_regular_price(); $sale_price = $product->get_sale_price(); $output .= '<ul class="bundle-detail">'; $output .= '<li class="bundle-sale-price"><b>Bundle Price : </b>'.$sale_price.'</li>'; $output .= '<li><b>Bundle Title : </b>'.$name.'</li>'; // Get the bundle_sells_form field $bundle_sells_form_ids = get_post_meta($product_id, 'bundle_sells_form', true); $bundle_sells_form_ids = explode(',', $bundle_sells_form_ids); // If the ids are stored as a comma-separated string foreach($bundle_sells_form_ids as $id){ $output .= '<li><b>Bundle Item : </b>'.get_the_title($id).'</li>'; } $output .= '<li class="bundle-reg-price"><b>Regular Price : </b>'.$price.'</li>'; $output .= '</ul>'; } // Return the HTML list of bundled product data return $output; } // Register the shortcode with WordPress add_shortcode( 'bundle_sells_shortcode', 'fetch_bundle_sells' ); Any help will be greatly appreciated!
TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.