-
-
Save InpsydeNiklas/42ec9699e532b447a0d643637f850d31 to your computer and use it in GitHub Desktop.
Autocomplete orders for downloadable products when using ppcp-gateway
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_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