Skip Navigation

[Resolved] Insert Types custom field into a 3rd party plugins shortcode, then in a template

This support ticket is created 10 years, 1 month 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by Jive 10 years, 1 month ago.

Assigned support staff: Luo Yang.

Author
Posts
#34170

I hope this is my last support request before launching a big beautiful site with Types/Views used all over it!

I'm using a great audio player plugin (hidden link) to insert a preview file in my WooCommerce products. This plugin uses the shortcode [wp_media media="audio" volume=0.8 urls="/some-directory/song-file.mp3"]

I used Views to make a custom field for the song file url. On my Products Archive page I'm successfully using the plugins and Views shortcode together like this:
[wp_media media="audio" volume=0.8 urls="[types field="file"][/types]"]
Works like a charm!

My problem:
I'm trying to get the same player with the same song file to show on the single-product.php template, just below the product title.

I tried multiple code snippets based around 'do_shortcode()' with no luck. I'm pretty new to php so it's a bit over my head.
Using Content Template works, but the product description displays way at the bottom of the single product template.
As this preview file is the most important part of these products, I need it right at the top under the product title.

I also tried a new single-product.php file in my child theme, but I had no luck getting it to work either.

What is the best way to go about this?

I'm using Genesis, WooCommerce, Types/Views, and the WordPress Media audio player linked above.

#34200

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Hi Jive,

WP function do_shortcode should works, could you post the PHP code you are using?
http://codex.wordpress.org/Function_Reference/do_shortcode

Regards
Luo

#34227

I tried a few things, but they were snippets I found in the forum since i'm not confident enough writing my own php yet.

Here is one:

add_action('woocommerce_after_add_to_cart_form', 'wordpress_media_jplayer');
function wordpress_media_jplayer() {
$var = get_post_meta($post->ID, 'preview_file_url', true);
if ($var == '')
{ }
echo do_shortcode('[wp_media media="audio" volume=0.8 urls="' . $var . '" ]');
}

And I tried something simpler like this:

add_action('woocommerce_after_add_to_cart_form', 'wordpress_media_jplayer');
function wordpress_media_jplayer() {
echo do_shortcode('[wp_media media="audio" volume=0.8 urls="[types field="preview_file_url"][/types]"]');
}

There probably something blatant that i'm missing here, i hope, right?

Thanks

#34233

WOW. I modified the first version of my code to make $var = the types shortcode. And it works.

add_action('woocommerce_after_add_to_cart_form', 'wordpress_media_jplayer');
function wordpress_media_jplayer() {
$var = do_shortcode('[types field="preview_file_url"][/types]');
echo do_shortcode('[wp_media media="audio" volume=0.8 urls="' . $var . '" ]');
}

Is there a way to make this an 'if !empty' statement?

Like:
if types field="preview_file_url" (!empty)
then display (insert all my code from above in this post)

Will something like that allow me to have products without the audio player in the future?

#34243

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Please try like this:

function wordpress_media_jplayer() {
$var = do_shortcode('[types field="preview_file_url"][/types]');
if(!empty($var)){
echo do_shortcode('[wp_media media="audio" volume=0.8 urls="' . $var . '" ]');
}
}

#34275

Perfection. Thank you!