plugin development - Get WooCommerce custom payment gateway values in process_payment function for Blocks checkout

admin2025-01-07  7

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 5 hours ago.

Improve this question

I am creating custom payment plugin for woocommerce. I am facing issue while getting the checkout form data in process_payment function of woocommerce payment class.

I am using following JS code to make payment gateway compatible with woocommerce Block checkout.

const PaySettings= window.wc.wcSettings.allSettings.paymentMethodData.pay;

const Paylabel = window.wp.htmlEntities.decodeEntities( PaySettings.title );

const PayMethod = ({ id, label,value }) => {

    return React.createElement('div', {className: 'pay-methods'},
        React.createElement('label', {htmlFor: id}, label),
        React.createElement('input', {type: 'radio', name: id, value: value, onChange: (e) => e.target.value}),
    );
};

const Content = () => {
    
    return React.createElement('div', {className: 'pay-methods-cont'}, null,
        React.createElement('img', {src: PaySettings.icon}),
        React.createElement('p', null, window.wp.htmlEntities.decodeEntities(PaySettings.description ||  '')),
        React.createElement(PayMethod, {id: 'pay_method', label: 'JazzCash',value: 'jazzcash' }),
        React.createElement(PayMethod, {id: 'pay_method', label: 'EasyPaisa',value: 'easypaisa' })
    );

}
const Icon = () => {
    return React.createElement('div', {className: 'custom-input-field'},
        React.createElement('img', {src: PaySettings.icon}))
}


const AP_Gateway = {
    name: 'pay',
    label: Paylabel,
    icon: Icon,
    content: Object(window.wp.element.createElement)(Content, null),
    edit: Object(window.wp.element.createElement)(Content, null),
    canMakePayment: () => true,
    ariaLabel: Paylabel,
    supports: {
        features: ['products'],//settings.supports,
    },
};

window.wc.wcBlocksRegistry.registerPaymentMethod( AP_Gateway )

It is showing radio options on checkout as payment gateway options but when I select any of the option I am not able to receive value in process_payment function.
public function process_payment( $order_id ) {
            
   echo "<pre>";print_r($_POST);echo "</pre>";die;
            
}


I am doing something wrong or missing something ? Please help.
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736252917a84.html

最新回复(0)