• Resolved may

    (@mayeiei1)


    I want to bring file Packing-slip.php to print from the PHP Website page by pulling the WooCommerce REST API.

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

    (@yordansoares)

    Hi @mayeiei1,

    We store the document data within the order data, but not the encrypted PDF document as is.

    However, you could try storing the packing slip link within the order data, following the steps explained below:

    1. Go to WooCommerce > PDF Invoices > Status, and set the Document link access type setting to Guest:

    2. Activate the following code snippet in your site, in order to save the packing slip link within the '_wcpdf_packing_slip_link' meta key:

    /**
     * PDF Invoices & Packing Slips for WooCommerce:
     * Save the PDF packing slip 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 == 'packing-slip' ) {
    		$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_invoice_link' meta key
    			update_post_meta( $order->get_id(), '_wcpdf_'.$document_type.'_link', esc_url( $pdf_url ) );
    		}
    	}
    }, 10, 2 );

    If you haven’t worked with code snippets (actions/filters) or functions.php before, read this guide: How to use filters

    Please note that _wcpdf_packing_slip_link meta key will be hidden. However, you can remove the underscore (_) under the 12th line, if you want to display the custom fields are, within the single order view:

    update_post_meta( $order->get_id(), 'wcpdf_'.$document_type.'_link', esc_url( $pdf_url ) );
    Thread Starter may

    (@mayeiei1)

    After I do as you indicated above, what should I do in my Website PHP code? Continue so that can print the Packaging-slip.php from the PHP site?

    Plugin Contributor alexmigf

    (@alexmigf)

    Hi,

    Where do you want to print it from? A specific page from your site?

    Thread Starter may

    (@mayeiei1)

    Yes, I want to print from my website PHP using API from WordPress Woocommerce.

    Plugin Contributor Yordan Soares

    (@yordansoares)

    After I do as you indicated above, what should I do in my Website PHP code? Continue so that can print the Packaging-slip.php from the PHP site?

    After saving the guest URL for the PDF document, within the WooCommerce order data, you will be able to get it from your PHP app, using the WooCommerce REST API.

    For instance, you could retrieve the JSON response like this (after configuring your app with the steps explained in this guide: Getting started with the REST API):

    // 123 is the order ID
    https://example.com/wp-json/wc/v3/orders/123

    Then search by _wcpdf_invoice_link within the meta_data field.

    Plugin Contributor Yordan Soares

    (@yordansoares)

    @mayeiei1,

    Since we haven’t heard back from you in the last two weeks, we’re assuming you solved this issue, so I’ll go ahead and mark this ticket as Resolved.

    Feel free to reply to this topic is you still need help with this, or open a new topic if you have any other questions!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Pulling the Packing-slip.php to print from WooCommerce REST API’ is closed to new replies.