How to add CPF in WooCommerce order emailHow to add CPF in WooCommerce order email

How to add CPF in WooCommerce order email

WooCommerce is one of the most popular eCommerce platforms in the world, allowing online store owners to sell products and services effectively. However, it is often necessary to customize order confirmation emails to include specific information, such as customers’ CPF or CNPJ in Brazil.

With that in mind, in this special article from Nerd Codex, you will learn how to add the CPF or CNPJ in the WooCommerce order email to meet the needs of your business and check the information in a faster and more practical way.

Before you begin, make sure you are logged into your WordPress admin panel where you manage your WooCommerce site.

  • Access the “Appearance” option in the left sidebar of your WordPress;
  • Go to the “Edit Theme” option or use FTP/SFTP to access your theme;
  • Open the file “functions.php” and go to the last line to add new code:

function kia_display_email_order_user_meta( $order, $sent_to_admin, $plain_text ) {

if ($order->billing_cpf){
echo '

CPF: '. $order->billing_cpf.'

';
}
if ($order->billing_cnpj){
echo '

CNPJ: ‘. $order->billing_cnpj. ‘

';
}

 

}
add_action('woocommerce_email_customer_details', 'kia_display_email_order_user_meta', 30, 3 );

  • Save the file and clear your site’s cache (if applicable) for immediate seeding;
  • Now just wait for a new transaction on your website or place a test order.

To ensure that the CPF or CNPJ is being displayed correctly in the order confirmation email, carry out a test purchase in your store. After completing your order, check the confirmation email you will receive. If everything is configured correctly, the confirmation email should display the customer’s CPF or CNPJ, as configured.

In summary, customizing the order confirmation email in WooCommerce to include the customer’s CPF or CNPJ is a relatively simple process, as long as you can enter the information into the functions.php. By following the steps above, you will be able to provide important information to your customers and improve the shopping experience in your online store.

Photo by cottonbro studio