Get post ID via the product instead of the get_the_ID() function
-
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 theget_the_ID()
function to get the post ID instead of using theget_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 entireget_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!
- The topic ‘Get post ID via the product instead of the get_the_ID() function’ is closed to new replies.