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 );
Thank you so much for the response! I just tested out the snippet (we’re on v3.6.1) and still doesn’t seem to add the URL to the custom meta. If we can get this to work, we will be purchasing the premium version so really appreciate your help!
Please note that the Code Snippets plugin have two buttons: Save Changes and Save Changes and Activate: Make sure that you have clicked in this latter.
Shoot. Snippet is active and we’ve placed a few test orders but still no luck. Screenshot here of our set up just in case you notice anything we missed. Thanks again for your help!
Did you open the PDF invoice in the order in which you are testing? Please note that you have to run this task for orders generated in the time window between updating to v3.6.0 and activating this code snippet.
Thanks for your help @yordansoares. Yes we’ve tried to delete the document and regenerate it as well, but still no luck. The _wcpdf_document_link field does not appear in the order meta. Appreciate you trying anyways! We’ll try to figure something else out.
Please note that meta key fields starting with underscore are not displayed directly in the order, i.e. they are hidden.
For instance:
wcpdf_document_link – Will be displayed under the Custom Fields panel in the order details.
_wcpdf_document_link – Will be hidden.
That said, with the Store Toolkit for WooCommerce plugin, you will be able to see all the order metadata, including hidden fields. Give it a try and let me know if you finally managed to find it
I see it! It is in the hidden fields under _wcpdf_document_link
It also has a value that links correctly. Now… how do we get this to appear as a visible field? It’s totally okay if you aren’t comfortable helping with this process. I really appreciate all your help so far! 🙂