How To add column on Woocommerce -> Orders backend page - php

Can't find working solution that would add an example column to backend Orders list. Already tried these (within child theme's functions.php):
add_filter('manage_edit-shop_order_columns', 'extra_column');
function extra_column($columns) {
$columns['title'] = 'Product-x';
return $columns;
}
add_filter( 'manage_edit-shop_order_columns', 'MY_COLUMNS_FUNCTION' );
function MY_COLUMNS_FUNCTION($columns){
$new_columns = (is_array($columns)) ? $columns : array();
unset( $new_columns['order_actions'] );
//edit this for you column(s)
//all of your columns will be added before the actions column
$new_columns['MY_COLUMN_ID_1'] = 'MY_COLUMN_1_TITLE';
// $new_columns['MY_COLUMN_ID_2'] = 'MY_COLUMN_2_TITLE';
//stop editing
$new_columns['order_actions'] = $columns['order_actions'];
return $new_columns;
}
add_action( 'manage_shop_order_posts_custom_column', 'MY_COLUMNS_VALUES_FUNCTION', 2 );
function MY_COLUMNS_VALUES_FUNCTION($column){
global $post;
$data = get_post_meta( $post->ID );
//start editing, I was saving my fields for the orders as custom post meta
//if you did the same, follow this code
if ( $column == 'MY_COLUMN_ID_1' ) {
echo (isset($data['MY_COLUMN_1_POST_META_ID']) ? $data['MY_COLUMN_1_POST_META_ID'] : '');
}
if ( $column == 'MY_COLUMN_ID_2' ) {
echo (isset($data['MY_COLUMN_2_POST_META_ID']) ? $data['MY_COLUMN_2_POST_META_ID'] : '');
}
}
add_filter( 'manage_edit-shop_order_columns', 'imarcon_set_custom_column_order_columns');
function imarcon_set_custom_column_order_columns($columns) {
// global $woocommerce;
$nieuwearray = array();
foreach($columns as $key => $title) {
if ($key=='billing_address') // in front of the Billing column
$nieuwearray['order_producten'] = __( 'Products', 'woocommerce' );
$nieuwearray[$key] = $title;
}
return $nieuwearray ;
}
I am using WP 4.1.1, Avada 3.7.3 with Child Theme enabled, Gravity Forms 1.8.22 + few WooCommerce addons and other plugins.

OK got it - Woocommerce update solved it.

Related

Add appointment date to WooCommerce orders tab (frontend)

I am using JetAppoitment (crocoblock) to make services bookable.
I would like to add the appoitment date to the orders from the front-end side.
Here is the code I used :
add_filter( 'woocommerce_account_orders_columns', 'add_account_orders_column', 10, 1 );
function add_account_orders_column( $columns ){
$columns['custom-column'] = __( 'Date de livraison', 'woocommerce' );
return $columns;
}
add_action( 'woocommerce_my_account_my_orders_column_custom-column',
'add_account_orders_column_rows' );
function add_account_orders_column_rows( $order ) {
// Example with a custom field
if ( $value = $order->get_meta( '_appointment_date' ) ) {
echo esc_html( $value );
}
}
The first part of the code worked good, the extra column is here :
https://i.stack.imgur.com/kSLiq.png
The problem is I have no data...
Any idea to how to fix it?
Thanks
add_action('woocommerce_my_account_my_orders_column_custom-column',
'add_account_orders_column_rows');
function add_account_orders_column_rows($order) {
// Example with a custom field
if ($value = get_post_meta($order->get_id(), '_appointment_date')) {
echo esc_html($value);
}
}

Add custom column product visibility to admin product list in Woocommerce 3

I am trying to add a custom column to admin product list with the Catalog Visibility value of the products (basically, I need to know easier which is Hidden and which is not).
My code so far for my child theme's functions.php:
add_filter( 'manage_edit-product_columns', 'custom_product_column', 10);
function custom_product_column($columns){
$columns['visibility'] = __( 'Visibility','woocommerce');
return $columns;
}
add_action( 'manage_product_posts_custom_column', 'custom_column_content', 10, 2 );
function custom_product_list_column_content( $column, $product_id ){
global $post;
$isitvisible = get_post_meta( $product_id, 'product_visibility', true );
switch ( $column ){
case 'visibility' :
echo $isitvisible;
break;
}
}
Can someone please guide me? The column is created (and the title displayed), but I get no data for the products.
There are some errors and mistakes in your code. Also since Woocommerce 3 product visibility is handled by Woocommerce custom taxonomy 'product_visibility'. Try the following instead:
// Add a new column to Admin products list with a custom order
add_filter( 'manage_edit-product_columns', 'visibility_product_column', 10);
function visibility_product_column($columns){
$new_columns = [];
foreach( $columns as $key => $column ){
$new_columns[$key] = $columns[$key];
if( $key == 'price' ) { // Or use: if( $key == 'featured' ) {
$new_columns['visibility'] = __( 'Visibility','woocommerce');
}
}
return $new_columns;
}
// Add content to new column raows in Admin products list
add_action( 'manage_product_posts_custom_column', 'visibility_product_column_content', 10, 2 );
function visibility_product_column_content( $column, $product_id ){
global $post;
if( $column =='visibility' ){
if( has_term( 'exclude-from-catalog', 'product_visibility', $product_id ) )
echo '<em style="color:grey;">' . __("No") . '</em>';
else
echo '<span style="color:green;">' . __("Yes") . '</span>';
}
}
Code goes in function.php file of your active child theme (active theme). Tested and works.
Woocommerce also allows you to hide products if they're out of stock. I needed to know which were excluded from catalog and which were hidden because they were out of stock. This small update to the code above uses an array to find all the hidden conditions I needed to know:
// Add content to new column rows in Admin products list
add_action( 'manage_product_posts_custom_column', 'visibility_product_column_content', 10, 2 );
function visibility_product_column_content( $column, $product_id ){
global $post;
if( $column =='visibility' ){
if( has_term( array('exclude-from-catalog', 'outofstock'),'product_visibility', $product_id ) )
echo '<em style="color:grey;">' . __("No") . '</em>';
else
echo '<span style="color:green;">' . __("Yes") . '</span>';
}
}

Add columns in admin order list on woocommerce 3.3

Related to:
Add columns to admin orders list in WooCommerce backend
Is it possible to add only one new column in admin Order list instead. For the content of this column my-column1 I will like to have 2 custom fields like:
$my_var_one = get_post_meta( $post_id, '_the_meta_key1', true );
$my_var_two = get_post_meta( $post_id, '_the_meta_key2', true );
To finish is it possible to position this new column after the order_number?
Any help is appreciated.
Updated - It can be done this way:
// ADDING 1 NEW COLUMNS WITH THEIR TITLES
add_filter( 'manage_edit-shop_order_columns', 'custom_shop_order_column',11);
function custom_shop_order_column($columns)
{
$reordered_columns = array();
foreach( $columns as $key => $column){
$reordered_columns[$key] = $column;
if( $key == 'order_number' ){
$reordered_columns['my-column1'] = __( 'Title1','theme_slug');
}
}
return $reordered_columns;
}
// Adding the data for the additional column (example)
add_action( 'manage_shop_order_posts_custom_column' , 'custom_orders_list_column_content', 10, 2 );
function custom_orders_list_column_content( $column, $post_id )
{
if( 'my-column1' == $column )
{
// Get custom post meta data 1
$my_var_one = get_post_meta( $post_id, '_the_meta_key1', true );
if(!empty($my_var_one))
echo $my_var_one;
// Get custom post meta data 2
$my_var_two = get_post_meta( $post_id, '_the_meta_key2', true );
if(!empty($my_var_two))
echo $my_var_two;
// Testing (to be removed) - Empty value case
if( empty($my_var_one) && empty($my_var_two) )
echo '<small>(<em>no value</em>)</small>';
}
}
The other function stays unchanged…
Code goes in function.php file of your active child theme (or active theme). Tested and works.

Displaying shipping zip code in the "Orders" list on Admin -> Woocommerce -> Orders

How can I display the shipping zip code associated to order in the “Orders” list view? Is there a hook that is available to include the shipping as an item in the individual order row?
Thank you.
//add a column
add_filter( 'manage_edit-shop_order_columns', 'MY_COLUMNS_FUNCTION' );
function MY_COLUMNS_FUNCTION($columns){
$new_columns = (is_array($columns)) ? $columns : array();
unset( $new_columns['order_actions'] );
//edit this for you column(s)
//all of your columns will be added before the actions column
$new_columns['MY_COLUMN_ID_1'] = 'Distro test';
//stop editing
$new_columns['order_actions'] = $columns['order_actions'];
return $new_columns;
}
// add data to column
add_action( 'manage_shop_order_posts_custom_column', 'MY_COLUMNS_VALUES_FUNCTION', 2 );
function MY_COLUMNS_VALUES_FUNCTION($column){
// ***WHAT MUST I DO HERE!!!!!!!!!!!!!!!!***
//stop editing
}
// sort column
add_filter( "manage_edit-shop_order_sortable_columns", 'MY_COLUMNS_SORT_FUNCTION' );
function MY_COLUMNS_SORT_FUNCTION( $columns ) {
$custom = array(
//start editing
'MY_COLUMN_ID_1' => 'MY_COLUMN_1_POST_META_ID'
//stop editing
);
return wp_parse_args( $custom, $columns );
}
I tested this and that work on the latest woocommerce version. The way to get order data changed since the link i sent you. So test this :
add_filter( 'manage_edit-shop_order_columns', 'MY_COLUMNS_FUNCTION' );
function MY_COLUMNS_FUNCTION($columns){
$new_columns = (is_array($columns)) ? $columns : array();
unset( $new_columns['order_actions'] );
//edit this for you column(s)
//all of your columns will be added before the actions column
$new_columns['zip_code'] = 'Zip Code';
//stop editing
$new_columns['order_actions'] = $columns['order_actions'];
return $new_columns;
}
add_action( 'manage_shop_order_posts_custom_column', 'MY_COLUMNS_VALUES_FUNCTION',10, 2 );
function MY_COLUMNS_VALUES_FUNCTION($column){
global $post, $the_order;
if ( empty( $the_order ) || $the_order->id != $post->ID ) {
$the_order = wc_get_order( $post->ID );
}
//start editing, I was saving my fields for the orders as custom post meta
//if you did the same, follow this code
if ( $column == 'zip_code' ) {
if(isset($the_order->shipping_postcode)):
$zip_code = $the_order->shipping_postcode;
if($zip_code == 'california store zip code'):
echo 'California';
elseif($zip_code == 'other store zip code'):
echo 'Other store location';
else:
echo $zip_code;
endif;
endif;
}
//stop editing
}

i want to show origin country shipping in the backend of WooCommerce (in Orders overview). How to do it

I am using WooCommerce in wordpress with ups shipping. I have 2 store with different address. I want to show origin country shipping in the backend.
#-----------------------------------------------------------------#
# Test show distro in admin order page
#-----------------------------------------------------------------#
//add a column
add_filter( 'manage_edit-shop_order_columns', 'MY_COLUMNS_FUNCTION' );
function MY_COLUMNS_FUNCTION($columns){
$new_columns = (is_array($columns)) ? $columns : array();
unset( $new_columns['order_actions'] );
//edit this for you column(s)
//all of your columns will be added before the actions column
$new_columns['MY_COLUMN_ID_1'] = 'Distro test';
//stop editing
$new_columns['order_actions'] = $columns['order_actions'];
return $new_columns;
}
// How can i do it here???????
add_action( 'manage_shop_order_posts_custom_column', 'MY_COLUMNS_VALUES_FUNCTION', 2 );
function MY_COLUMNS_VALUES_FUNCTION($column){
global $post;
$data = get_post_meta( $post->ID );
//start editing, I was saving my fields for the orders as custom post meta
//if you did the same, follow this code
if ( $column == 'MY_COLUMN_ID_1' ) {
echo (isset($data['MY_COLUMN_1_POST_META_ID']) ? $data['MY_COLUMN_1_POST_META_ID'] : '');
}
//stop editing
}
// make column can sort
add_filter( "manage_edit-shop_order_sortable_columns", 'MY_COLUMNS_SORT_FUNCTION' );
function MY_COLUMNS_SORT_FUNCTION( $columns ) {
$custom = array(
//start editing
'MY_COLUMN_ID_1' => 'MY_COLUMN_1_POST_META_ID'
//stop editing
);
return wp_parse_args( $custom, $columns );
}
anyone review mycode and tell me what should i do?
This is example
add_filter( 'manage_edit-shop_order_columns', 'MY_COLUMNS_FUNCTION' );
function MY_COLUMNS_FUNCTION($columns){
$new_columns = (is_array($columns)) ? $columns : array();
unset( $new_columns['order_actions'] );
//edit this for you column(s)
//all of your columns will be added before the actions column
$new_columns['zip_code'] = 'Zip Code';
//stop editing
$new_columns['order_actions'] = $columns['order_actions'];
return $new_columns;
}
add_action( 'manage_shop_order_posts_custom_column', 'MY_COLUMNS_VALUES_FUNCTION',10, 2 );
function MY_COLUMNS_VALUES_FUNCTION($column){
global $post, $the_order;
if ( empty( $the_order ) || $the_order->id != $post->ID ) {
$the_order = wc_get_order( $post->ID );
}
//start editing, I was saving my fields for the orders as custom post meta
//if you did the same, follow this code
if ( $column == 'zip_code' ) {
echo (isset($the_order->shipping_postcode) ? $the_order->shipping_postcode : '');
}
//stop editing
}
thanks 1way for this answer.

Categories