Right, well it is a bit different if you want the sale date to be shown based on the current selection. You need a way to determine what selection is made and find the scheduled sales date based on that selection.
The first part is done like this:
add_action( 'woocommerce_after_add_to_cart_button', 'woocommerce_output_sale_end_date', 10 );
function woocommerce_output_sale_end_date() {
?>
<script type="text/javascript">
jQuery(function( $ ) {
$('input[name=variation_id]').on( 'change', function(event) {
if ( $(this).val() != '' ) {
// DO AJAX CALL HERE BASED ON: $(this).val()
}
});
});
</script>
}
At the line of the // DO AJAX CALL HERE you'll need to do an Ajax call (read more about that here: http://codex.wordpress.org/AJAX_in_Plugins ) to get the scheduled sales dates for the value we check for there. This value will be a variation id and can be used to get a WC_Product_Variation object using our get_product() function.
So in the Ajax call, you'll do this (part of the original code). You will not need to make a full instance in this case, since you already have the id:
$variation_id = $VALUE_POSTED_BY_AJAX;
$sale_end_date = get_post_meta( $variation_id, '_sale_price_dates_to', true );
return '<span id="sale-price-to-date">' . __( 'Sale End Date: ', 'woocommerce' ) . date( 'Y-m-d', $sale_end_date ) . '</span>';
And once that is returned, you'll need to output the data returned.
This is as far as I can go without writing a full custom plugin for you. If you need more help beyond this, I advise you to find someone who can do this as a paid job:
Affiliated Woo Workers: http://www.woothemes.com/affiliated-woo-workers/
Codeable: https://codeable.io/
Tweaky: https://www.tweaky.com/