• Resolved tjos123

    (@tjos123)


    Hi. I used to be able to see the symbols/emoji (eg ???? etc) on the PDF files. But not sure from which version onwards, I no longer see them. They are now all shown as squares on the generated PDF. Is there a way out to this? I am not using custom fonts, most settings are the default ones.

    I am using v3.2.4 with WordPress v6.1.

    Thanks!

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

    (@yordansoares)

    Hi @tjos123,

    Maybe you were using a different PDF Invoices plugin before? I ask this because the default PDF engine we use (dompdf) is not compatible with emojis yet. See: Add Emoji support (Issue #1698)

    The best thing we can do is offering a code snippet to remove the emojis from the PDF documents. Let me know if this is enough for you.

    Thread Starter tjos123

    (@tjos123)

    Hi @yordansoares. I certainly only used this plugin. It’s good enough for my usage, so I have never tried others. But yeah, it’s rather strange too as I would have thought that the emojis aren’t supported.

    Yes if you could share the code snippet for me to test out. Thank you.

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @tjos123,

    Please add this code snippet to your site, in order to remove the emojis from the product names on the PDF documents:

    /**
     * PDF Invoices & Packing Slips for WooCommerce:
     * Remove emojis, emoticons and other non-printable characters from the product names on the PDF documents
     */
    add_filter( 'wpo_wcpdf_html_filters', function( $filters ) {
    	$filters[] = array( 'woocommerce_order_item_name', 'wpo_wcpdf_remove_emojis_from_item_name', 999, 3 );
    	return $filters;
    } );
    function wpo_wcpdf_remove_emojis_from_item_name ( $item_name, $item, $is_visible ) {
    	
    	// Emojis
    	$regex_emojis = '/[[:^print:]]/';
    	$item_name = preg_replace( $regex_emojis, '', $item_name );
    	
    	// Emoticons
    	$regex_emoticons = '/[\x{1F600}-\x{1F64F}]/u';
    	$item_name = preg_replace( $regex_emoticons, '', $item_name );
    	
    	// Miscellaneous Symbols and Pictographs
    	$regex_symbols = '/[\x{1F300}-\x{1F5FF}]/u';
    	$item_name = preg_replace( $regex_symbols, '', $item_name );
    
    	return $item_name;
    }

    Let me know if it worked! ??

    Thread Starter tjos123

    (@tjos123)

    Hi @yordansoares! Sorry I wasn’t clear at first. I was referring to the emojis on the meta of the product.

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @tjos123,

    Oh, I thought it was happening only in the item name. Please replace my previous code snippet to remove the emojis and other non-printable characters from the formatted meta on the PDF documents:

    /**
     * PDF Invoices & Packing Slips for WooCommerce:
     * Remove emojis, emoticons and other non-printable characters from the formatted meta on the PDF documents
     */
    add_filter( 'wpo_wcpdf_html_filters', function( $filters ) {
    	$filters[] = array( 'woocommerce_order_item_get_formatted_meta_data', 'wpo_wcpdf_remove_emojis_from_item_meta', 999, 2 );
    	return $filters;
    } );
    function wpo_wcpdf_remove_emojis_from_item_meta( $formatted_meta, $item ) {
    	foreach( $formatted_meta as $key => $meta ){
    		// Emojis
    		$regex_emojis = '/[[:^print:]]/';
    		$value = preg_replace( $regex_emojis, '', $meta->value );
    
    		// Emoticons
    		$regex_emoticons = '/[\x{1F600}-\x{1F64F}]/u';
    		$value = preg_replace( $regex_emoticons, '', $value );
    
    		// Miscellaneous Symbols and Pictographs
    		$regex_symbols = '/[\x{1F300}-\x{1F5FF}]/u';
    		$meta->value = preg_replace( $regex_symbols, '', $value );
    		
    		$meta->display_value = $meta->value;
    		$formatted_meta[$key] = $meta;
    	}
    
    	return $formatted_meta;
    }
    Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @tjos123,

    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 ‘Symbols’ is closed to new replies.