Skip to content

Instantly share code, notes, and snippets.

@dleone81
Last active January 27, 2016 16:33
Show Gist options
  • Save dleone81/a43234f29aa89453540c to your computer and use it in GitHub Desktop.
Save dleone81/a43234f29aa89453540c to your computer and use it in GitHub Desktop.
Add new column to woocommerce product grid, add custom fields value
add_filter( 'manage_edit-product_columns', 'admin_add_in_promo', 10, 2 );
function admin_add_in_promo($columns){
//remove column
//unset( $columns['tags'] );
//add column
$columns['in_promo'] = __( 'Promo');
return $columns;
}
add_action( 'manage_posts_custom_column', 'admin_show_in_promo', 10 );
function admin_show_in_promo( $column) {
global $post;
if ( $column == 'in_promo' ) {
if( function_exists('get_product') ){
$product = get_product( $post->ID );
if( $product->is_type( 'variable' ) ){
$available_variations = $product->get_available_variations();
foreach($available_variations as $k) {
$_in_promo = get_post_meta($k[variation_id], '_in_promo', true);
if($_in_promo == yes) {
$modulo = $k[attributes][attribute_pa_modulo];
echo $modulo . '<br />';
$colore = $k[attributes][attribute_pa_colore];
echo $colore . '<br />';
echo 'Fino al:<br />';
$_special_price_to_date = get_post_meta($k[variation_id], '_special_price_to_date', true);
echo $_special_price_to_date;
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment