Hi,
I am looking for a way to show products to all users, but without seeing prices and the ability to purchase.
If a user has logged in and is member of a specific user group, the user should be possible to purchase, depend on the group related prices.
Any hint, how to get this setup working?
Thanks
Maik
Well, before posting here, better read this about this:
viewtopic.php?t=200480
viewtopic.php?t=200480
My Github OC Site: https://github.com/IP-CAM
5'600 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.
Hi Maik,daliose wrote: ↑Thu Sep 05, 2024 3:36 pmHi,
I am looking for a way to show products to all users, but without seeing prices and the ability to purchase.
If a user has logged in and is member of a specific user group, the user should be possible to purchase, depend on the group related prices.
Any hint, how to get this setup working?
Thanks
Maik
There are probably many ways to achieve this setup in OpenCart 3, I personally would:
In catalog/controller/product/product.php and catalog/controller/product/category.php, locate where the product prices are set:
Code: Select all
$data['price'] = $this->currency->format($product_info['price'], $this->session->data['currency']);
Code: Select all
if ($this->customer->isLogged() && in_array($this->customer->getGroupId(), 1)) {
$data['price'] = $this->currency->format($product_info['price'], $this->session->data['currency']);
$data['show_price'] = true;
$data['can_purchase'] = true;
} else {
$data['price'] = '';
$data['show_price'] = false;
$data['can_purchase'] = false;
}
Then in your view folder (.twig files), product.twig and category.twig, find {{price}} and wrap it in an if statement:
Code: Select all
{% if show_price %}
<p class="price">{{ price }}</p>
{% else %}
<p><a href="link to account">Login to see prices</a></p>
{% endif %}
Code: Select all
{% if can_purchase %}
<button type="button" class="btn btn-primary">Add to Cart</button>
{% else %}
<button type="button" class="btn btn-secondary" disabled>Login to purchase</button>
{% endif %}
Hope this helps.
Scott
Who is online
Users browsing this forum: No registered users and 17 guests