Skip Navigation

[Resolved] WooCommerce Product Bundles extension Add-to-Cart and Toolset custom field

This thread is resolved. Here is a description of the problem and solution.

Problem: I want to display an audio player using an MP3 I have stored in a Types custom audio field. I'm using a Product Bundle extension and I'd like to replace some of their text output with this MP3 player.

Solution: I can show you how to display an audio player, but replacing some of a 3rd-party plugin's output may require the assistance of the support team for that 3rd-party plugin. In general, you would use the Types field API to display a MP3 player loaded with the MP3 from a custom audio field. An example showing how to display a basic player with 'autoplay' set to 'off':

echo( types_render_field('your-field-slug', array( 'autoplay' => 'on' ) ) );

Relevant Documentation:
https://toolset.com/documentation/customizing-sites-using-php/functions/#audio

This support ticket is created 4 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 3 replies, has 2 voices.

Last updated by Christian Cox 4 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#1510615
Screenshot_2.png
Screenshot_1.png

I'm developing a new e-commerce site using various WooCommerce and Toolset plugins for a music label that will be selling both track and albums as downloadable files. The album products are 'built' using the WooCommerce Product Bundles extension, which has its own version of the Add-to-Cart button to show, in this case, the list of tracks for the particular album product.
The Product Bundles Add-to-Cart shows several standard WooCommerce fields from the individual track products, including the respective product Short Description. I would very much like to replace that with one of the Toolset custom fields I have added to the Product CPT - the track's sample mp3 file.
Looking at the code for the WooCommerce Product Bundles plugin, I've found the following in plugins/woocommerce-product-bundles/templates/single-product/add-to-cart/bundle.php :

	/**
	 * 'woocommerce_before_bundled_items' action.
	 *
	 * @param WC_Product_Bundle $product
	 */
	do_action( 'woocommerce_before_bundled_items', $product );

	foreach ( $bundled_items as $bundled_item ) {

		/**
		 * 'woocommerce_bundled_item_details' action.
		 *
		 * @hooked wc_pb_template_bundled_item_details_wrapper_open  -   0
		 * @hooked wc_pb_template_bundled_item_thumbnail             -   5
		 * @hooked wc_pb_template_bundled_item_details_open          -  10
		 * @hooked wc_pb_template_bundled_item_title                 -  15
		 * @hooked wc_pb_template_bundled_item_description           -  20
		 * @hooked wc_pb_template_bundled_item_product_details       -  25
		 * @hooked wc_pb_template_bundled_item_details_close         -  30
		 * @hooked wc_pb_template_bundled_item_details_wrapper_close - 100
		 */
		do_action( 'woocommerce_bundled_item_details', $bundled_item, $product );
	}

and the following in plugins/woocommerce-product-bundles/includes/class_wc_template_hooks.php :

// Bundled item description.
add_action( 'woocommerce_bundled_item_details', 'wc_pb_template_bundled_item_description', 20, 2 );

But this is where my current skill set falls down; I think what needs to happen is that the immediately above add_action needs to be replaced with something that invokes the audio custom field from the same product post, but I'm not sure if that's possible or how that would be done. I'd appreciate any guidance you can provide!

#1511565

Hi, customizing the output from a 3rd party's filters isn't really something I am qualified to help with. You may need to reach out to their support team to find out how to inject or replace their custom output with your own PHP code. If you are able to find out, I can show you how to use PHP to display any Types custom field. You can use the types_render_field API to display the formatted field. Here's an example with the autoplay option set to 'on':

echo( types_render_field('your-field-slug', array( 'autoplay' => 'on' ) ) );

We have documentation for this API available here:
https://toolset.com/documentation/customizing-sites-using-php/functions/#audio

#1531315

My issue is resolved now. Thank you!

#1534297

Great, if you need more information about implementing any Toolset API feel free to create more tickets. We can discuss the options and syntax in more detail as needed.