Hi @bugnumber9,
Yes, it is possible. Do you know if the renewal orders store a dedicated meta value that we can use as a condition to block the invoice for those kind if orders?
See: Finding WooCommerce custom fields
Hey @yordansoares.
Many thanks for your reply.
I’ve examined order metadata (in wp_postmeta table, this particular project is not using HPOS yet).
Parent orders have ‘_created_via’ field set to ‘checkout’ while renewal orders have it set to ‘subscription’.
Also, renewal orders have ‘_subscription_renewal’ field which contains the order ID or the parent order. Parent orders don’t have this field.
Hi @bugnumber9:
Please try with this code snippet I just wrote as a courtesy for you:
/**
* PDF Invoices & Packing Slips for WooCommerce:
* Enable the PDF invoice only for new Subscriptions (disable it for renewals)
*/
add_filter( 'wpo_wcpdf_document_is_allowed', function( $allowed, $document ) {
if ( ( $order = $document->order ) && $document->type == 'invoice' && ! $document->exists() ) {
$is_a_renewal = $order->get_meta( '_subscription_renewal' );
$allowed = ! empty( $is_a_renewal ) ? false : true;
}
return $allowed;
}, 10, 2 );
If you haven’t worked with code snippets (actions/filters) or functions.php before, read this guide: How to use filters