php - Show date of friday every 2 weeks
Get the solution ↓↓↓I have woocommerce products with special pickup dates. Pickup day is on fridays. For example a products has a pickup time in two weeks, the date i want to show by the product should be:
- 31-07-2020
- 14-08-2020
- 28-08-2020 (every two weeks)
What my code below do is:
- 31-07-2020
- 07-08-2020 WRONG (this is not every two weeks then, because it counts then from the next friday)
Here i calculate the dates:
function lwb_pickup_days( $att ) {
switch ( $att ) {
case "weekly":
$date = date_i18n( 'l, d.m.Y', strtotime("next Friday"));
return $date;
break;
case "2 weeks":
$date = date_i18n( 'l, d.m.Y', strtotime("next Friday + 2weeks"));
return $date;
break;
case "3 weeks":
$date = date_i18n( 'l, d.m.Y', strtotime("next Friday + 3weeks"));
return $date;
break;
case "4 weeks":
$date = date_i18n( 'l, d.m.Y', strtotime("next Friday + 4weeks"));
return $date;
break;
}
}
This is how i use the function above to get the pickup date for each product!
// Show Attributes on Product Archive & Single Product
function lwb_show_attribute_on_product(){
global $product;
$taxonomy = 'pa_lieferfrequenz';
$value = $product->get_attribute( $taxonomy );
// calculate the pickup date
$date = lwb_pickup_days( $value );
if ( $value ) {
$label = get_taxonomy( $taxonomy )->labels->singular_name;
$name = 'Abholtag';
echo '<div class="lwb-product-meta">';
echo '<p class="lwb-' . strtolower( $label ) .'">' . $name . ': ' . $date . '</p>';
echo '</div>';
}
}
add_action( 'woocommerce_after_shop_loop_item_title', 'lwb_show_attribute_on_product', 45 );
add_action( 'woocommerce_product_meta_start', 'lwb_show_attribute_on_product', 45 );
Thanks for your inputs...
Answer
Solution:
Can you try this?
// this Friday.
date('Y-m-d', strtotime('friday this week'))
// in 2 weeks
date('Y-m-d', strtotime('friday this week') + 7 * 2 * 86400)
// in 4 weeks
date('Y-m-d', strtotime('friday this week') + 7 * 4 * 86400)
// etc
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: script cache:clear returned with error code 255
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.