• Resolved quimo72

    (@quimo72)


    Hi,
    I built this page manually (no build-in WooCommerce category page) and I need to show a badge if the variable product is discounted. The discount is applied to all the variations. If I use is_on_sale() the result is false. Can I use a plugin method to achieve this? Thank a lot. This plugin works great.

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter quimo72

    (@quimo72)

    How can I get the variation price with the discount applied?
    Actually I use this code:

    $variations = $product->get_available_variations();
    for ($j = 0; $j < count($variations); $j++) {
      $dummy = wc_get_product($variations[$j]['variation_id']);
      if ($dummy->is_on_sale()) {
        $this->data[$i]['badge'] = 'shoppaua_on_sale'; /* show the badge on the template */
        $this->data[$i]['discounted_price'] = ????
        break;
      }
    }

    $dummy->sale_price returns “”

    • This reply was modified 6 years ago by quimo72.
    • This reply was modified 6 years ago by quimo72.
    Thread Starter quimo72

    (@quimo72)

    Is there a way (a class method) to get the discounted price of a product?

    Thread Starter quimo72

    (@quimo72)

    I used this approach:

    $discount = new WC_Taxonomy_Discounts_Webdados();
    $variations = $product->get_available_variations();
    for ($j = 0; $j < count($variations); $j++) {
        $dummy = wc_get_product($variations[$j]['variation_id']);
        if ($dummy->is_on_sale()) {
            $discount_price = $discount->kuantokusta_product_node_variation_current_price($dummy-
            $discount_price = number_format((float)$discount_price, 2, ',', '');
            break;
        }
    }

    It’s correct?

    Plugin Author Marco Almeida | Webdados

    (@webdados)

    Yes, from 1.3 there’s a helper function.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Method to invoke to check if a variable product is discounted’ is closed to new replies.