How To Check If Product Is On Sale By Product ID (WooCommerce)

To check if the product is on sale by using the product id:

  1. Get product object using product id => ($product = wc_get_product($id);)
  2. Get sale price of product => ($sale_price = $product->get_sale_price();)
  3. Lastly, get the price of product => ($price = $product->get_price();)

Conclusion: get_price() method return the current active price. So, if the sale is running, it will return the sale price, if not, it will return the regular price. You can compare the active price with sale price to check if sale is running or not. This is the simplest way.

function check_if_sale_active_by_product_id($product_id) {
    $product = wc_get_product($product_id);
    $sale_price = $product->get_sale_price();
    $price = $product->get_price();
    if($price == $sale_price) {
        return true;
    } else {
        return false;