Skip to content

Instantly share code, notes, and snippets.

@InpsydeNiklas
Created April 28, 2023 09:29
Show Gist options
  • Save InpsydeNiklas/42ec9699e532b447a0d643637f850d31 to your computer and use it in GitHub Desktop.
Save InpsydeNiklas/42ec9699e532b447a0d643637f850d31 to your computer and use it in GitHub Desktop.
Autocomplete orders for downloadable products when using ppcp-gateway
<?php
add_action('woocommerce_payment_complete', 'ppcp_gateway_set_downloadable_order_completed', 10, 1);
function ppcp_gateway_set_downloadable_order_completed($order_id) {
$order = wc_get_order($order_id);
if (!$order) {
return;
}
// Check if the order payment method is ppcp-gateway
if ($order->get_payment_method() !== 'ppcp-gateway') {
return;
}
$all_downloadable = true;
// Loop through order items to check if all products are downloadable
foreach ($order->get_items() as $item) {
$product = $item->get_product();
if (!$product->is_downloadable()) {
$all_downloadable = false;
break;
}
}
// If all products are downloadable, set order status to 'completed'
if ($all_downloadable) {
$order->update_status('completed', 'All products are downloadable, setting order status to completed.');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment