Forum Replies Created

Viewing 15 replies - 31 through 45 (of 92 total)
  • Thread Starter torbent

    (@torbentschechnegmailcom)

    Hello,
    does anybody know why this happens?

    I digged a bit deeper and can see that the ?removed_item=1 action has this value in the request header:

    Referer: https://www.domain.com

    In the correct setup this Referer has this value: Referer: https://www.domain.com/cart

    So the referer is not the correct one and the user gets not redirected to the cart.

    Thread Starter torbent

    (@torbentschechnegmailcom)

    I solved it, thanks for your support!

    Thread Starter torbent

    (@torbentschechnegmailcom)

    Hey Tom,
    thanks for getting back to me. I solved it partly. The reason at my side was, that I did not return “USD”, I returned usd. So the missing uppercase made the point.

    However I have the strange behaviour that I have different results when I am logged in and when I am not logged in. So in the cart I still have the product in CAD, but only when I am not logged in as a customer.

    How is that possible? I debugged this filter woocommerce_get_cart_item_from_session and item[‘data’] has the currency USD.

    Do you have any idea why there is a different behaviour on the cart page depended on the state of the user (logged in, logged out)?

    Thread Starter torbent

    (@torbentschechnegmailcom)

    I did find it, but there’s a bug in the plugin. I can change the price for display but when I add it to the cart the old price is taken into account:

    https://d.pr/i/VLRth

    I create a ticket…

    Thread Starter torbent

    (@torbentschechnegmailcom)

    Hey Ewout,
    thanks for the quick reply. This is not WPML related, I just want to tell the pdf before creation that it should make use of these files:

    woocommerce-pdf-invoices-packing-slips-de_DE.po
    woocommerce-pdf-invoices-packing-slips-de_DE.mo

    And I thought this is possible, by setting the plugin_locale to “de_DE”?

    I just tried this, and the only textdomain that is available is ‘woocommerce’:

    add_filter( 'plugin_locale', function($locale, $domain) {
    if($domain == 'woocommerce-pdf-invoices-packing-slips') {
    die('yes');
    }
    • This reply was modified 7 years, 3 months ago by torbent.
    Thread Starter torbent

    (@torbentschechnegmailcom)

    Hello Ewout,
    I have one question left. When I trigger the invoice manually in the WC backend the order can be a result of the english page or the german one. Now I want to include the english or german invoice to my email.

    Once somebody triggers the action I do this:

    $language_of_order = get_post_meta($orderObj->get_id(), '_language_code', true);
    if (!$language_of_order) {
    	$language_of_order = get_post_meta($orderObj->get_id(), 'wpml_language', true);
    }
    
    if ($language_of_order == 'de') {
    	add_filter( 'plugin_locale', function($locale, $domain) {
    		$locale = 'de_DE';
    		return $locale;
    	}, 99, 2);	
    }		

    So I check which is the correct language of the order and set the locale of WooCommerce to the respective value. However when I do this the email has some elements in german which is correct, but the attachment/subject of the email has not the correct language.

    Is there a possibility that I can manually switch to the correct language before attaching the invoice?

    As you might recall I make use of the woocommerce_email_attachments filter to create the pdf invoice…

    Thanks!

    Thread Starter torbent

    (@torbentschechnegmailcom)

    I found it, I did not set

    $this->object = $order;

    inside the trigger function.

    It works now. Thank you so much for your great support!

    Thread Starter torbent

    (@torbentschechnegmailcom)

    Yep, I have. When someone triggers the bulk action I do the following:

    add_filter('woocommerce_email_attachments', function( $attachments, $email_id, $order) {
    	$invoice = wcpdf_get_invoice($order);
    	$pdf_data = $invoice->get_pdf();
    	$filename = $invoice->get_filename();
    	$upload_dir = wp_upload_dir();
    	$pdf_path = $upload_dir['basedir'] . '/wpo_wcpdf/attachments/' .$filename;
    	file_put_contents ( $pdf_path, $pdf_data );
    	$attachments[] = $pdf_path;
    
    	return $attachments;
    
    }, 99, 3);
    
    $mailer       = WC()->mailer();
    $notification = $mailer->emails['WC_Additional_Info_Email'];
    $notification->trigger( $email, $order );

    And the trigger function of the Class WC_Additional_Info_Email looks like this:

    public function trigger( $email, $order ) {
    	 
        // bail if no email is present
        if ( ! $email )
            return;
    
    $this->recipient = $email;
    
    .... (excluded some code here)...
    
        // woohoo, send the email!
        $this->setup_locale();
        $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
        $this->restore_locale();

    When I use the code to attach the invoice on the classic WC invoice template, the filter works, but with my custom class not, but I have no clue why…as I use get_attachments() the WC filter should work here as well.

    Thread Starter torbent

    (@torbentschechnegmailcom)

    I digged a bit deeper, and found out when triggering my custom email and using the filter the following error is thrown:

    [14-Aug-2017 07:55:20 UTC] PHP Notice:  id was called <strong>incorrectly</strong>. Order properties should not be accessed directly. Backtrace: apply_filters('handle_bulk_actions-edit-shop_order'), WP_Hook->apply_filters, custom_bulk_action_handler, WC_Additional_Info_Email->trigger, WC_Abstract_Legacy_Order->__get, wc_doing_it_wrong Please see <a href="https://codex.www.ads-software.com/Debugging_in_WordPress">Debugging in WordPress</a> for more information. (This message was added in version 3.0.) in /is/htdocs/wp10_TWGAEPLQ0D/www/projekte/rr/wp-includes/functions.php on line 4139
    [14-Aug-2017 07:55:20 UTC] PHP Fatal error:  Uncaught Error: Call to a member function get_formatted_billing_address() on null in /is/htdocs/wp10_TWGAEPLQ0D/www/projekte/rr/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/includes/documents/abstract-wcpdf-order-document-methods.php:108
    Stack trace:
    #0 /is/htdocs/wp10_TWGAEPLQ0D/www/projekte/rr/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/includes/documents/abstract-wcpdf-order-document-methods.php(119): WPO\WC\PDF_Invoices\Documents\Order_Document_Methods->get_billing_address()
    #1 /is/htdocs/wp10_TWGAEPLQ0D/www/projekte/rr/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/templates/Simple/invoice.php(31): WPO\WC\PDF_Invoices\Documents\Order_Document_Methods->billing_address()
    #2 /is/htdocs/wp10_TWGAEPLQ0D/www/projekte/rr/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/includes/documents/abstract-wcpdf-order-document.php(604): include('/is/htdocs/wp10...')
    #3 /is/htdocs/wp10_TWGAEPLQ0D/www/projekte/rr/wp-c in /is/htdocs/wp10_TWGAEPLQ0D/www/projekte/rr/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/includes/documents/abstract-wcpdf-order-document-methods.php on line 108

    It seems that the invoice document can not access the billing address. Do you know why this happens?

    Thread Starter torbent

    (@torbentschechnegmailcom)

    Yep, thanks.

    I did solve it now as this within the filter handle_bulk_actions-edit-shop_order.

    if ($action == 'send_additional_info') {
    
    			$invoice = wcpdf_get_invoice($order);
    			$pdf_data = $invoice->get_pdf();
    			$filename = $invoice->get_filename();
    			$upload_dir = wp_upload_dir();
    			$pdf_path = $upload_dir['basedir'] . '/wpo_wcpdf/attachments/' .$filename;
    			file_put_contents ( $pdf_path, $pdf_data );
    			$attachments[] = $pdf_path;
    			//do_action( 'wpo_wcpdf_email_attachment', $pdf_path, 'invoice' );
    			$mailer       = WC()->mailer();
    			$notification = $mailer->emails['WC_Additional_Info_Email'];
    			$notification->trigger( $email, $order->get_id(), $attachments );
    
    		}

    If I add the woocommerce_email_attachments filter here, it does not work. I do not know why exactly. If I change it to this, the documents gets echoed, but not attached:

    if ($action == 'send_additional_info') {
    
    	add_filter( 'woocommerce_email_attachments', function($attachments, $email_id, $order) {
    		$invoice = wcpdf_get_invoice($order);
    		$pdf_data = $invoice->get_pdf();
    		$filename = $invoice->get_filename();
    		$upload_dir = wp_upload_dir();
    		$pdf_path = $upload_dir['basedir'] . '/wpo_wcpdf/attachments/' .$filename;
    		file_put_contents ( $pdf_path, $pdf_data );
    		$attachments[] = $pdf_path;	
    		return $attachments;
    	}, 99, 3 );
    
    	$mailer       = WC()->mailer();
    	$notification = $mailer->emails['WC_Additional_Info_Email'];
    	$notification->trigger( $email, $order->get_id() );
    
    }

    You do not need to answer, I am just curious why the filter does not work here…

    Thread Starter torbent

    (@torbentschechnegmailcom)

    I have found this function now:

    
    $invoice = wcpdf_get_invoice($order);
    $invoice->get_filename();
    

    This does output a filename, but I can not find the file in /uploads/wpo_wcpdf/. So my basic question is, how can I generate the invoice, save it and attach it to my email then?

    Would be great if you have a hint for me…

    Thread Starter torbent

    (@torbentschechnegmailcom)

    Ewout, yes I have ??

    I have a custom e-mail template “additional email info” and now I want to create the possibility in the orders bulk section to trigger these three emails:

    – “Send Invoice”
    – “Send Additional Info”
    – “Send Invoice and Additional Info”

    In either of these cases I need to attach something to the email that’s being sent. And I have tried with this:

    if ($action == 'send_invoice_and_info') {
    	$attachments = wcpdf_get_invoice($order);
    
    	$mailer       = WC()->mailer();
    	$notification = $mailer->emails['WC_Additional_Info_Email'];
    	$notification->trigger( $email, 0, $attachments );
    
    }

    And then in the class, I do this:

    public function trigger( $email, $product_id, $attachments ) {
    ...
    $t = $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $attachments);
    }

    But this does not work and so I tried also the hook woocommerce_email_attachments, but there I have no access to the order, so I can not use wcpdf_get_invoice($order).

    Do you have an idea how I can attach documents to my different email templates within the if clause?

    • This reply was modified 7 years, 3 months ago by torbent.
    Thread Starter torbent

    (@torbentschechnegmailcom)

    Ah, sure. Thanks ?? Silly question…

    Thread Starter torbent

    (@torbentschechnegmailcom)

    Hey mjassen,
    exactly. WooCommerce official support has no developer support, that’s why I am asking here ??

    Thread Starter torbent

    (@torbentschechnegmailcom)

    Hey,
    I tried other versions – down to 3.0.0.0 but nothing changed.

    Then I changed the PHP version of the server from 5.6 to 7.0 and now it works! ??

    Thanks!

Viewing 15 replies - 31 through 45 (of 92 total)