I have an attribute "brand" with type Swatch.
I have created many brands as an option in this attribute.
I want to filter brands label which are starts with a particular letter (ex. A or B or C).
Well, I am using manufacturer as a brand so in my case.
Make Magento_catalog->templates->product->view->brand_info.phtml and put that code.
<?php
$_helper = $this->helper('Magento\Catalog\Helper\Output');
$_product = $block->getProduct();
$_code = $block->getAtCode();
$_className = $block->getCssClass();
$_attributeLabel = $block->getAtLabel();
$_attributeType = $block->getAtType();
$_attributeAddAttribute = $block->getAddAttribute();
if ($_attributeLabel && $_attributeLabel == 'default') {
$_attributeLabel = $_product->getResource()->getAttribute($_code)->getFrontendLabel();
}
$_attributeValue =$_product->getResource()->getAttribute($_code)->getFrontend()->getValue($_product);
?>
<?php if ($_attributeValue): ?>
<div class="product_<?php echo $_className?>"><?php if ($_attributeLabel != 'none'): ?><h4 class="brand" itemscope itemtype="http://schema.org/Brand">Brand: </h4><?php endif; ?><div class="brand-value" itemprop="brand"<?php echo $_attributeAddAttribute;?>><h4> <?php echo $_attributeValue; ?></h4></div>
</div>
<?php endif; ?>
<style>
.brand{
/*color:#D00000;*/
float:left;
margin:0;
}
.brand-value{
color:#008000;
}
</style>
then make a layout in Magento_catalog->layout->catalog_product_view.xml put that code according to your attribute name.
<?xml version="1.0"?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="product.info.price">
<block class="Magento\Catalog\Block\Product\View\Description" name="product.info.brand" template="product/view/brand_info.phtml" before="-">
<arguments>
<argument name="at_call" xsi:type="string">getBrand</argument>
<argument name="at_code" xsi:type="string">manufacturer2</argument>
<argument name="css_class" xsi:type="string">brand</argument>
<argument name="at_label" xsi:type="string">default</argument>
<argument name="add_attribute" xsi:type="string">itemprop="manufacturer2"</argument>
</arguments>
</block>
</referenceContainer>
</body>
</page>