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!
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
My issue is resolved now. Thank you!
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.