Question

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!!

Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top