Skip to content

Instantly share code, notes, and snippets.

@esedic
Created August 7, 2026 08:50
Show Gist options
  • Select an option

  • Save esedic/ddc0a838ec8490795062d6647c952f78 to your computer and use it in GitHub Desktop.

Select an option

Save esedic/ddc0a838ec8490795062d6647c952f78 to your computer and use it in GitHub Desktop.
Samodejno zaključi brezplačna digitalna naročila (0,00 €). Deluje samo za naročila, ki vsebujejo izključno virtualne/prenosljive izdelke.
/**
* Samodejno zaključi brezplačna digitalna naročila (0,00 €).
* Deluje samo za naročila, ki vsebujejo izključno virtualne/prenosljive izdelke.
*/
add_filter( 'woocommerce_payment_complete_order_status', 'auto_complete_free_digital_orders', 10, 3 );
function auto_complete_free_digital_orders( $status, $order_id, $order ) {
// Varnostna preverba
if ( ! $order instanceof WC_Order ) {
return $status;
}
// Naročilo mora biti brezplačno
if ( (float) $order->get_total() !== 0.0 ) {
return $status;
}
// Preveri, da so vsi izdelki virtualni ali prenosljivi
foreach ( $order->get_items() as $item ) {
$product = $item->get_product();
if ( ! $product ) {
continue;
}
if ( ! $product->is_virtual() && ! $product->is_downloadable() ) {
return $status;
}
}
// Samodejno nastavi status na completed
return 'completed';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment