• Resolved Nazar Hotsa

    (@bugnumber9)


    Hello.

    I’m looking for a way to create “purchase certificates”, so I thought a customized invoice will do the trick.

    However, I need to restrict the invoice creation to the first order only (using Woo Subscriptions). Is it possible to achieve this via some hook?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Yordan Soares

    (@yordansoares)

    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

    Thread Starter Nazar Hotsa

    (@bugnumber9)

    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.

    Plugin Contributor Yordan Soares

    (@yordansoares)

    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

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Restrict invoice creation to the first order only?’ is closed to new replies.