Skip to content
Advertisement

how to add if current date is before a certain date condition as an if-statement parameter

I have a WordPress site and I have written a filter:

function wc_add_string_to_price_newline( $price, $product ) {
    $product_id = $product->get_id();

    if ($product_id == '1190') {
        $price .= "<br>(15% off until May 31, 2020)";
    }

    return $price;
}
add_filter( 'woocommerce_get_price_html', 'wc_add_string_to_price_newline', 10, 2 );

I want to add a second condition to the if-statement: if current date is before 5-31-2020. How can I add that current date condition as a second if-statement parameter?

Advertisement

Answer

if ($product_id == '1190' && date('Y-m-d') < '2020-05-31') {
    $price .= "<br>(15% off until May 31, 2020)";
}
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement