Modify Existing Fields
1 2 3 4 |
// add order prefix add_filter('woe_get_order_value_order_number', function ($value, $order, $fieldname) { return "KTR-" . $value; }, 10, 3); |
1 2 3 4 |
// remove line breaks from customer note add_filter('woe_get_order_value_customer_note',function ($value, $order,$fieldname) { return preg_replace( "/\r|\n/", "", $value); },10,3); |
1 2 3 4 |
// swap last and first names in "Shipping Full Name" add_filter('woe_get_order_value_shipping_full_name',function ($value, $order,$fieldname) { return $order->get_shipping_last_name(). ' ' . $order->get_shipping_first_name(); },10,3); |
1 2 3 4 5 6 |
// remap shipping method titles add_filter('woe_get_order_value_shipping_method_title', function ($value, $order, $fieldname) { if($value == 'Flat rate') // copy these 2 lines for other mappings $value = 'STANDARD'; return $value; }, 10, 3); |
1 2 3 4 |
// format product weight, 0.2->0.200 and 0.12->0.120 add_filter('woe_get_order_product_value_weight', function ($value, $order, $item, $product,$Item_meta) { return number_format($value,3,'.',''); }, 10, 5); |
1 2 3 4 5 6 7 8 |
// fix problem with apostrophe in "WC Fields Factory" add_filter( "woe_get_order_product_item_meta", function($item_meta ){ foreach($item_meta as $k=>$v) { $k2 = html_entity_decode ($k,ENT_QUOTES); $item_meta[$k2] = $v; } return $item_meta; }); |
1 2 3 4 5 6 7 8 9 10 11 12 |
// fill empty shipping address add_filter( "woe_fetch_order", function ($row, $order) { if( empty($row['shipping_address_1']) ) { // overwrite address $row['shipping_address_1'] = $row['billing_address_1']; $row['shipping_address_2'] = $row['billing_address_2']; $row['shipping_city'] = $row['billing_city']; $row['shipping_state'] = $row['billing_state']; $row['shipping_postcode'] = $row['billing_postcode']; } return $row; },10,2); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
//convert "order total" and "item price" from CNY to USD class WOE_currency_mod { var $rate = false; function __construct() { add_filter('woe_get_order_value_order_total',array($this,'convert_cny_usd'), 10, 3); add_filter('woe_get_order_product_value_item_price',array($this,'convert_cny_usd'), 10, 3); } function convert_cny_usd($value, $order,$fieldname) { return round( $value * $this->get_rate(), 2 ); } function get_rate() { if( $this->rate === false) { $response = wp_remote_get("http://ratesapi.io/api/latest?base=CNY&symbols=USD"); $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); $this->rate = $api_response['rates']['USD']; } return $this->rate; } } new WOE_currency_mod(); |