PHP code example of pixelopen / magento-product-main-category
1. Go to this page and download the library: Download pixelopen/magento-product-main-category library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pixelopen / magento-product-main-category example snippets
$mainCategory = $product->getMainCategory();
// OR
$mainCategory = $product->getData('main_category');
// OR
$mainCategory = $product->getCustomAttribute('main_category')?->getValue();