• Resolved Minh Nguyen

    (@ducminhn)


    We’re running into an issue where the product price HTML which is retrieved outside of the loop returns the normal price instead of the sale price after updating the plugin to the latest version.

    I’ve looked more into the code and found the get_product_price_html function is now using the get_the_ID() function to get the post ID instead of using the get_id() method of the $product object. This causes the issue when we get the products from outside of the default loop on a custom page template.

    I’m not sure what’s the benefit of using get_the_ID() function but I think we should use the $product->get_id() method to ensure the sale price returns correctly no matter what. Here is the entire get_product_price_html() function that I think it should be:

    
    // Price View HTML
        public function get_product_price_html ( $item_price, $product )
        {
    
            if ( is_admin() ) 
                return $item_price;
    
            // Load discount rules
            $this->load_rules();
            
            // Check if discount is active
            if ( $this->discount_rules == null )
                return $item_price; // Exit if no rules 
    
            // Load Product List
            $this->set_product_list();
            
            $post_id        = $product->get_id();
            $product        = wc_get_product( $post_id ); 
            $updatedPrice   = '';
    
            if ( !$product ) return $item_price;
    
            $rules      = $this->discount_rules;
            $price      = $product->get_sale_price() ? $product->get_sale_price() : $product->get_price();
            $prodLists  = $this->product_lists;
            $variations = $this->variations;
            $cartRules  = $this->awdp_cart_rules;
    
            // if( $this->converted_rate == '' && $item->get_ID() != '' ) {
            //     $this->converted_rate = $this->get_con_unit($item, $price, true);
            // }
    
            $viewPrice = call_user_func_array ( 
                array ( new AWDP_viewProductPrice(), 'product_price' ), 
                array ( $rules, $price, $post_id, $product, $prodLists, $cartRules, $item_price ) 
            );
    
            if ( is_array ( $viewPrice ) ) {
                $updatedPrice                   = $viewPrice['itemPrice'];
                $this->discountProductPrice     = $viewPrice['discountedPrice'];
                $this->discountProductMaxPrice  = $viewPrice['discountedMaxPrice'];
                $this->discountProductMinPrice  = $viewPrice['discountedMinPrice'];
            }
    
            return $updatedPrice ? $updatedPrice : $item_price; 
    
        }

    Please let me know if we can have this in the next release so we can update the plugin again?

    Thank you!

    • This topic was modified 3 years, 6 months ago by Minh Nguyen.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support ijas

    (@ijasacodez)

    Thanks for sharing the same, we have passed the code to our development team, our team will check and update the same on our next update.

    Plugin Support ijas

    (@ijasacodez)

    Hope you have updated the plugin to the latest version, we have updated the code on our latest release. Thanks for pointing out the same.

    We are closing this thread, please feel free to open a new thread if you have any further queries.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get post ID via the product instead of the get_the_ID() function’ is closed to new replies.