If this is your request data for an AJAX POST:
data: {
action: 'gs_order',
nonce_data: ajax_vars.nonce,
product_groups: $(this).data("pgid"),
products: $(this).data("pid")
},
Then you access product_groups
and products
like this:
$data = [
'product_groups' => $_POST['product_groups'],
'products' => $_POST['products'],
];
Just make sure you sanitize and escape the data as required. If they’re going to be IDs you can just use absint()
:
$data = [
'product_groups' => absint( $_POST['product_groups'] ),
'products' => absint( $_POST['products'] ),
];
And to verify the nonce, use:
check_ajax_referer( 'gs_nonce', 'nonce_data' );
So all together:
function gs_ajax_callback()
{
check_ajax_referer( 'gs_nonce', 'nonce_data' );
$data = [
'product_groups' => absint( $_POST['product_groups'] ),
'products' => absint( $_POST['products'] ),
];
$order = new Group_Shop_Order();
$order->create_order( 194, $data['products'], $data['product_groups'] );
wp_die();
}
PS: I have no idea what Group_Shop_Order
is, or how it works, so I can’t say whether the usage of $order->create_order()
is correct. I’m just going of your code for that.