Created
October 19, 2024 11:02
-
-
Save Tusko/18d6dc31f8963331d1f663aa1ec8dccf to your computer and use it in GitHub Desktop.
Оплата картою пакунок малюка для monobank
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// morkva-monopay extension | |
add_action('woocommerce_checkout_create_order', 'add_cheque_metadata', 10, 2); | |
function add_cheque_metadata($order, $data) { | |
if($order->get_payment_method() === 'cheque') { | |
$order->update_meta_data('_pakunok_maluka', 'yes'); | |
$order->save(); | |
} | |
} | |
add_action('woocommerce_checkout_order_processed', 'yk_redirect_to_monobank', 10, 3); | |
function yk_redirect_to_monobank($order_id, $posted_data, $order) { | |
if($order->get_payment_method() === 'cheque' && $order->get_meta('_pakunok_maluka') === 'yes') { | |
// Clear the cart | |
//WC()->cart->empty_cart(); | |
// Get the Monobank payment gateway | |
$available_gateways = WC()->payment_gateways->get_available_payment_gateways(); | |
$monobank_gateway = $available_gateways['morkva-monopay']; | |
$order = wc_get_order($order_id); | |
// Redirect to Monobank payment page | |
if($monobank_gateway) { | |
$order->set_payment_method($monobank_gateway); | |
$monobank_gateway->process_payment($order_id); | |
$order->save(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment