Last active
August 23, 2024 12:59
-
-
Save kilbot/751bf4705a6e7e60dac94705191acba9 to your computer and use it in GitHub Desktop.
Triggering the Lottery for WooCommerce plugin from the WC REST API
This file contains 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 | |
/** | |
* Add this to your theme's functions.php file. | |
*/ | |
function wc_rest_create_ticket_on_placing_order($order, $request) { | |
if (class_exists('LTY_Order_Handler')) { | |
// Get the order ID | |
$order_id = $order->get_id(); | |
// Initialize the LTY_Order_Handler class | |
LTY_Order_Handler::init(); | |
// Trigger the create_ticket_on_placing_order method with the order ID | |
LTY_Order_Handler::create_ticket_on_placing_order($order_id); | |
} | |
} | |
add_action('woocommerce_rest_insert_shop_order_object', 'wc_rest_create_ticket_on_placing_order', 10, 2); | |
function wcpos_force_trigger_update_lottery_ticket_in_order($id, $order) { | |
if (class_exists('LTY_Order_Handler') && woocommerce_pos_request()) { | |
// Initialize the LTY_Order_Handler class | |
LTY_Order_Handler::init(); | |
// Trigger the update_lottery_ticket_in_order with the order | |
LTY_Order_Handler::update_lottery_ticket_in_order($id, $order); | |
} | |
} | |
add_action('woocommerce_order_status_completed', 'wcpos_force_trigger_update_lottery_ticket_in_order', 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment