1

i magento 2 in product view page based on some condition or input my SpecialPrice will be changed

so i follow below code in Block file but it return the old SpecialPrice , how to fix this issue

echo $block->getPriceHtml($_product, true);
echo $this->getCustomProductPrice($product); 

in block

public function getCustomProductPrice(){
  $product->setSpecialPrice(40); 
  return $this->getPriceHtml($_product, true);
}

but it show old price only

1

in Magento 2 when ever product object is loaded, It init the new object called pricing info based on the price pool price will be displayed

so while product object is init and in between price is changed it wont reflect till you reload it

To reload the

$product->reloadPriceInfo();

that is

public function getCustomProductPrice(){
  $product->setSpecialPrice(40); 
  $product->reloadPriceInfo();
  return $this->getPriceHtml($_product, true);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.