Skip to content

Instantly share code, notes, and snippets.

@romanpamula
Created May 15, 2018 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romanpamula/cbf19cfb10d86a2946efbe62ae69af12 to your computer and use it in GitHub Desktop.
Save romanpamula/cbf19cfb10d86a2946efbe62ae69af12 to your computer and use it in GitHub Desktop.
How to add product's category list on order preview modal window in WooCommerce
<?php
/**
* Adds product's category list on admin order preview modal window in WooCommerce
* @since 3.3.0
* @see https://pamula.sk/woocommerce-ako-zobrazit-kategorie-produktu-v-nahlade-objednavky/
*
* Please REMOVE the opening <?php tag before placing into functions.php
* Prosim ODSTRANTE otvaraciu <?php znacku pred umiestnenim do functions.php
*/
add_filter( 'woocommerce_admin_order_preview_line_item_columns', 'rp_add_product_category_column', 10, 2 );
function rp_add_product_category_column( $_columns ) {
$newcol = [ 'category' => __( 'Category', 'woocommerce' ) ];
$items = count( $_columns );
return array_merge( array_slice( $_columns, 0, 1 ), $newcol, array_slice( $_columns, 1, $items - 1 ) );
}
add_filter( 'woocommerce_admin_order_preview_line_item_column_category', 'rp_add_product_category_list', 10, 2 );
function rp_add_product_category_list( $result, $_item ) {
$result = wc_get_product_category_list( $_item['product_id'], ', ', '', '' );
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment