Add player to template php
-
I am trying to add the player to only the single product page php file but can’t figure it out. I have tried to use the do_shortcode function but its not working. I don’t want a playlist, i just want the single audio file to auto populate on every product.
-
Hello @pathosmusic
I guess you are using the free version of the plugin, if it is the case, you should configure the product as “downloadable” and select at least an audio file from the list of downloadable files.
Best regards.
Hi sorry if I was unclear.
So the products are set as downloadable and the plugin works fine for the most part. If I enable it on
? single-entry pages (Product’s page only)
it adds a player everywhere on the site that the product shows up. For example I have a woocommerce “Latest Products” Visual Composer block on the home page that shows 10 recent items, but it puts an audio player under each product and the home page loads very slow. I just want to be able to add it to the content-single-product.php from woocommerce but it doesn’t seem so straightforward.
Hello @pathosmusic
Concerning to this point: …but it puts an audio player under each product and the home page loads very slow…
To fix the performance issue, I recommend you to select the “none” option for the “Preload” attribute in the players’ settings.
If you want to load the players associated to a product directly from the template file, you should call the playlist shortcode as follows:
<?php print do_shortcode('[wcmp-playlist products_ids="123"]'); ?>
Replacing the product’s id 123, by the corresponding one.
Best regards.
Is there a way to auto find the product id? This is a multi vendor marketplace so authors upload via a front end submission dashboard. I would like the player to auto populate on the product page template by finding the current product id.
Hello @pathosmusic
The file you are referring is a template of WooCommerce, it is not precisely part of our plugin, and in this file you should use the WooCommerce and WordPress functions to determine the id of the current product (post).
For example, you can use the WordPress function:
get_the_ID()
as follows:<?php print do_shortcode('[wcmp-playlist products_ids="'+get_the_ID()+'"]'); ?>
Best regards.
Thanks for your help so far!
That code doesn’t work for me. All I want to do is have an audio player show up on only the single product pages by adding some code to call your player in the content-single-product.php. There is no code to add your plugin to a template file and have it behave like normal?
Hello @pathosmusic
The code I recommended you is working properly in my website.
Please, create a ticket in my private website for checking your settings in detail:
https://wordpress.dwbooster.com/support
Best regards.
Can I ask how you are able to get the file to play automatically when the woocommerce downloadable files have a security access feature?
Hello @pathosmusic
It is possible, using a PHP Script as proxy. Furthermore, the commercial version of the plugin is able to create a new copy of file, but truncating it’s size at the percentage defined in the player’s settings, so, in case the user download the file used for demo, it would be the truncated version of the original file.
Best regards.
So what I am doing is having users upload audio “products” they want to sell in a .zip file, but also requiring them to provide an .mp3 file that is watermarked using an audio watermark file I provide them. So I’m not too worried about the mp3 getting downloaded since its watermarked and a preview. The .zip file should never be compromised with your plugin right? Because its only looking for audio files?
<?php print do_shortcode('[wcmp-playlist products_ids="'+get_the_ID()+'"]'); ?>
This code you gave me is pulling the ID but not displaying a player, it just outputs the ID as a number on the webpage.
Hello @pathosmusic
Answering your first question, the plugin will consider only the audio files.
Concerning to the shorcode, my apologies, as I’m writing code for javascript and php at the same time, I’ve made a mistake in the snippet of code I sent you. The correct one is:
<?php print do_shortcode('[wcmp-playlist products_ids="'.get_the_ID().'"]'); ?>
Best regards.
No need for apologies! Thanks for the replies! This code is also not working. Even if I manually add the product ID for one that I know, the audio player doesn’t show. Is it a problem with the way I am implementing the shortcode in my php template?
If I use the wordpress built in audio shortcode, I use this code:
$ca_audio = $product->get_id(); $_product = wc_get_product( $ca_audio ); $downloads = $product->get_files(); foreach( $downloads as $key => $each_download ) { if ( strpos( $each_download["file"] , '.mp3') !== false) { $attr = array( 'src' => $each_download["file"], 'loop' => '', 'autoplay' => '', 'preload' => 'none' ); echo wp_audio_shortcode( $attr ); break; } }
and it shows the wordpress player, just won’t play the audio.
Should your shortcode be called another way in the php file? It doesn’t seem to be showing at all with any variation of the code you gave me. Does there need to be any special options enabled in the plugin for the shortcode to show?
Hello @pathosmusic
Please, contact me through my private website for checking your settings in detail.
Actually, if you want to display the music player in every product’s page where there are at least an audio file as downloadable file, you don’t need to insert the shortcode in the template’s file or edit the template’s file, you simply should configure the players through the settings page (and not directly in every product). Furthermore, if you want the products’ authors cannot edit the players’ settings from the products’ settings, you simply should edit the code of the plugin for not including the metabox corresponding to the players’ settings.
Best regards.
Will it cost anything to look into this more on your website? It asks me to put in an email for payment.
Also I did have that option enabled and it works, but it loads it on the front page as well in a “recent products” section from woocommerce Visual Composer block element.
Somehow I just want it to be on the single product page only.
- The topic ‘Add player to template php’ is closed to new replies.