Hide Wishlist Or Add To Cart Button?

Hide Wishlist and add to cart button after a user adds a product to wishlist or to their cart?

for example:

{if user adds item "A" to cart}

add to cart button for item "A" hide for that user only

{/if}

Hello.

You can check in the session if the customer has a product in the basket and then use the hook to block the show of these buttons.

Best regards

Robert

What's the php code for this?

i tried the below code and it didn't work..

if (!isset($cart['products'][$_id])) {

}

What's the php code for this?

i tried the below code and it didn't work..

if (!isset($cart['products'][$_id])) {

}

Looks correctly. Where did you add this code??

Looks correctly. Where did you add this code??

I added it to the smarty function and then assigned a true or false statement yet no lock..

I tried this.. on the smarty function

function smarty_function_cart_hide($params, &$smarty) {
if (!isset($cart['products'][$_id])) {
$smarty->assign('cart_added', false);
} else {
$smarty->assign('cart_added', true);
}
}
then on the tpl i used
{cart_hide}
{if $cart_added}Add to Cart{else}view in your cart{/if}
....yet no luck...

And so how would a customer update product options for the item or change the quantity? Going to force them to go to the cart to do this?

And so how would a customer update product options for the item or change the quantity? Going to force them to go to the cart to do this?

I'm hoping that if someone can help me figure it out, when a customer select a different option the add to cart should reappear, just like on ebay...

Your code will not work since $cart and $_id are not passed to your function. Please also note that $_id parameter is not ID of the product, but ID generated by the fn_generate_cart_id function. It takes into account ID, selected options and extra parameters

Your code will not work since $cart and $_id are not passed to your function. Please also note that $_id parameter is not ID of the product, but ID generated by the fn_generate_cart_id function. It takes into account ID, selected options and extra parameters

Can you help me out with a code that will do this?

Try something like

func.php:

function fn_check_product_in_cart($product_id) {
    $in_cart = false;
    $cart = Tygh::$app['session']['cart'];
    if (!empty($cart['products'])) {
        foreach ($cart['products'] as $product) {
            if ($product['product_id'] == $product_id) {
                $in_cart = true;        
                break;
            }
        }    
    }
    return $in_cart;
}

your template:

{$cart_added = $product.product_id|fn_check_product_in_cart}
{if !$cart_added}Add to Cart{else}view in your cart{/if}

(!) Not tested

Try something like

func.php:

function fn_check_product_in_cart($product_id) {
    $in_cart = false;
    $cart = Tygh::$app['session']['cart'];
    if (!empty($cart['products'])) {
        foreach ($cart['products'] as $product) {
            if ($product['product_id'] == $product_id) {
                $in_cart = true;        
                break;
            }
        }    
    }
    return $in_cart;
}

your template:

{$cart_added = $product.product_id|fn_check_product_in_cart}
{if !$cart_added}Add to Cart{else}view in your cart{/if}

(!) Not tested

Oh lord, it works!!!!!!!!!!!!!!! You the best..! Thanks, I really appreciate it! any way to get this for the wishlist button too?

Oops it doesn't take the change option into consideration.. can you help me fix this.. Thanks

Thanks, I really appreciate it! any way to get this for the wishlist button too?

Use similar function but get content wishlist with the following line

$cart = Tygh::$app['session']['wishlist'];

Oops it doesn't take the change option into consideration.. can you help me fix this.. Thanks

In this case more complex changes are required. You should pass selected options to the function and check it there

How can i pass the selected option please?

Try to use

{$cart_added = $product.product_id|fn_check_product_in_cart:$product.selected_options}

Try to use

{$cart_added = $product.product_id|fn_check_product_in_cart:$product.selected_options}

i tried it, but it didn't change back to add to cart when option is changed..

As I said, more complex changes are required

I tried to the below code, can you please give a tweak, thanks

if (!empty($cart['products']) && is_array($cart['products'])) {
$product_not_in_cart = true;
foreach ($cart['products'] as $k => $v) {
// Check if the product with the same selectable options already exists ( for tracking = O)
if ($k != $cart_id) {
if (isset ($product['tracking']) &&
(
$product['tracking'] == ProductTracking::TRACK_WITHOUT_OPTIONS &&
$v['product_id'] == $product_id
) ||
(
$product['tracking'] == ProductTracking::TRACK_WITH_OPTIONS &&
@$v['selectable_cart_id'] == $selectable_cart_id
)
) {
$current_amount -= $v['amount'];
}
} else {
$product_not_in_cart = false;
}
}

This code will not work correctly. Hire someone to create required functions for you

I just sent you a direct message, added to that i want the options to save on the product page as well... Thanks