0

In Magento2 / Adobe commerce, create order through admin panel, select the payment method mandatory create the order, I want to remove the payement method from create order from admin case only in magento 2.4.x version, How can I place admin create order without mandatory select payment method

Page: http://domainame.com/admin/sales/order_create/index/

enter image description here

4
  • Without select payment method not allow to place the order Feb 27 at 11:30
  • If the product price is zero then it should be work Feb 27 at 11:30
  • @HardikMakwana Thanks for your response, I hope, If any method implement like event or plugin through possible implement
    – junaidh
    Feb 27 at 12:22
  • There is no any event or plugin available if the quote subtotal has a price above 0 Feb 27 at 12:23

1 Answer 1

0

It is impossible to remove payment method from the equation as it is required for order. At it was said in comments it is possible to use zero-subtotal checkout if subtotal is 0, but it seems not what was asked here. It is possible to remove payment block and to create plugin to set some payment by default. Then payment will be set. In your custom module you'd need to create directory view/adminhtml/layout Then 3 files should be created here in order to remove payment section from admin checkout.

sales_order_create_index.xml
sales_order_create_load_block_data.xml
sales_order_create_load_block_billing_method.xml

The content of all of them should look like

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="billing_method" remove="true"/>
    </body>
</page>

Then in module's etc/adminhtml/di.xml new custom plugin should be added

<type name="Magento\Sales\Model\AdminOrder\Create">
    <plugin name="custom_plugin_name" type="Vendorname\Modulename\Class\Pluginname" />
</type>

In that custom plugin one could add

<?php
declare(strict_types=1);

namespace Vendorname\Modulename\Class;

use Magento\OfflinePayments\Model\Checkmo;
use Magento\Sales\Model\AdminOrder\Create as Subject;

class Pluginname
{

    /**
     * Import custom post data
     *
     * @param Subject $subject
     * @param array $data
     * @return array
     */
    public function beforeImportPostData(Subject $subject, array $data): array
    {

        $data['payment_method'] = Checkmo::PAYMENT_METHOD_CHECKMO_CODE;//Here we can hardcode payment method

        return [$data];
    }
}

Some custom payment method could be created using Check Money order as example. Then we could enable that payment method only for admin area via plugins. It seems too much to describe whole solution here as it would result in module, which is more than just an answer. But I hope that the main idea might help somebody to understand the direction.

3
  • Thanks for sharing code, use Magento\OfflinePayments\Model\Purchaseorder; $data['payment_method'] = Purchaseorder::PAYMENT_METHOD_PURCHASEORDER_CODE; I have try to change "Purchase Order" payment method, It's showing "Purchase order number is a required field" ,@Oleksandr If you please provide the payment method "Purchase Order" related code
    – junaidh
    Feb 29 at 12:18
  • @junaidh Purchase Order requires unique reference entered in the payment section in admin or frontend checkout. In cache you'd like to automate that, then in beforeImportData please add $data['po_number'] = 'some_random_string'; I think for random string you could use some static thing like quote ID or quote create time. You could add some sole for hashing. Just a very simple example $data['po_number'] = sha1($subject->getQuote()->getCreatedAt()); But I'd use better hashing rather than just sha1(). Magento has own hasher \Magento\Framework\Encryption\EncryptorInterface::hash(). Mar 1 at 8:35
  • It look your Check Money order payment method code work fine, Thanks
    – junaidh
    Mar 8 at 5:19

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.