Skip to content

Instantly share code, notes, and snippets.

@ptrsmk
Last active May 5, 2017 14:44
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 ptrsmk/6883ebefd205a16a6c7bdb3238b24600 to your computer and use it in GitHub Desktop.
Save ptrsmk/6883ebefd205a16a6c7bdb3238b24600 to your computer and use it in GitHub Desktop.
foreach ( $_order->order_items as $key => $item ) {
$product_id = ( version_compare( WC_VERSION, '2.7', '<' ) ) ? !empty( $item['variation_id'] ) ? $item['variation_id'] : $item['product_id'] : $item->get_product_id();
$_product = new WC_Product( $product_id );
$needs_shipping = $_product->is_virtual();
if ( !$needs_shipping ) $needs_shipping = 0;
$downloadable = ( $_product->is_downloadable( 'yes' ) ) ? true: false;
if ( $downloadable == null ) $downloadable = 0;
$item_qty = $item['qty'];
$item_name = $item['name'];
$products .= "$item_qty x $item_name \r";
$needs_to_ship = ( $needs_shipping || !$downloadable ) ? true : false;
if ( ! empty( $item[ 'item_meta_array' ] ) ) {
foreach ( $item[ 'item_meta_array' ] as $meta ) {
// Skip hidden core fields
if ( in_array( $meta->key, apply_filters( 'woocommerce_hidden_order_itemmeta', array(
'_qty',
'_tax_class',
'_product_id',
'_variation_id',
'_line_subtotal',
'_line_subtotal_tax',
'_line_total',
'_line_tax',
'method_id',
'cost',
'_commission_total',
'is_wpsls_software',
WC_Vendors::$pv_options->get_option( 'sold_by_label' ),
) ) ) ) {
continue;
}
// Skip serialised meta
if ( is_serialized( $meta->value ) ) {
continue;
}
// Get attribute data
if ( taxonomy_exists( wc_sanitize_taxonomy_name( $meta->key ) ) ) {
$term = get_term_by( 'slug', $meta->value, wc_sanitize_taxonomy_name( $meta->key ) );
$meta->key = wc_attribute_label( wc_sanitize_taxonomy_name( $meta->key ) );
$meta->value = isset( $term->name ) ? $term->name : $meta->value;
} else {
$meta->key = apply_filters( 'woocommerce_attribute_label', wc_attribute_label( $meta->key, $_product ), $meta->key );
}
$products .= wp_kses_post( rawurldecode( $meta->key ) ) . ': ' . wp_kses_post( rawurldecode( $meta->value ) ) . ' | ';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment