• Resolved pathosmusic

    (@pathosmusic)


    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.

Viewing 15 replies - 1 through 15 (of 17 total)
  • Plugin Author codepeople

    (@codepeople)

    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.

    Thread Starter pathosmusic

    (@pathosmusic)

    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.

    Plugin Author codepeople

    (@codepeople)

    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.

    Thread Starter pathosmusic

    (@pathosmusic)

    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.

    Plugin Author codepeople

    (@codepeople)

    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.

    Thread Starter pathosmusic

    (@pathosmusic)

    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?

    Plugin Author codepeople

    (@codepeople)

    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.

    Thread Starter pathosmusic

    (@pathosmusic)

    Can I ask how you are able to get the file to play automatically when the woocommerce downloadable files have a security access feature?

    Plugin Author codepeople

    (@codepeople)

    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.

    Thread Starter pathosmusic

    (@pathosmusic)

    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?

    Thread Starter pathosmusic

    (@pathosmusic)

    <?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.

    Plugin Author codepeople

    (@codepeople)

    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.

    Thread Starter pathosmusic

    (@pathosmusic)

    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?

    Plugin Author codepeople

    (@codepeople)

    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.

    Thread Starter pathosmusic

    (@pathosmusic)

    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.

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Add player to template php’ is closed to new replies.