One product "Outofstock" and save in wishlist then after, when after login in wishlist form click on "Add All to Cart" button. But it's not working because of "Outofstock" product in wishlist. So how can remove when if any one "Outofstock" product in wishlist, "Add All to Cart" button is disabled.

Note : Outofstock product need to add in wishlist.

  • So, your question is only: How to disable "Add All to Cart" button when one of products is out stock in Wishlist page? Commented May 31, 2018 at 6:22
  • Yes. @KhoaTruongDinh Commented May 31, 2018 at 6:30

1 Answer 1


The most important thing is that we need to know where is this button: vendor/magento/module-wishlist/view/frontend/templates/button/tocart.phtml

<?php if ($block->getWishlist()->getItemsCount() && $block->getWishlist()->isSalable()): ?>
    <button type="button" data-role="all-tocart" title="<?= $block->escapeHtmlAttr(__('Add All to Cart')) ?>" class="action tocart">
        <span><?= $block->escapeHtml(__('Add All to Cart')) ?></span>
<?php endif;?>

As we can see, Magento checked the salable item(s) already $block->getWishlist()->isSalable(). But, seem that doesn't enough... I'm going to remove this check and use our custom one.

Let's create a custom module:


<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    <preference for="Magento\Wishlist\Block\Customer\Wishlist\Button"
                type="Vendor\Wishlist\Block\Customer\Wishlist\Button" />

We will override block Magento\Wishlist\Block\Customer\Wishlist\Button. And create our custom method to check all the salable items.



namespace Vendor\Wishlist\Block\Customer\Wishlist;

class Button extends \Magento\Wishlist\Block\Customer\Wishlist\Button
     * @return bool
    public function canAddAllToCart()
        $wishlist = $this->getWishlist();
        foreach ($wishlist->getItemCollection() as $item) {
            if (!$item->getProduct()->getIsSalable()) {
                return false;
        return true;

Set the custom template for wishlist button.


<?xml version="1.0"?>

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        <referenceBlock name="customer.wishlist.button.toCart">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Vendor_Wishlist::buttons/tocart.phtml</argument>

Replace $block->getWishlist()->isSalable() by our custom method: canAddAllToCart()



// @codingStandardsIgnoreFile

/** @var \Vendor\Wishlist\Block\Customer\Wishlist\Button $block */

<?php if ($block->getWishlist()->getItemsCount() && $block->canAddAllToCart()): ?>
    <button type="button" data-role="all-tocart" title="<?= $block->escapeHtmlAttr(__('Add All to Cart')) ?>" class="action tocart">
        <span><?= $block->escapeHtml(__('Add All to Cart')) ?></span>
<?php endif;?>

Remember to create module.xml and registration.php files.

Magento version is 2.2.2.

  • @KhosTruongDinh hii! i want to restrict some of the products to addtocart from the wishlist page. can you please help me? Commented Apr 2, 2021 at 4:18

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.