0

How to hide or restrict the FedEx calculation in the checkout page

I don't want to show the FedEx shipping method based on product attribute value at the checkout page?

For example

  1. The attribute code "shipping_applicable_for_fedex"
  2. If the attribute set as no, I don't want to show the FedEx shipping method on the checkout page
  3. If the attribute is set as yes, I want to show the FedEx shipping method on the checkout page

Can anyone please guide me to achieve it?

Thanks in advance

2 Answers 2

0

How to hide or restrict the FedEx calculation in the checkout page

I don't want to show the FedEx shipping method based on product attribute value at the checkout page?

The attribute code "is_test"
If the attribute set as no, I don't want to show the FedEx shipping method on the checkout page
If the attribute is set as yes, I want to show the FedEx shipping method on the checkout page

Can anyone please guide me to achieve it?

Thanks

0

This is my code.

<?php

namespace Podsix\Tweaks\Model;

use Podsix\Tweaks\Helper\Data;
use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Checkout\Model\Session as CheckoutSession;
use Magento\Catalog\Model\ProductFactory;

class ConfigProvider implements ConfigProviderInterface
{
    protected $dataHelper;
    protected $checkoutSession;
    protected $productFactory;

    
    public function __construct(
        Data $dataHelper,
        CheckoutSession $checkoutSession,
        ProductFactory $productFactory
    ) {
        $this->dataHelper = $dataHelper;
        $this->checkoutSession = $checkoutSession;
        $this->productFactory = $productFactory;
    }

    public function getConfig()
    {
        $showHazmatInfo = false;
        $quote = $this->checkoutSession->getQuote();
        foreach($quote->getAllItems() as $item) {
            $productId = $item->getProductId();
            $product = $this->productFactory->create()->load($productId);
            if($product->getIsHazmat()) {
                $showHazmatInfo = true;
            }
        }
        $hazmatBlock = $this->dataHelper->getBlockByIdentifier('hazardous_shipping_notice');
        $hazmatBlock_ups = $this->dataHelper->getBlockByIdentifier('hazardous_shipping_notice_ups');
        if($showHazmatInfo && $hazmatBlock->getIsActive()) {
            return [
                'is_hazmat_block' => $hazmatBlock_ups->getContent()
            ];
        }else{
            
        return [
                'is_hazmat_block' => $hazmatBlock->getContent()
            ];  
        }
        return [];
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.