猿问

如果当前日期早于某个日期条件,如何将其添加为 if 语句参数

我有一个 WordPress 网站,我写了一个过滤器:


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 );

我想在 if 语句中添加第二个条件:如果当前日期早于 5-31-2020。如何将当前日期条件添加为第二个 if 语句参数?


慕标5832272
浏览 135回答 1
1回答

达令说

if&nbsp;($product_id&nbsp;==&nbsp;'1190'&nbsp;&&&nbsp;date('Y-m-d')&nbsp;<&nbsp;'2020-05-31')&nbsp;{&nbsp; &nbsp;&nbsp;&nbsp;$price&nbsp;.=&nbsp;"<br>(15%&nbsp;off&nbsp;until&nbsp;May&nbsp;31,&nbsp;2020)"; }
随时随地看视频慕课网APP
我要回答