Add Invoice PDF URL to Order Meta

[ad_1]

Hi @ifcstudios,

On version 3.6.0, launched 3 days ago (see changelog), we have improved the setting to configure the access type for the document link, under the Status tab:

Since there are more options now, we update the setting key from 'guest_access' to document_link_access_type, that is why the code stopped working.

However, I have updated the code, so it is working again for v3.6.0 or higher:

/**
 * PDF Invoices & Packing Slips for WooCommerce:
 * Save the PDF invoice link for guest access in the order data.
 * Note: Requires v3.6.0 or higher
 */
add_action( 'wpo_wcpdf_before_document', function( $document_type, $order ) {
	if( ! empty( $order ) && $document_type == 'invoice' ) {
		$debug_settings = get_option( 'wpo_wcpdf_settings_debug', array() );
		if( isset( $debug_settings['document_link_access_type'] ) && $debug_settings['document_link_access_type'] === 'guest' ) {
			$pdf_url = admin_url( 'admin-ajax.php?action=generate_wpo_wcpdf&template_type=".$document_type."&order_ids=" . $order->get_id() . "&order_key=' . $order->get_order_key() );
			// Save the PDF invoice link under the '_wcpdf_document_link' meta key
			update_post_meta( $order->get_id(), '_wcpdf_document_link', esc_url( $pdf_url ) );
		}
	}
}, 10, 2 );

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer