• Resolved nerealonela

    (@nerealonela)


    Hello,
    I have your plugin installed on my site. I have created a custom template to add the custom fields, however, reading your documentation, I followed all the steps and the custom fields are still not shown on the invoice.

    I have added the following:
    <?php $this->custom_field(“nombre_empresa”); ?>
    <?php $this->custom_field(“_nombre_empresa”); ?>
    <?php $this->custom_field(‘_nombre_empresa’); ?>
    <?php $this->custom_field(‘nombre_empresa’); ?>

    No option is valid, because it does not show me the custom fields in the invoice.

    These custom fields have been created in the checkout using the WooCommerce Custom Fields plugin (created by RightPress).

    These custom fields are conditional, they are displayed in the checkout depending on the user role. Therefore, they only appear when the client fulfills the user role and completes them in the checkout.

    Attached screenshot of the custom checkout fields in the Custom Fields plugin.
    https://prnt.sc/hc3n1i

    In the individual order of the client they are shown as follows:
    https://prnt.sc/hc3pxx

    What am I doing wrong? Why are not the custom fields shown in the custom invoice?

    On the other hand, in the settings of your plugin, it does not let me upload the logo. When I click on the “upload image” button nothing opens. Look image.
    https://prnt.sc/hc3r38

    How can I put my logo on the invoice?

    Thank you very much

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter nerealonela

    (@nerealonela)

    Hello,

    I apologize, do not pay attention to the case of the personalized fields because I have already been able to solve it. It turns out that he was introducing the wrong key.

    However, the theme of the logo that does not allow any image to appear in its complement remains that way. However I have fixed it by uploading the image directly to my custom template.

    I would like to know if there is the option of having two different series numbers … one for simplified invoices and one for complete invoices.
    This would work through the user_role option, however I do not know how to complement the code … That is, for “wholesale” users it would be the invoice with the serial number of complete invoices and for the other users it would be the invoice with the number of series of simplified invoices.

    And finally, in the invoice the country is not shown either in the billing address or in the shipping address.

    I have added the following code to my custom template:

    <?php $this->custom_field(“_billing_country”); ?>

    However only the first two digits of the country are shown. For example, for Spain, it only shows ES … How can I do it to show the full name of the country?

    Attached image: https://prnt.sc/hc7wxy

    Thanks

    Plugin Contributor kluver

    (@kluver)

    Hi @nerealonela,

    First of all it’s strange the add logo button doesn’t work. It is possible another plugin is giving a javascript error that prevents the window from opening.

    With regard to the different series of numbers. Theoretically this is possible, although this is not something you’ll be able to do from the settings out of the box (neither free or pro).
    There are several filters that you can use for this purpose:

    wpo_wcpdf_document_number_settings which lets you set the prefix and suffix based on your own criteria
    wpo_wcpdf_raw_document_number to replace the unformatted document number with your own
    wpo_wcpdf_external_invoice_number_enabled & wpo_wcpdf_external_invoice_number specifically for invoice numbers (doesn’t affect proforma) – example here.
    This is quite advanced and requires a fair bit of knowledge of PHP, and also beyond free support. I hope this gets you on track though!

    With regard to the billing country there is no easy way of converting the country codes to a full country name. I believe WooCommerce offers some solutions. Else you would have to make an array with all the countries and show the country name based on the country code with something like a switch statement.

    I hope this helps you in the right direction.

    With kind regards,

    Michael

    Thread Starter nerealonela

    (@nerealonela)

    Then, it is possible to configure that for users with a “wholesale” role no invoices are generated? Only for other users …

    How could the code be? I found a forum thread to exclude categories, however I would not know how to adapt this to exclude a user role.

          return $condition;
        }
    
        // define categories which shouldn't get an invoice here
        $no_invoice_cats = array('deposit','event');
    
        $items = $order->get_items();
        $order_cats = array();
        foreach ($items as $item_id => $item) {
            // get categories for item, requires product
            $product = $order->get_product_from_item( $item );
            if ($product) {
                $terms = get_the_terms( $product->id, 'product_cat' );
                if (empty($terms)) {
                    continue;
                }
                foreach ($terms as $key => $term) {
                    $order_cats[$term->term_id] = $term->name;
                }
            }
        }
    
        // get array of category matches
        $cat_matches = array_intersect($no_invoice_cats, $order_cats);
        if ( count($cat_matches) > 0 ) {
            // 1 or more matches, don't attach invoice
            return false;
        } else {
            return $condition;
        }
    }

    Thank you

    • This reply was modified 8 years, 3 months ago by nerealonela.
    Plugin Contributor Ewout

    (@pomegranate)

    This is a bit beyond what we can do for you as part of free support, but you could try this (untested!):

    
    add_filter('wpo_wcpdf_custom_attachment_condition', 'wpo_wcpdf_disable_invoice_wholesale', 10, 4 );
    function wpo_wcpdf_disable_invoice_wholesale( $condition, $order, $email_id, $document_type  ) {
        $user = $order->get_user();
        if ( empty($user) || empty ( $user->roles ) or ! is_array( $user->roles ) ) {
            return $condition;
        }
        // get role names
        $wp_roles = new WP_Roles;
        $names    = $wp_roles->get_names();
        $user_roles = array();
        // check if user is a wholesale user
        $role_to_exclude = 'wholesale'; // this can be part of the user role or user role name
        foreach ( $user->roles as $role ) {
            if ( strpos( strtolower( $role ), $role_to_exclude ) !== false || ( isset( $names[$role] ) && strpos( strtolower( $names[$role] ), $role_to_exclude ) !== false ) ) {
                // use has wholesale role
                return false;
            }
        }
    
        return $condition;
    }
    

    Hope that helps!
    Ewout

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Custom fields does not work in custom template’ is closed to new replies.