How to Delete Catalog Price Rule by rule id Magento 2?

You can delete catalog rule by rule id in Magento 2 using delete by id method of catalog rule repository interface.

You can see a list of available Catalog Price rules from the admin panel by Marketing -> Promotions -> Catalog Price rule.

You need to select id from the list of available catalog price rules grid and pass rule id to the given method from the code snippet. Using the below code snippet you can delete Catalog rule Price programmatically with Magento standard way.

<?php
namespace Jesadiya\CatlogRuleDelete\Model;

use Psr\Log\LoggerInterface;
use Magento\CatalogRule\Api\CatalogRuleRepositoryInterface;
use Magento\Framework\Exception\NoSuchEntityException;

class CatlogRuleDeleteById
{
    /**
     * @var CatalogRuleRepositoryInterface
     */
    private $catalogRuleRepository;

    public function __construct(
        CatalogRuleRepositoryInterface $catalogRuleRepository,
        LoggerInterface $logger
    ) {
        $this->catalogRuleRepository = $catalogRuleRepository;
        $this->logger = $logger;
    }

    /**
     * Delete catalog rule by id
     *
     * @param int $ruleId
     *
     * @return bool
     */
    public function deleteRuleByID(int $ruleId): bool
    {
        $rule = false;
        try {
            $rule = $this->catalogRuleRepository->deleteById($ruleId);
        } catch (NoSuchEntityException $exception) {
            $this->logger($exception->getMessage());
        }

        return $rule;
    }

In the above method, You can easily delete any catalog price rule by catalog rule id. You need to use CatalogRuleRepositoryInterface to delete a specific rule.

Output:
If You have passed valid rule id, Rule will be deleted from the Catalog rule price Grid. If the rule id is not found, the result will be False.