Virtuemart Add to Cart buttons hide for non user

Giuma
86 Posts
Giuma posted this 15 February 2017

hello it's possibile to hide Virtuemart Add to Cart buttons, quantity and variants, to non registered user?

for example in virtuemart tempalte

change this

<?php
?>      // Add To Cart Button
//          if (!empty($this->product->prices) and !empty($this->product->images[0]) and $this->product->images[0]->file_is_downloadable==0 ) {


        if (!VmConfig::get('use_as_catalog', 0) and !empty($this->product->prices)) {
            echo $this->loadTemplate('addtocart');
        }  // Add To Cart Button END
        ?>

whith this

<?php check if user is logged in/registered. $user jfactory::getuser(); if( $user-?>id ){  
$user = JFactory::getUser();  
$status = $user->guest; 
if($status == 1){
echo "Log in om de prijzen te zien.";
}
else
{
// Add To Cart Button
if (!VmConfig::get('use_as_catalog', 0) and !empty($this->product->prices)) {


    echo $this->loadTemplate('addtocart');
}  // Add To Cart Button END
}
?>

how to do it in themler?

hello it's possibile to hide Virtuemart Add to Cart buttons, quantity and variants, to non registered user? for example in virtuemart tempalte change this <?php ?> // Add To Cart Button // if (!empty($this->product->prices) and !empty($this->product->images[0]) and $this->product->images[0]->file_is_downloadable==0 ) { if (!VmConfig::get('use_as_catalog', 0) and !empty($this->product->prices)) { echo $this->loadTemplate('addtocart'); } // Add To Cart Button END ?> whith this <?php check if user is logged in/registered. $user jfactory::getuser(); if( $user-?>id ){ $user = JFactory::getUser(); $status = $user->guest; if($status == 1){ echo "Log in om de prijzen te zien."; } else { // Add To Cart Button if (!VmConfig::get('use_as_catalog', 0) and !empty($this->product->prices)) { echo $this->loadTemplate('addtocart'); } // Add To Cart Button END } ?> how to do it in themler?

Last edited 15 February 2017 by Giuma

Vote to pay developers attention to this features or issue.
9 Comments
Order By: Standard | Newest
Support Team
Support Team posted this 16 February 2017

Hello Giuseppe,
the solution would require some help from developers. I'll contact them about how it is possible to incorporate this solution into Themler themes and will let you know

regards,
Aileen

Hello Giuseppe, the solution would require some help from developers. I'll contact them about how it is possible to incorporate this solution into Themler themes and will let you know regards, Aileen
Giuma
86 Posts
Giuma posted this 18 February 2017

thanks i'm wait

thanks i'm wait
Support Team
Support Team posted this 20 February 2017

Hello Giuseppe,
you need to incorporate the additional code to the file

<ThemeName>\html\mod_virtuemart_product\default_template.php 

Find the code block

    <?php
        $tmpPrice = (float)$productItems->productBuy->prices['costPrice'];
        if (!(VmConfig::get('askprice', true) and empty($tmpPrice))) {
            if (isset($productItems->productBuy->orderable) && $productItems->productBuy->orderable) {
                $vmLang = VmConfig::get ('vmlang_js', 1) ? '&lang=' . substr (VmConfig::$vmlang, 0, 2) : '';
                $attributes = 'data-vmsiteurl="' . JURI::root( ) . '" ' .
                    'data-vmlang="' . $vmLang . '" ' .
                    'data-vmsuccessmsg="' . JText::_('COM_VIRTUEMART_CART_ADDED') . '" ' .
                    'title="' . $productItems->productBuy->product_name . '" ' .
                    'class="' . $classNames . ' add_to_cart_button" ' .
                    $buttonDataAttrs;
                echo JHTML::link ('#', JText::_ ('COM_VIRTUEMART_CART_ADD_TO'), $attributes);
            } else {
                $button = JHTML::link ($productItems->productBuy->link, JText::_ ('COM_VIRTUEMART_CART_ADD_TO'),
                    'title="' . $productItems->productBuy->product_name . '" ' . 'class="' . $classNames . '" ' . $buttonDataAttrs);
                if (isset($productItems->productBuy->isOne))
                    $button = JText::_('COM_VIRTUEMART_ADDTOCART_CHOOSE_VARIANT');
                echo $button;
            }
        }
    ?>

and replace it with

    <?php


$user jfactory::getuser(); if( $user-?>id ){  
$user = JFactory::getUser();  
$status = $user->guest; 
if($status == 1){
echo "Log in om de prijzen te zien.";
}
else
{
// Add To Cart Button
                $tmpPrice = (float)$productItems->productBuy->prices['costPrice'];
                if (!(VmConfig::get('askprice', true) and empty($tmpPrice))) {
                    if (isset($productItems->productBuy->orderable) && $productItems->productBuy->orderable) {
                        $vmLang = VmConfig::get ('vmlang_js', 1) ? '&lang=' . substr (VmConfig::$vmlang, 0, 2) : '';
                        $attributes = 'data-vmsiteurl="' . JURI::root( ) . '" ' .
                            'data-vmlang="' . $vmLang . '" ' .
                            'data-vmsuccessmsg="' . JText::_('COM_VIRTUEMART_CART_ADDED') . '" ' .
                            'title="' . $productItems->productBuy->product_name . '" ' .
                            'class="' . $classNames . ' add_to_cart_button" ' .
                            $buttonDataAttrs;
                        echo JHTML::link ('#', JText::_ ('COM_VIRTUEMART_CART_ADD_TO'), $attributes);
                    } else {
                        $button = JHTML::link ($productItems->productBuy->link, JText::_ ('COM_VIRTUEMART_CART_ADD_TO'),
                            'title="' . $productItems->productBuy->product_name . '" ' . 'class="' . $classNames . '" ' . $buttonDataAttrs);
                        if (isset($productItems->productBuy->isOne))
                            $button = JText::_('COM_VIRTUEMART_ADDTOCART_CHOOSE_VARIANT');
                        echo $button;
                    }
                }
}
            ?>

Regards,
Aileen

Hello Giuseppe, you need to incorporate the additional code to the file <ThemeName>\html\mod_virtuemart_product\default_template.php Find the code block <?php $tmpPrice = (float)$productItems->productBuy->prices['costPrice']; if (!(VmConfig::get('askprice', true) and empty($tmpPrice))) { if (isset($productItems->productBuy->orderable) && $productItems->productBuy->orderable) { $vmLang = VmConfig::get ('vmlang_js', 1) ? '&lang=' . substr (VmConfig::$vmlang, 0, 2) : ''; $attributes = 'data-vmsiteurl="' . JURI::root( ) . '" ' . 'data-vmlang="' . $vmLang . '" ' . 'data-vmsuccessmsg="' . JText::_('COM_VIRTUEMART_CART_ADDED') . '" ' . 'title="' . $productItems->productBuy->product_name . '" ' . 'class="' . $classNames . ' add_to_cart_button" ' . $buttonDataAttrs; echo JHTML::link ('#', JText::_ ('COM_VIRTUEMART_CART_ADD_TO'), $attributes); } else { $button = JHTML::link ($productItems->productBuy->link, JText::_ ('COM_VIRTUEMART_CART_ADD_TO'), 'title="' . $productItems->productBuy->product_name . '" ' . 'class="' . $classNames . '" ' . $buttonDataAttrs); if (isset($productItems->productBuy->isOne)) $button = JText::_('COM_VIRTUEMART_ADDTOCART_CHOOSE_VARIANT'); echo $button; } } ?> and replace it with <?php $user jfactory::getuser(); if( $user-?>id ){ $user = JFactory::getUser(); $status = $user->guest; if($status == 1){ echo "Log in om de prijzen te zien."; } else { // Add To Cart Button $tmpPrice = (float)$productItems->productBuy->prices['costPrice']; if (!(VmConfig::get('askprice', true) and empty($tmpPrice))) { if (isset($productItems->productBuy->orderable) && $productItems->productBuy->orderable) { $vmLang = VmConfig::get ('vmlang_js', 1) ? '&lang=' . substr (VmConfig::$vmlang, 0, 2) : ''; $attributes = 'data-vmsiteurl="' . JURI::root( ) . '" ' . 'data-vmlang="' . $vmLang . '" ' . 'data-vmsuccessmsg="' . JText::_('COM_VIRTUEMART_CART_ADDED') . '" ' . 'title="' . $productItems->productBuy->product_name . '" ' . 'class="' . $classNames . ' add_to_cart_button" ' . $buttonDataAttrs; echo JHTML::link ('#', JText::_ ('COM_VIRTUEMART_CART_ADD_TO'), $attributes); } else { $button = JHTML::link ($productItems->productBuy->link, JText::_ ('COM_VIRTUEMART_CART_ADD_TO'), 'title="' . $productItems->productBuy->product_name . '" ' . 'class="' . $classNames . '" ' . $buttonDataAttrs); if (isset($productItems->productBuy->isOne)) $button = JText::_('COM_VIRTUEMART_ADDTOCART_CHOOSE_VARIANT'); echo $button; } } } ?> Regards, Aileen
Giuma
86 Posts
Giuma posted this 20 February 2017

wooow thanks so much

wooow thanks so much
Giuma
86 Posts
Giuma posted this 25 September 2017

hello i need help also for quantity selector
i think i'll do similar
can you help me?

hello i need help also for quantity selector i think i'll do similar can you help me?
Support Team posted this 25 September 2017

Hi,

The general solution is the same:

  1. you have the elements that you want to hide for users which are not logged in. At first you need to open browser developers tool and search for the identifier of this control. For example, Product Quantity control on the Product Details template has bd-productquantity-2 class on my side.
  2. search for his class through the theme files. You will find
    \templates\[theme_name]\html\com_virtuemart\productdetails\default-template.php file
  3. open this file and search for the control by this class. For example, Product Quantity looks as follows:
    <div class=" bd-productquantity-2 quantity-box">
    <input type="text" class="quantity-input js-recalculate bd-bootstrapinput-13 form-control input-sm" step="1" value="<?php echo $init; ?>" data-errStr="<?php echo vmText::_('COM_VIRTUEMART_WRONG_AMOUNT_ADDED')?>"
    />
    <span class="quantity-controls js-recalculate">
    <input type="button" class="quantity-controls quantity-plus"/>
    <input type="button" class="quantity-controls quantity-minus"/>
    </span>
    </div>
  4. wrap the control in piece of php code which checks if the current user has ID, for example:
    <?php
    $user =& JFactory::getUser();
    $user_id = $user->get('id');
    if ($user_id)
    {
    ?>
    SHOW SOMETHING (HTML) IF USER IS LOGGEN IN
    <?php
    } else
    if (!$user_id)
    {
    echo "TEXT MESSAGE FOR GUESTS";
    }
    ?>

    You can use any ready code depending on your needs.
    The SHOW SOMETHING (HTML) IF USER IS LOGGEN IN line can be replaced with the control's code:
    <?php
    $user =& JFactory::getUser();
    $user_id = $user->get('id');
    if ($user_id)
    {
    ?>
    <div class=" bd-productquantity-2 quantity-box">
    <input type="text" class="quantity-input js-recalculate bd-bootstrapinput-13 form-control input-sm" step="1" value="<?php echo $init; ?>" data-errStr="<?php echo vmText::_('COM_VIRTUEMART_WRONG_AMOUNT_ADDED')?>"
    />
    <span class="quantity-controls js-recalculate">
    <input type="button" class="quantity-controls quantity-plus"/>
    <input type="button" class="quantity-controls quantity-minus"/>
    </span>
    </div>
    <?php
    } else
    if (!$user_id)
    {
    echo "TEXT MESSAGE FOR GUESTS";
    }
    ?>

It should work for all controls if you do it right.

Thank you,
Olivia

Hi, The general solution is the same: 1. you have the elements that you want to hide for users which are not logged in. At first you need to open browser developers tool and search for the identifier of this control. For example, Product Quantity control on the Product Details template has `bd-productquantity-2` class on my side. 2. search for his class through the theme files. You will find `\templates\[theme_name]\html\com_virtuemart\productdetails\default-template.php` file 3. open this file and search for the control by this class. For example, Product Quantity looks as follows: `<div class=" bd-productquantity-2 quantity-box"> <input type="text" class="quantity-input js-recalculate bd-bootstrapinput-13 form-control input-sm" step="1" value="<?php echo $init; ?>" data-errStr="<?php echo vmText::_('COM_VIRTUEMART_WRONG_AMOUNT_ADDED')?>" /> <span class="quantity-controls js-recalculate"> <input type="button" class="quantity-controls quantity-plus"/> <input type="button" class="quantity-controls quantity-minus"/> </span> </div>` 4. wrap the control in piece of php code which checks if the current user has ID, for example: `<?php $user =& JFactory::getUser(); $user_id = $user->get('id'); if ($user_id) { ?> SHOW SOMETHING (HTML) IF USER IS LOGGEN IN <?php } else if (!$user_id) { echo "TEXT MESSAGE FOR GUESTS"; } ?> ` You can use any ready code depending on your needs. The `SHOW SOMETHING (HTML) IF USER IS LOGGEN IN` line can be replaced with the control's code: `<?php $user =& JFactory::getUser(); $user_id = $user->get('id'); if ($user_id) { ?> <div class=" bd-productquantity-2 quantity-box"> <input type="text" class="quantity-input js-recalculate bd-bootstrapinput-13 form-control input-sm" step="1" value="<?php echo $init; ?>" data-errStr="<?php echo vmText::_('COM_VIRTUEMART_WRONG_AMOUNT_ADDED')?>" /> <span class="quantity-controls js-recalculate"> <input type="button" class="quantity-controls quantity-plus"/> <input type="button" class="quantity-controls quantity-minus"/> </span> </div> <?php } else if (!$user_id) { echo "TEXT MESSAGE FOR GUESTS"; } ?>` It should work for all controls if you do it right. Thank you, Olivia

Last edited 28 September 2017 by Support Team

Giuma
86 Posts
Giuma posted this 28 September 2017

wow thaks so much Olivia

wow thaks so much Olivia
Support Team
Support Team posted this 28 September 2017

Hi,

You're welcome.
Please let us know if you need our further assistance.

Thank you,
Olivia

Hi, You're welcome. Please let us know if you need our further assistance. Thank you, Olivia
Giuma
86 Posts
Giuma posted this 13 October 2017

this work well also in cms code

<?php $user jfactory::getuser(); $user_id?>get('id');
if ($user_id){
echo "TEXT MESSAGE FOR register ;

} else{

echo "TEXT MESSAGE FOR GUESTS id is $user_id ";
}
?>

this work well also in cms code &lt;?php $user jfactory::getuser(); $user_id?&gt;get('id'); if ($user_id){ echo "TEXT MESSAGE FOR register ; } else{ echo "TEXT MESSAGE FOR GUESTS id is $user_id "; } ?>
You must log in or register to leave comments