I am currently using the snippet below to show estimated delivery on my single product pages. I need help making a few changes to the code;
-
I currently have a custom taxonomy (Available now) and would like to
modify the code to show for only products with that taxonomy -
Change the output notice to show eg. (Ready for delivery between 4
Nov & 7 Nov when you order within [hours left before end of day].) -
Hide the notice when when the item is out of stock
add_action( 'woocommerce_before_add_to_cart_form', 'delivery_estimate' );
function delivery_estimate() {
date_default_timezone_set( 'Europe/Tallinn' );
// if FRI/SAT/SUN delivery will be MON
if ( date( 'N' ) >= 5 ) {
$del_day = date( "l jS F", strtotime( "next tuesday" ) );
$order_by = "Monday";
}
// if MON/THU after 4PM delivery will be day after tomorrow
elseif ( date( 'H' ) >= 16 ) {
$del_day = date( "l jS F", strtotime( "tomorrow + 1 day" ) );
$order_by = "tomorrow";
}
// if MON/THU before 4PM delivery will be TOMORROW
else {
$del_day = date( "2 jS F", strtotime( "tomorrow" ) );
$order_by = "today";
}
$html = "<br><div class='woocommerce-message' style='clear:both'>Order by 4PM {$order_by} for delivery on {$del_day}</div>";
echo $html;
}
2
Answers
OUTPUT
If you use WooCommerce’s
global $product
you can get the taxonomy terms for the current product. Then you should be able to display the right messages.Your code will look something like this: