• Resolved goddess_dix

    (@goddess_dix)


    First of all, thank you for this plugin. I’m new to WooCommerce, and this provides the experience I was missing but would have expected from the core plugin. Very much appreciated!

    I would like to change the template for completed orders on virtual/downloadable products to be a big “Download Now” button instead of a text link with the product name. I assume I might need to customize the template to do this.

    Could you maybe point me in the right direction? Advice appreciated

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hey,
    Thanks for your comment,
    Yes, you would have to edit the template to change how this works in woocommerce core. The template for downloads is email-downloads.php
    https://github.com/woocommerce/woocommerce/blob/master/templates/emails/email-downloads.php

    You could do something like this, where you removed this code:

    <?php foreach ( $downloads as $download ) : ?>
    		<tr>
    			<?php foreach ( $columns as $column_id => $column_name ) : ?>
    				<td class="td" style="text-align:<?php echo esc_attr( $text_align ); ?>;">
    					<?php
    					if ( has_action( 'woocommerce_email_downloads_column_' . $column_id ) ) {
    						do_action( 'woocommerce_email_downloads_column_' . $column_id, $download, $plain_text );
    					} else {
    						switch ( $column_id ) {
    							case 'download-product':
    								?>
    								<a href="<?php echo esc_url( get_permalink( $download['product_id'] ) ); ?>"><?php echo wp_kses_post( $download['product_name'] ); ?></a>
    								<?php
    								break;
    							case 'download-file':
    								?>
    								<a href="<?php echo esc_url( $download['download_url'] ); ?>" class="woocommerce-MyAccount-downloads-file button alt"><?php echo esc_html( $download['download_name'] ); ?></a>
    								<?php
    								break;
    							case 'download-expires':
    								if ( ! empty( $download['access_expires'] ) ) {
    									?>
    									<time datetime="<?php echo esc_attr( date( 'Y-m-d', strtotime( $download['access_expires'] ) ) ); ?>" title="<?php echo esc_attr( strtotime( $download['access_expires'] ) ); ?>"><?php echo esc_html( date_i18n( get_option( 'date_format' ), strtotime( $download['access_expires'] ) ) ); ?></time>
    									<?php
    								} else {
    									esc_html_e( 'Never', 'woocommerce' );
    								}
    								break;
    						}
    					}
    					?>
    				</td>
    			<?php endforeach; ?>
    		</tr>
    	<?php endforeach; ?>

    And replaced with this:

    <?php foreach ( $downloads as $download ) : ?>
    		<tr>
    		<a class="btn" href="<?php echo esc_url( get_permalink( $download['product_id'] ) ); ?>"><?php echo wp_kses_post( $download['product_name'] ); ?></a>
    		</tr>
    	<?php endforeach; ?>

    Ben

    Thread Starter goddess_dix

    (@goddess_dix)

    Thank you! That was exactly what I needed to get there.

    To anyone else who may want to do something similar, the code needs to be tweaked just a smidge. In the replacement code as above, this (which links to the product page):

    <a class="btn" href="<?php echo esc_url( get_permalink( $download['product_id'] ) ); ?>">

    needs to become this (which is a link to the actual download):

    <a class="btn" href="<?php echo esc_url( $download['download_url'] ); ?>">

    Thanks again for the help. Now I know where to look to make any other adjustments I want to. Appreciate it! ~Dix

    • This reply was modified 4 years, 9 months ago by goddess_dix.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Make Button for Downloadable Product?’ is closed to new replies.