如何在缺货商品时将添加购物车按钮文本更改为缺货文本?
我已经尝试过了,但是没有用
if($_product->getStockItem()->getBackorders()!=0){
$buttonTitle=$this->__('Backorder');
}
答案 0 :(得分:0)
<?php
$obj = \Magento\Framework\App\ObjectManager::getInstance();
$stockRegistry = $obj->get('Magento\CatalogInventory\Api\StockRegistryInterface');
$stockitem = $stockRegistry->getStockItem($_product->getId(),$_product->getStore()->getWebsiteId());
if($stockitem->getBackorders() == 1):
$buttonTitle = __('Backorders');
else:
$buttonTitle = __('Add to Cart');
endif;
?>