Include new column for WooCommerce Email Invoice Only - woocommerce

I want to include a new column for the customer invoice email for my woocommerce website. But I don't want the new column to be seen in other customer emails.
Thanks.

Copy the file /woocommerce/templates/emails/customer-invoice.php to a subfolder /woocommerce/emails/ in your active theme.
The following line includes the template file email-order-details.php.
do_action( 'woocommerce_email_order_details', $order, $sent_to_admin, $plain_text, $email );
You can replace this line by the content of the above mentioned file.
Here you can add an additional column header. To also add the column content replace the following part:
echo wc_get_email_order_items( $order, array(
'show_sku' => $sent_to_admin,
'show_image' => false,
'image_size' => array( 32, 32 ),
'plain_text' => $plain_text,
'sent_to_admin' => $sent_to_admin,
) );
by the content of email-order-items.php and customize your columns here.
If you want make your live easier you can use my plugin WP HTML Mail for WooCommerce and just click the + icon to add a column.

Related

How to change field's label on checkout page in woocommerce?

I am using wordpress for the first time. There is overwhelming information available about How to do stuff in WordPress. I want to simply change the label of postal code/zip field on check out page. Here are the steps i followed:
1>Installed woocommerce plugin
2>Imported Dummy Data
3>Installed Astra Starter Template Plugin
4>Installed Brandstore theme
5>Created my own child theme as per guidelines
Tested site. At this point everything working fine.
Now i want to simply change the lable for "Postalcode/Zip" on chekout page
So as per the woocommerce guidelines i added the following code in child theme's functions.php
// Hook in
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields',100 );
// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
$fields['billing']['billing_postcode']['label'] = 'Postal Code';
return $fields;
}
When i refresh page it did not change the label.
Q1> How do i change field lable on checkout page.
Q2> where is template located for checkout page? Look like checkout page is using
[woocommerce_checkout] code
/**
* Add the field to the checkout
*/
add_action( 'woocommerce_after_order_notes', 'my_custom_checkout_field' );
function my_custom_checkout_field( $checkout ) {
echo '<div id="my_custom_checkout_field"><h2>' . __('My Field') . '</h2>';
woocommerce_form_field( 'my_field_name', array(
'type' => 'text',
'class' => array('my-field-class form-row-wide'),
'label' => __('Fill in this field'),
'placeholder' => __('Enter something'),
), $checkout->get_value( 'my_field_name' ));
echo '</div>';
}
visit Official Documentation

Custom woocommerce product field not working for CSV import

I've created a custom field for my products this way:
// The code for displaying WooCommerce Product Custom Fields
add_action( 'woocommerce_product_options_general_product_data', 'woocommerce_product_custom_fields' );
// Following code Saves WooCommerce Product Custom Fields
add_action( 'woocommerce_process_product_meta', 'woocommerce_product_custom_fields_save' );
function woocommerce_product_custom_fields () {
global $woocommerce, $post;
echo '<div class=" product_custom_field ">';
// Custom Product Number Field
woocommerce_wp_text_input(
array(
'id' => '_shipping_days_field',
'placeholder' => 'Días de entrega',
'label' => __('Días estimados de entrega', 'woocommerce'),
'type' => 'number',
'custom_attributes' => array(
'step' => 'any',
'min' => '1'
)
)
);
echo '</div>';
}
function woocommerce_product_custom_fields_save($post_id){
// Custom Product Number Field
$shipping_days = $_POST['_shipping_days_field'];
if (!empty($shipping_days))
update_post_meta($post_id, '_shipping_days_field', esc_attr($shipping_days));
}
This is working ok on the frontend admin it shows the field and saves it, but it is not working for the CSV impornt, I cannot specify the field in my CSV mapping. Is there a way I can create custom field that works for CSV import as well?
I actually solved it, on the mapping you just should select Meta Attributes, and the label on the CSV column must be as follows:
meta:your_custom_field

Placing Wordpress plugin name at the top of the amdin header

I have a Wordpress plugin which I've named 'Solve Maths'. I want this plugin name to be displayed only at the Admin header of the Arthur alone for easy access.
I used the admin_head action hook but once I installed the plugin, the system tells me my plugin has generated these number of characters at the header.
<?php function Solve_Maths{ echo "<a href='Solve_Maths.php'>Solve Maths</a>";} add_action('admin_head','Solve_Maths');?>
The Solve_Maths.php is the name of the main plugin file with the header information. I want this file name in the tag to be shown at the admin header of the user and should execute the file when the link is linked. Thank you all for your help.
This is not the correct way to do it. Please check the WordPress Codex and refer to the function add_node: https://codex.wordpress.org/Function_Reference/add_node
add_action( 'admin_bar_menu', 'toolbar_link_to_mypage', 999 );
function toolbar_link_to_mypage( $wp_admin_bar ) {
$args = array(
'id' => 'my_page',
'title' => 'My Page',
'href' => 'http://example.com/my-page/',
'meta' => array( 'class' => 'my-toolbar-page' )
);
$wp_admin_bar->add_node( $args );
}

Get Post meta to display on invoice in WordPress

I'm using a plugin called woo-get to add a product attribute called 'prod_hsn_id' which add a filed called HSN code at product edit page,
I'm also using a pdf invoice plugin called woocommerce pdf invoice to generate pdf invoice.
Now I want to display the HSN code on the invoice.
I am having a very hard time to get it to work, I tried searching online and contacting the plugin author, and he said that it can be retrieved using the WordPress get post meta.
But
This the function the plugin use to create the custom field.
public function fn_add_product_custom_meta_box() {
woocommerce_wp_text_input(
array(
'id' => 'hsn_prod_id',
'label' => __('HSN Code', 'woocommerce' ),
'description' => __( 'HSN Code is mandatory for GST.', 'woocommerce' ),
'custom_attributes' => array( 'required' => 'required' ),
'value' => get_post_meta( get_the_ID(), 'hsn_prod_id', true )
)
);
}
In the Invoice Template file I'm trying to display the HSN Code using
<?php $meta = get_post_meta( $post_id , 'hsn_prod_id', true ); ?>
<?php $meta = get_post_meta( get_the_ID(), 'hsn_prod_id', true ); ?>
Sources :
Support
1. https://wordpress.org/support/topic/print-hsn-in-invoice/
https://wordpress.org/support/topic/which-pdf-plugin-will-display-the-hsn-field-and-gst-number/
Product details will be under line_items of order. Can you share your invoice template code where you are trying to access product id?
You will have order object, using that object you can retrieve all products related to that order. You need to execute on foreach loop (that should be there already).
You can see $product at line 77 of original template file of plugin. You can get id using $product->get_id().

Add secondary attributes tab to woocommerce

I need to add another tab to product tabs section of woocommerce with the name of features and it's content fills just like attributes section. the source be same but data store in separate meta data and show it in another tab in product page view section.
any Idea how should to do this?
thank you in advance
Here is my code
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
$tabs['featurestab'] = array(
'title' => __( 'Features', 'woocommerce' ),
'priority' => 15,
'callback' => 'features_tab_content');
return $tabs;
}
function features_tab_content() {
echo 'Your product ('.get_the_ID().') features.';
}

Resources