WooCommerce PDF Invoice Custom Macros Issue

This topic has 8 replies, 2 voices, and was last updated 6 days, 6 hours ago ago by Luca Rossi

  • Avatar: Filip
    Filip
    Participant
    June 25, 2025 at 22:48

    Hi,

    I’m contacting you in connection with my previous ticket https://www.8theme.com/topic/woocommerce-pdf-invoices-custom-macros/#post-447446. I am experiencing a critical issue with WooCommerce PDF Invoice plugin (by RightPress) on my XStore theme website. I need to add custom macros for business requirements (IČO, DIČ, IČ DPH) or (ID, Tax ID, VAT ID) to PDF invoices, but despite multiple attempts and code implementations, the custom macros are not appearing in the generated PDF documents.

    What I’m Trying to Achieve
    I need to add these specific macros to my WooCommerce PDF invoices:

    {{billing_ic}} – Company Registration Number (IČO)
    {{billing_dic}} – Tax ID Number (DIČ)
    {{billing_ic_dph}} – VAT Number (IČ DPH)

    These are standard business requirements for my countries’ invoices and should pull data from WooCommerce billing fields.

    Current Setup

    Theme: XStore (latest version)
    Plugin: WooCommerce PDF Invoice by RightPress
    WordPress: Latest version
    WooCommerce: Latest version
    Server: Standard hosting environment

    What We Know About the Plugin
    Through debugging, I discovered that the plugin uses these WordPress hooks and filters:
    Active Plugin Hooks:
    woo_pdf_macros – Priority: 10, Callbacks: 4
    rightpress_pdf_template_data – Priority: 10, Callbacks: 1
    rightpress_pdf_settings_defaults – Priority: 10, Callbacks: 1
    Available Standard Macros:

    The plugin includes standard macros like:

    {{order_number}}
    {{order_date}}
    {{billing_first_name}}
    {{billing_last_name}}
    {{billing_company}}
    {{total}}

    Code Attempts Made
    I have tried multiple approaches to add custom macros:
    Method 1: Using woo_pdf_macros filter

    phpadd_filter('woo_pdf_macros', function($macros) {
        $macros['billing_ic'] = 'SK123456789';
        $macros['billing_dic'] = 'SK2023456789'; 
        $macros['billing_ic_dph'] = 'SK2023456789';
        return $macros;
    }, 10);

    Method 2: Using rightpress_pdf_template_data filter

    phpadd_filter('rightpress_pdf_template_data', function($data) {
        $data['macros']['billing_ic'] = get_post_meta($data['order_id'], '_billing_ic', true);
        return $data;
    }, 10);

    Method 3: Direct macro registration

    phpadd_action('init', function() {
        if (function_exists('woo_pdf_add_macro')) {
            woo_pdf_add_macro('billing_ic', 'Company ID');
        }
    });

    Current Problem
    Despite all attempts:

    Custom macros don’t appear in the PDF invoice
    Debug logs show that filters are being called
    Standard plugin macros work perfectly
    No PHP errors are generated
    Plugin hooks are active but custom macros are ignored

    Debug Information
    Plugin debug shows:

    woo_pdf_macros filter has 4 callbacks active
    Custom filter callbacks are being added (priority 999 visible)
    No error messages in debug.log
    Template rendering works for standard macros only

    Previous Support Attempts
    I have attempted to contact RightPress support for this WooCommerce PDF Invoice plugin issue but have been waiting several days without response. Since this is affecting me deeply and XStore is my theme, I’m hoping you could provide guidance or assistance.

    Thank you for your time and support.

    Best regards,
    Filip

    7 Answers
    Avatar: Justin
    Luca Rossi
    Support staff
    June 26, 2025 at 12:56

    Dear @Filip,

    We hope this message finds you well.

    We kindly request that you provide us with the updated username and password, as the account listed in the private content is currently not functioning.

    Thank you in advance for your assistance.

    Best regards,
    The 8Theme Team

    Content is visible for topic creator and
    support staff only.
    Avatar: Filip
    Filip
    Participant
    June 26, 2025 at 20:52

    Hi,

    yes, it was automatically attached. I’m sending the new login details.

    Best regards,
    Filip

    Content is visible for topic creator and
    support staff only.
    Avatar: Justin
    Luca Rossi
    Support staff
    June 27, 2025 at 08:20

    Dear Filip,

    We hope this message finds you well.

    We would like to inform you that the meta key names previously used were incorrect. To ensure proper functionality, we kindly ask you to review the custom code we have implemented, which includes the correct meta key names.

    Additionally, we have updated the custom code on your website accordingly. As a result, the PDF file now correctly displays the custom macro values.

    Please find below the updated code for your reference:

    
    // Macro for IČO (Business Registration Number)
    add_filter('woo_pdf_macros', 'woo_pdf_custom_macro_ico', 10, 2);
    
    function woo_pdf_custom_macro_ico($macros, $order) {
        $custom_macro_key = '{{woo_pdf_custom_macro_ico}}';
        $custom_macro_value = '';
    
        // Check if order is actually an object
        if (is_object($order)) {
            // Get IČO from order meta
            $ico = get_post_meta($order->get_id(), 'billing_ic', true);//$order->get_meta('_wpify_ic');
            
            // Alternative meta key if the above doesn't work
            if (empty($ico)) {
                $ico = get_post_meta($order->get_id(), '_billing_ic', true);//$order->get_meta('wpify_ic');
            }
            
            $custom_macro_value = !empty($ico) ? $ico : '';
        }
    
        $macros[$custom_macro_key] = $custom_macro_value;
        return $macros;
    }
    
    // Macro for DIČ (Tax Number)
    add_filter('woo_pdf_macros', 'woo_pdf_custom_macro_dic', 10, 2);
    
    function woo_pdf_custom_macro_dic($macros, $order) {
        $custom_macro_key = '{{woo_pdf_custom_macro_dic}}';
        $custom_macro_value = '';
    
        // Check if order is actually an object
        if (is_object($order)) {
            // Get DIČ from order meta
            $dic = get_post_meta($order->get_id(), 'billing_dic', true);//$order->get_meta('_wpify_dic');
            
            // Alternative meta key if the above doesn't work
            if (empty($dic)) {
                $dic = get_post_meta($order->get_id(), '_billing_dic', true);//$order->get_meta('wpify_dic');
            }
            
            $custom_macro_value = !empty($dic) ? $dic : '';
        }
    
        $macros[$custom_macro_key] = $custom_macro_value;
        return $macros;
    }
    
    // Macro for IČ DPH (VAT Number)
    add_filter('woo_pdf_macros', 'woo_pdf_custom_macro_ic_dph', 10, 2);
    
    function woo_pdf_custom_macro_ic_dph($macros, $order) {
        $custom_macro_key = '{{woo_pdf_custom_macro_ic_dph}}';
        $custom_macro_value = '';
    
        // Check if order is actually an object
        if (is_object($order)) {
            // Get IČ DPH from order meta
            $ic_dph = get_post_meta($order->get_id(), 'billing_dic_dph', true);//$order->get_meta('_wpify_dic_dph');
            
            // Alternative meta key if the above doesn't work
            if (empty($ic_dph)) {
                $ic_dph = get_post_meta($order->get_id(), '_billing_dic_dph', true);//$order->get_meta('wpify_dic_dph');
            }
            
            $custom_macro_value = !empty($ic_dph) ? $ic_dph : '';
        }
    
        $macros[$custom_macro_key] = $custom_macro_value;
        return $macros;
    }
    
    // Note: Company name is already available in standard WooCommerce macros
    // Use {{billing_company}} or {{shipping_company}} instead
    
    // Combined macro for all business info in formatted block
    add_filter('woo_pdf_macros', 'woo_pdf_custom_macro_business_info', 10, 2);
    
    function woo_pdf_custom_macro_business_info($macros, $order) {
        $custom_macro_key = '{{woo_pdf_custom_macro_business_info}}';
        $custom_macro_value = '';
    
        // Check if order is actually an object
        if (is_object($order)) {
            // Use standard WooCommerce billing company field
            $company = $order->get_billing_company();
            
            $ico = get_post_meta($order->get_id(), 'billing_ic', true) ?: get_post_meta($order->get_id(), '_billing_ic', true);//$order->get_meta('_wpify_ic') ?: $order->get_meta('wpify_ic');
            $dic = get_post_meta($order->get_id(), 'billing_dic', true) ?: get_post_meta($order->get_id(), '_billing_dic', true);//$order->get_meta('_wpify_dic') ?: $order->get_meta('wpify_dic');
            $ic_dph = get_post_meta($order->get_id(), 'billing_dic_dph', true) ?: get_post_meta($order->get_id(), '_billing_dic_dph', true);//$order->get_meta('_wpify_dic_dph') ?: $order->get_meta('wpify_dic_dph');
            
            $business_info = array();
            
            if (!empty($company)) {
                $business_info[] = $company;
            }
            if (!empty($ico)) {
                $business_info[] = 'IČO: ' . $ico;
            }
            if (!empty($dic)) {
                $business_info[] = 'DIČ: ' . $dic;
            }
            if (!empty($ic_dph)) {
                $business_info[] = 'IČ DPH: ' . $ic_dph;
            }
            
            $custom_macro_value = implode("\n", $business_info);
        }
    
        $macros[$custom_macro_key] = $custom_macro_value;
        return $macros;
    }
    
    /**
     * Usage in PDF templates:
     * 
     * {{woo_pdf_custom_macro_ico}} - displays IČO
     * {{woo_pdf_custom_macro_dic}} - displays DIČ
     * {{woo_pdf_custom_macro_ic_dph}} - displays IČ DPH
     * {{billing_company}} - displays company name (standard WooCommerce macro)
     * {{woo_pdf_custom_macro_business_info}} - displays all business info formatted
     */
    
    

    You can also view a screenshot of the result here: https://prnt.sc/bu_iGEjHjAci

    Should you have any questions or require further assistance, please do not hesitate to reach out.

    Best regards,
    The 8Theme Team

    Avatar: Filip
    Filip
    Participant
    June 27, 2025 at 14:12

    Hi,

    I can’t thank you enough! Both the invoice and the code look good. Could you please share the path or the placement of the ”Custom Macro:” string on the invoice? I’d like to tweak the text and the placement of the actual macro and I obviously don’t want to bother you.

    Thank you very much again!
    Filip

    Avatar: Justin
    Luca Rossi
    Support staff
    June 27, 2025 at 14:25

    Hi @Filip,

    Please navigate to the PDF Invoice setting page under Seller & Buyer tab:

    https://grmtrade.sk/wp-admin/admin.php?page=woo-pdf&tab=seller_details

    https://prnt.sc/d4lwbu18KoTM

    Hope it helps!

    Avatar: Filip
    Filip
    Participant
    June 27, 2025 at 14:26

    Yes, thanks again!

    Avatar: Justin
    Luca Rossi
    Support staff
    June 27, 2025 at 14:27

    Dear @Filip,

    In the spirit of gratitude, we want to express our appreciation for your trust in our products. As a valued customer, your experience matters greatly. Would you consider sharing it by giving our theme a deserving 5-star rating on ThemeForest?

    Click here to share your thoughts: https://themeforest.net/downloads

    Being part of our community means a lot, and your feedback contributes immensely.

    Best Regards,
    The 8Theme Team

  • Viewing 8 results - 1 through 8 (of 8 total)

The issue related to '‘WooCommerce PDF Invoice Custom Macros Issue’' has been successfully resolved, and the topic is now closed for further responses

Helpful Topics

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.