Snippets

Visser Labs Adding static Order Item fields to the Orders export type: unique

Created by Michael Visser last modified
<?php
function custom_woo_ce_extend_order_items_unique_columns( $fields = array(), $i = 0, $original_columns = array() ) {

	if( isset( $original_columns[sprintf( 'order_item_%d_static', $i )] ) )
		$fields[] = sprintf( __( 'Order Item #%d: Static Field', 'woo_ce' ), $i );
	return $fields;

}
add_filter( 'woo_ce_unique_order_item_columns', 'custom_woo_ce_extend_order_items_unique_columns', 10, 3 );

function custom_woo_ce_extend_order_items_unique( $order, $i = 0, $order_item = array() ) {

	$order->{sprintf( 'order_item_%d_static', $i )} = 'Static value';
	return $order;

}
add_filter( 'woo_ce_order_items_unique', 'custom_woo_ce_extend_order_items_unique', 10, 3 );

function custom_woo_ce_unique_order_item_fields_on( $fields = array(), $i = 0 ) {

	$fields[sprintf( 'order_item_%d_static', $i )] = 'on';
	return $fields;

}
add_filter( 'woo_ce_add_unique_order_item_fields_on', 'custom_woo_ce_unique_order_item_fields_on', 10, 2 );

function custom_woo_ce_extend_order_items_unique_fields_exclusion( $excluded_fields = array(), $fields = '' ) {

	$excluded_fields[] = 'order_items_static';
	return $excluded_fields;

}
add_filter( 'woo_ce_add_unique_order_item_fields_exclusion', 'custom_woo_ce_extend_order_items_unique_fields_exclusion', 10, 2 );
?>

Comments (0)