• Resolved mitchellvandevorst

    (@mitchellvandevorst)


    Hi there,

    I’ve added a custom template to my child theme in SFTP only the template isnt loading.

    I get an error message with the info in a HTML, not a downloadable PDF.

    The error message reads the following:

    Fatal error: Using $this when not in object context
    #0 /nas/content/live/ecoffeecupcom/wp-content/themes/atelier-child/woocommerce/pdf/ecoffeecom/invoice.php(197): WC_Email::get_from_address()
    #1 /nas/content/live/ecoffeecupcom/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/includes/documents/abstract-wcpdf-order-document.php(704): include(‘/nas/content/li…’)
    #2 /nas/content/live/ecoffeecupcom/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/includes/documents/abstract-wcpdf-order-document.php(608): WPO\WC\PDF_Invoices\Documents\Order_Document->render_template(‘/nas/content/li…’, Array)
    #3 /nas/content/live/ecoffeecupcom/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/includes/documents/abstract-wcpdf-order-document.php(590): WPO\WC\PDF_Invoices\Documents\Order_Document->get_html()
    #4 /nas/content/live/ecoffeecupcom/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/includes/documents/abstract-wcpdf-order-document.php(626): WPO\WC\PDF_Invoices\Documents\Order_Document->get_pdf()
    #5 /nas/content/live/ecoffeecupcom/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/includes/class-wcpdf-main.php(304): WPO\WC\PDF_Invoices\Documents\Order_Document->output_pdf(‘download’)
    #6 [internal function]: WPO\WC\PDF_Invoices\Main->generate_pdf_ajax(”)
    #7 /nas/content/live/ecoffeecupcom/wp-includes/class-wp-hook.php(286): call_user_func_array(Array, Array)
    #8 /nas/content/live/ecoffeecupcom/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(”, Array)
    #9 /nas/content/live/ecoffeecupcom/wp-includes/plugin.php(465): WP_Hook->do_action(Array)
    #10 /nas/content/live/ecoffeecupcom/wp-admin/admin-ajax.php(167): do_action(‘wp_ajax_generat…’)
    #11 {main}

    I was working before, but we did a migration – I checked the SFTP folders, and the template is still there, just not loading properly.

    Thank you in advance,

    Regards,

    Mitch

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

    (@pomegranate)

    Hello Mitch,
    It looks like the plugin is actually loading the custom template correctly, but there’s a customization in your invoice.php document that tries to load something the wrong way. Can you temporarily switch to the Simple template in the plugin settings to see if this indeed resolves the issue? If yes, I recommend checking your customizations around line 197 in invoice.php, this is what the error is referring to. If you can share your custom invoice.php file on something like https://pastebin.com we can also see if we spot something wrong there.

    Let us know your findings!

    Thread Starter mitchellvandevorst

    (@mitchellvandevorst)

    Hi Ewout – I really appreciate the quick reponse, Thank you!

    Ive set the default template and that is loading correctly, so it must be in the invoice.php – as you mentioned.

    Line 197: If you have and questions, please email: <?php echo WC_Email::get_from_address(); ?>

    I’ve uploaded the php code to pastebin: https://pastebin.com/iP2CZdyw

    If you wish to download a copy here: https://www.dropbox.com/s/fbhjbbuwe0u7918/invoice.php?dl=0

    Looking forward hearing from you,

    Regards,

    Mitch

    Plugin Contributor Ewout

    (@pomegranate)

    I see – that won’t work because the WC_Email class needs to be instantiated to be able to call that function, which requires the object ($this) to pass to the filter:
    https://github.com/woocommerce/woocommerce/blob/3.7.0/includes/emails/class-wc-email.php#L614-L617

    You may be able to fix this by using this instead (untested):

    
    <?php $email = new WC_Email(); echo $email->get_from_address(); ?>
    

    But I would stay away from this because it’s not supposed to be used like that.

    Either enter the email address directly without any function calls, or if you really need to do it dynamically, call the setting directly:

    
    <?php echo get_option( 'woocommerce_email_from_address' ); ?>
    
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Not Loading custom PDF Invioce’ is closed to new replies.