Skip to content

Instantly share code, notes, and snippets.

@mircobabini
Created February 14, 2023 17:28
Show Gist options
  • Save mircobabini/e0cd068002718f2d98a1690aca00a55b to your computer and use it in GitHub Desktop.
Save mircobabini/e0cd068002718f2d98a1690aca00a55b to your computer and use it in GitHub Desktop.
<?php
define( 'INVOICE_GENERATION_MINIMUM_SUBTOTAL', 100 ); // se subtotale >= X€ IVA ESCUSA, allora genero la fattura
add_filter( 'wpo_wcpdf_document_is_allowed', function ( $allowed, $document ) {
if ( ! $document->exists() && ! empty( $order = $document->order ) ) {
if ( ! is_callable( array( $order, 'get_subtotal' ) ) ) {
return false;
}
// check order total & setting
$order_subtotal = $order->get_subtotal();
if ( $order_subtotal < INVOICE_GENERATION_MINIMUM_SUBTOTAL ) {
return false;
} else {
return $allowed;
}
} else {
return $allowed;
}
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment