How to change configurable product “Add to Cart” button label to something else in the category page

magento.stackexchange https://magento.stackexchange.com/questions/294371

سؤال

I am building a custom theme

I need to change the configurable products "Add to Cart" button label to "See Options" in category page.

Only for the configurable product.

Any Help will Appreciate!!

هل كانت مفيدة؟

المحلول

If you want to change Add to Cart to See Options on product category (list page), You need to edit following file:

app/design/frontend/{Package}/{theme}/Magento_Catalog/templates/product/list.phtml

on list.phtml, You can check product type i.e

$_product->getTypeId();//it will give product type simple,configurable 

Based on product type you can change Add to cart text like:

<?php if($_product->getTypeId()=='configurable')  { ?>
<a class="product-button"
   href="<?= /* @escapeNotVerified */ $_product->getProductUrl() ?>">
    <?= $block->escapeHtml(__('See Options')) ?>
</a>
<?php } else { ?>
    <button type="submit"
            title="<?= $block->escapeHtml(__('Add to Cart')) ?>"
            class="action tocart primary">
        <span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
    </button>
<?php } ?> 

Above code will change text only for configurable product and add a link to product view page.

Note: You need to remove original Add to cart button and add code given in solution.

نصائح أخرى

I assume you find the list file from which the list of product code is there. So, just need to check in add to cart button with this code.

if($product->getTypeId() == \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE)    
{    
     echo "product is configurable";
}

You just need to put add to cart label code in between the if condition and your work will be done.

Thanks

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top