Skip to content

Instantly share code, notes, and snippets.

@matrixwd
Created July 16, 2017 11:55
Show Gist options
  • Save matrixwd/4eac5813dffb4bdeaf8b1d1373bbbc48 to your computer and use it in GitHub Desktop.
Save matrixwd/4eac5813dffb4bdeaf8b1d1373bbbc48 to your computer and use it in GitHub Desktop.
Adding Custom Fields Version Number to WooCommerce Downloads page
<?php break;
case 'download-product_version' :
$dl_id = $download['product_id'];
$version = esc_html( get_post_meta( $dl_id, 'version', true ) ); ?>
<span class="version"><?php echo $version; ?></span>
<?php break;
}
}
?>
</td>
function add_woocommerce_account_downloads_columns( $actions ) {
$actions = array(
'download-product' => __( 'Product', 'woocommerce' ),
'download-remaining' => __( 'Downloads remaining', 'woocommerce' ),
'download-expires' => __( 'Expires', 'woocommerce' ),
'download-file' => __( 'File', 'woocommerce' ),
'download-actions' => '&nbsp;',
'download-product_version' => __( 'Version', 'woocommerce' ),
);
return $actions;
}
add_filter( 'woocommerce_account_downloads_columns', 'add_woocommerce_account_downloads_columns', 10, 2 );
<?php
// Setup your custom query
$args = array( 'post_type' => 'product');//Shows all products
//$args = array( 'post_type' => 'product', 'product_cat' => 'your-cat');//show only your cat plugins products
$loop = new WP_Query( $args );
global $product;
?>
<table class="shop_table shop_table_responsive tablesorter">
<thead>
<tr>
<th class="col-md-6"><span class="nobr">Plugin / Theme Name</span></th>
<th class="col-md-2"><span class="nobr">Current Version</span></th>
<th class="col-md-2"><span class="nobr">Last Updated</span></th>
</tr>
</thead>
<tbody>
<?php
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<tr>
<td>
<a class="productLink" href="<?php echo get_permalink( $loop->post->ID ) ?>">
<?php the_title(); ?>
</a>
<?php //echo get_the_excerpt(); ?>
</td>
<td>
<span class="version"><?php echo esc_html( get_post_meta(get_the_ID(), 'version', true) ); ?></span>
</td>
<td>
<?php
$u_time = get_the_time('U');
$u_modified_time = get_the_modified_time('U');
if ($u_modified_time >= $u_time + 86400):
//echo '<span class="time">' . the_modified_time("F jS, Y") . '</span> '; ?>
<span class="time"><?php echo the_modified_time('F jS, Y'); ?></span>
<?php else: ?>
<span class="time"><?php echo the_time('F jS, Y'); ?></span>
<?php
endif;
?>
</td>
</tr>
<?php endwhile; wp_reset_query(); // Remember to reset ?>
</tbody>
</table>
@matrixwd
Copy link
Author

downloads.php is located in /themeName/woocommerce/myaccount/downloads.php

functions.php is your wordpress main functions.php file

wp-template-file.php is any wordpress template file you wish to put this in.

@guri-dev
Copy link

guri-dev commented Aug 7, 2019

@matrixwd in Woocommerce 3.3+ version location of switch statement is changed from woocommerce/myaccount/downloads.php to woocommerce/order/order-downloads.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment