1

I need an option to toggle off/on the price (category/view.phtml and product/view.phtml).

Let's say a logged in customer wants to hide the price.

So he ticks a checkbox or anything like that which hides prices on the both mentioned view.phtml

Is there any way to achieve something like that in magento 1.9.3.6 ? Thanks

1 Answer 1

0
  • Create the button to click
  • Whenever the button is clicked. Create and set a session variable that the price will not show like:

Mage::getSingleton(‘core/session’)->setMyValue("nopriceview");

  • Have a check in the (category/view.phtml and product/view.phtml) where if the session is active:

if (Mage::getSingleton('core/session')->getNoPriceView())

then add a container around the price and add inline css display none.

For example:

You have the hide price button inside a form.

<form name="priceView" action="" method="post" />
<input type="submit" value="submit" name="priceCheck" />
</form>

Then you also have PHP code to check if the form has been submitted.

<?php
    if(!(isset($_SESSION["priceView"]))) {
        $_SESSION["priceView"] = "yesPrice";
    }
    if (isset($_POST['priceCheck'])){
        if($_SESSION["priceView"] == "yesPrice") {
            $_SESSION["priceView"] = "noPrice";
        } elseif($_SESSION["priceView"] == "noPrice") {
            $_SESSION["priceView"] = "yesPrice";
        }
    }
?>

I'm using basic PHP but if you need this the Magento way we can do that also.

5
  • Thank you. Very helpful. Just for my understanding: I have to put the session Mage::getSingleton(‘core/session’)->setMyValue("nopriceview"); into a button like jQuery toggle() w3schools.com/jquery/eff_toggle.asp If yes, how would I do that?
    – zlep
    Commented Oct 12, 2017 at 7:16
  • Create a form where you will submit the button data to add a session variable or create a button where it will ajax a session variable. Then have the form or ajax have a check if the session is active or not to turn it on or off.
    – fja3omega
    Commented Oct 12, 2017 at 7:26
  • I'm very sorry for being so stupid. I got the Magento part but I struggle with the button thing. Is there any stackexchange or example I could use? Or could you point me in the right direction if you don't mind? Thank you very much.
    – zlep
    Commented Oct 12, 2017 at 8:22
  • @zlep I better just edit my answer and elaborate.
    – fja3omega
    Commented Oct 13, 2017 at 3:42
  • Thank you very much. I tried it with your basic PHP code but it did not work unfortunately. I guess it has to be the Magento way to work correctly? Which is kind of more difficult than I thought.
    – zlep
    Commented Oct 13, 2017 at 8:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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