EDIT* I have rewritten original question.
I am trying to force the Lottery for Woocommerce plugin on WordPress to auto generate ticket numbers in the thankyou page instead of manually doing this for every order in the WP dashboard.
I can't find the item ID of what is in the basket.
Latest error:
Uncaught ReferenceError: item_id is not defined
<anonymous> https://www.unicorncompetitions.com/checkout/order-received/11073/?key=wc_order_02bCFA2GQQTa1&doing_wp_cron=1712209272.9610309600830078125000:2402
jQuery 2
e
t
11073:2402:17
<anonymous> https://www.unicorncompetitions.com/checkout/order-received/11073/?key=wc_order_02bCFA2GQQTa1&doing_wp_cron=1712209272.9610309600830078125000:2402
jQuery 2
Here is my code I've got it down to:
add_action('woocommerce_thankyou', 'generate_ticket_on_thankyou_page');
function generate_ticket_on_thankyou_page() {
?><script>
jQuery(function($) {
$(document).ready(function() {
var data = ({
action: 'lty_generate_automatic_ticket_edit_order',
item_id: item_id,
order_id: $('.lty-order-id').val(),
answer_id: $('.lty-question-answer-id').val(),
lty_security: lty_shop_order_params.lty_automatic_ticket_nonce,
});
$.post(ajaxurl, data, function (res) {
LTY_Shop_Order.unblock($('.woocommerce_order_items').find('#order_line_items'));
if (true === res.success) {
alert(lty_shop_order_params.lty_success_message);
location.reload();
} else {
alert(res.data.error);
}
}
);
},
)});
</script>
<?php
};