Changeset 2981027
- Timestamp:
- 10/19/2023 07:24:06 AM (2 years ago)
- Location:
- uafrica-shipping
- Files:
-
- 6 edited
- 1 copied
-
tags/2.5.19 (copied) (copied from uafrica-shipping/trunk)
-
tags/2.5.19/app/class-woocommerce.php (modified) (1 diff)
-
tags/2.5.19/readme.txt (modified) (2 diffs)
-
tags/2.5.19/uafrica-shipping.php (modified) (3 diffs)
-
trunk/app/class-woocommerce.php (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/uafrica-shipping.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uafrica-shipping/tags/2.5.19/app/class-woocommerce.php
r2857508 r2981027 23 23 // Grab total weight from cart. 24 24 $weight = $cart->get_cart_contents_weight(); 25 } else if ( $order instanceof \WC_Order ){25 } else { 26 26 // Order was likely created/edited on admin or via REST API. Determine total weight from product data. 27 $order = is_a( $order, 'WC_Order' ) ? $order : wc_get_order( $order_id ); 28 if ( empty( $order ) || $order === false ) { 29 return; 30 } 31 27 32 foreach ( $order->get_items() as $item ) { 28 $product = WC()->product_factory->get_product( $item->get_data()['product_id'] ); 33 // Get the product 34 $product = $item->get_product(); 29 35 if ( $product === false ) { 30 36 continue; 31 37 } 32 38 33 $weight += (float) $product->get_weight() * $item->get_quantity(); 34 } 35 } 36 39 if ( ! empty( trim( $product->get_weight() ) ) ) { 40 $weight += (float) $product->get_weight() * $item->get_quantity(); 41 } 42 } 43 } 44 45 // Save the total weight (in grams) in order meta 37 46 $weight = wc_get_weight( $weight, 'g' ); 38 47 update_post_meta( $order_id, 'uafrica_total_grams', $weight ); 48 } 49 50 /** 51 * Save the weight and dimensions of the items in the order as part of order meta so that it is included in order webhooks. 52 * 53 * @param int $order_id ID of the order. 54 * @param array|\WC_Order|null Posted order data, or the existing order. 55 * 56 * @return void 57 */ 58 public static function include_items_meta( $order_id, $order = null ) { 59 if ( ! function_exists( 'WC' ) ) { 60 return; 61 } 62 63 // Get order if not sent along to hook (Happens when hook fires too fast) 64 $order = is_a( $order, 'WC_Order' ) ? $order : wc_get_order( $order_id ); 65 if ( empty( $order ) || $order === false ) { 66 return; 67 } 68 69 $formatted_order_items = array(); 70 71 // Loop through the items 72 foreach ( $order->get_items() as $item ) { 73 // Get the product 74 $product = $item->get_product(); 75 if ( $product === false ) { 76 continue; 77 } 78 79 // Save the product dimensions 80 $formatted_item = array(); 81 if ( ! empty( trim( $product->get_height() ) ) ) { 82 $formatted_item['height_cm'] = (int) wc_get_dimension( $product->get_height(), 'cm' ); 83 } 84 if ( ! empty( trim( $product->get_length() ) ) ) { 85 $formatted_item['length_cm'] = (int) wc_get_dimension( $product->get_length(), 'cm' ); 86 } 87 if ( ! empty( trim( $product->get_width() ) ) ) { 88 $formatted_item['width_cm'] = (int) wc_get_dimension( $product->get_width(), 'cm' ); 89 } 90 // Save the product weight 91 if ( ! empty( trim( $product->get_weight() ) ) ) { 92 $formatted_item['grams'] = (int) wc_get_weight( $product->get_weight(), 'g' ); 93 } 94 95 // Save the item to the array 96 if ( ! empty( $formatted_item ) ) { 97 $formatted_item['id'] = $item->get_id(); 98 array_push( $formatted_order_items, $formatted_item ); 99 } 100 } 101 102 // Update the meta for the items 103 if ( ! empty( $formatted_order_items ) ) { 104 update_post_meta( $order_id, 'bobgo_items_meta', $formatted_order_items ); 105 } 39 106 } 40 107 -
uafrica-shipping/tags/2.5.19/readme.txt
r2966422 r2981027 5 5 Tested up to: 6.1.1 6 6 Requires PHP: 7.0.0 7 Stable tag: 2.5.1 87 Stable tag: 2.5.19 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 71 71 72 72 == Changelog == 73 74 = 2.5.19 = 75 * Add order item information to order meta 73 76 74 77 = 2.5.18 = -
uafrica-shipping/tags/2.5.19/uafrica-shipping.php
r2966422 r2981027 13 13 * Requires at least: 5.0 14 14 * Requires PHP: 7.0 15 * Version: 2.5.1 815 * Version: 2.5.19 16 16 * License: GPLv2 or later 17 17 * … … 25 25 */ 26 26 27 define( 'UAFRICA_SHIPPING_VERSION', '2.5.1 8' );27 define( 'UAFRICA_SHIPPING_VERSION', '2.5.19' ); 28 28 // Endpoints for tracking orders. 29 29 define( 'UAFRICA_SHIPPING_API_TRACKING_V3', 'https://api.bobgo.co.za/tracking?channel=DOMAIN&tracking_reference=NUMBER' ); … … 104 104 // WooCommerce-specific configs, hooks and filter. 105 105 add_action( 'woocommerce_checkout_update_order_meta', array( '\uAfrica_Shipping\app\WooCommerce', 'include_total_grams_in_order' ), 20, 2 ); 106 add_filter( 'woocommerce_checkout_fields', array( '\uAfrica_Shipping\app\WooCommerce', 'add_suburb_to_checkout_fields' ), 20, 1 ); 107 add_filter( 'woocommerce_after_shipping_rate', [ '\uAfrica_Shipping\app\WooCommerce', 'shipping_methods_description' ], 10 , 2 ); 106 108 add_action( 'woocommerce_new_order', [ '\uAfrica_Shipping\app\WooCommerce', 'include_total_grams_in_order' ], 20, 2 ); 109 add_action( 'woocommerce_new_order', [ '\uAfrica_Shipping\app\WooCommerce', 'include_service_code_in_order' ], 10, 2 ); 110 add_action( 'woocommerce_new_order', [ '\uAfrica_Shipping\app\WooCommerce', 'include_items_meta' ], 20, 2 ); 107 111 add_action( 'woocommerce_update_order', [ '\uAfrica_Shipping\app\WooCommerce', 'include_total_grams_in_order' ], 20, 2 ); 112 add_action( 'woocommerce_update_order', [ '\uAfrica_Shipping\app\WooCommerce', 'include_service_code_in_order' ],10, 2 ); 113 add_action( 'woocommerce_update_order', [ '\uAfrica_Shipping\app\WooCommerce', 'include_items_meta' ], 20, 2 ); 108 114 add_filter( 'woocommerce_admin_billing_fields', array( '\uAfrica_Shipping\app\WooCommerce', 'add_suburb_to_admin_address_fields' ), 20, 1 ); 109 115 add_filter( 'woocommerce_admin_shipping_fields', array( '\uAfrica_Shipping\app\WooCommerce', 'add_suburb_to_admin_address_fields' ), 20, 1 ); 110 add_filter( 'woocommerce_checkout_fields', array( '\uAfrica_Shipping\app\WooCommerce', 'add_suburb_to_checkout_fields' ), 20, 1 );111 add_action( 'woocommerce_new_order', [ '\uAfrica_Shipping\app\WooCommerce', 'include_service_code_in_order' ], 10, 2 );112 add_action( 'woocommerce_update_order', [ '\uAfrica_Shipping\app\WooCommerce', 'include_service_code_in_order' ],10, 2 );113 add_filter( 'woocommerce_after_shipping_rate', [ '\uAfrica_Shipping\app\WooCommerce', 'shipping_methods_description' ], 10 , 2 ); -
uafrica-shipping/trunk/app/class-woocommerce.php
r2857508 r2981027 23 23 // Grab total weight from cart. 24 24 $weight = $cart->get_cart_contents_weight(); 25 } else if ( $order instanceof \WC_Order ){25 } else { 26 26 // Order was likely created/edited on admin or via REST API. Determine total weight from product data. 27 $order = is_a( $order, 'WC_Order' ) ? $order : wc_get_order( $order_id ); 28 if ( empty( $order ) || $order === false ) { 29 return; 30 } 31 27 32 foreach ( $order->get_items() as $item ) { 28 $product = WC()->product_factory->get_product( $item->get_data()['product_id'] ); 33 // Get the product 34 $product = $item->get_product(); 29 35 if ( $product === false ) { 30 36 continue; 31 37 } 32 38 33 $weight += (float) $product->get_weight() * $item->get_quantity(); 34 } 35 } 36 39 if ( ! empty( trim( $product->get_weight() ) ) ) { 40 $weight += (float) $product->get_weight() * $item->get_quantity(); 41 } 42 } 43 } 44 45 // Save the total weight (in grams) in order meta 37 46 $weight = wc_get_weight( $weight, 'g' ); 38 47 update_post_meta( $order_id, 'uafrica_total_grams', $weight ); 48 } 49 50 /** 51 * Save the weight and dimensions of the items in the order as part of order meta so that it is included in order webhooks. 52 * 53 * @param int $order_id ID of the order. 54 * @param array|\WC_Order|null Posted order data, or the existing order. 55 * 56 * @return void 57 */ 58 public static function include_items_meta( $order_id, $order = null ) { 59 if ( ! function_exists( 'WC' ) ) { 60 return; 61 } 62 63 // Get order if not sent along to hook (Happens when hook fires too fast) 64 $order = is_a( $order, 'WC_Order' ) ? $order : wc_get_order( $order_id ); 65 if ( empty( $order ) || $order === false ) { 66 return; 67 } 68 69 $formatted_order_items = array(); 70 71 // Loop through the items 72 foreach ( $order->get_items() as $item ) { 73 // Get the product 74 $product = $item->get_product(); 75 if ( $product === false ) { 76 continue; 77 } 78 79 // Save the product dimensions 80 $formatted_item = array(); 81 if ( ! empty( trim( $product->get_height() ) ) ) { 82 $formatted_item['height_cm'] = (int) wc_get_dimension( $product->get_height(), 'cm' ); 83 } 84 if ( ! empty( trim( $product->get_length() ) ) ) { 85 $formatted_item['length_cm'] = (int) wc_get_dimension( $product->get_length(), 'cm' ); 86 } 87 if ( ! empty( trim( $product->get_width() ) ) ) { 88 $formatted_item['width_cm'] = (int) wc_get_dimension( $product->get_width(), 'cm' ); 89 } 90 // Save the product weight 91 if ( ! empty( trim( $product->get_weight() ) ) ) { 92 $formatted_item['grams'] = (int) wc_get_weight( $product->get_weight(), 'g' ); 93 } 94 95 // Save the item to the array 96 if ( ! empty( $formatted_item ) ) { 97 $formatted_item['id'] = $item->get_id(); 98 array_push( $formatted_order_items, $formatted_item ); 99 } 100 } 101 102 // Update the meta for the items 103 if ( ! empty( $formatted_order_items ) ) { 104 update_post_meta( $order_id, 'bobgo_items_meta', $formatted_order_items ); 105 } 39 106 } 40 107 -
uafrica-shipping/trunk/readme.txt
r2966422 r2981027 5 5 Tested up to: 6.1.1 6 6 Requires PHP: 7.0.0 7 Stable tag: 2.5.1 87 Stable tag: 2.5.19 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 71 71 72 72 == Changelog == 73 74 = 2.5.19 = 75 * Add order item information to order meta 73 76 74 77 = 2.5.18 = -
uafrica-shipping/trunk/uafrica-shipping.php
r2966422 r2981027 13 13 * Requires at least: 5.0 14 14 * Requires PHP: 7.0 15 * Version: 2.5.1 815 * Version: 2.5.19 16 16 * License: GPLv2 or later 17 17 * … … 25 25 */ 26 26 27 define( 'UAFRICA_SHIPPING_VERSION', '2.5.1 8' );27 define( 'UAFRICA_SHIPPING_VERSION', '2.5.19' ); 28 28 // Endpoints for tracking orders. 29 29 define( 'UAFRICA_SHIPPING_API_TRACKING_V3', 'https://api.bobgo.co.za/tracking?channel=DOMAIN&tracking_reference=NUMBER' ); … … 104 104 // WooCommerce-specific configs, hooks and filter. 105 105 add_action( 'woocommerce_checkout_update_order_meta', array( '\uAfrica_Shipping\app\WooCommerce', 'include_total_grams_in_order' ), 20, 2 ); 106 add_filter( 'woocommerce_checkout_fields', array( '\uAfrica_Shipping\app\WooCommerce', 'add_suburb_to_checkout_fields' ), 20, 1 ); 107 add_filter( 'woocommerce_after_shipping_rate', [ '\uAfrica_Shipping\app\WooCommerce', 'shipping_methods_description' ], 10 , 2 ); 106 108 add_action( 'woocommerce_new_order', [ '\uAfrica_Shipping\app\WooCommerce', 'include_total_grams_in_order' ], 20, 2 ); 109 add_action( 'woocommerce_new_order', [ '\uAfrica_Shipping\app\WooCommerce', 'include_service_code_in_order' ], 10, 2 ); 110 add_action( 'woocommerce_new_order', [ '\uAfrica_Shipping\app\WooCommerce', 'include_items_meta' ], 20, 2 ); 107 111 add_action( 'woocommerce_update_order', [ '\uAfrica_Shipping\app\WooCommerce', 'include_total_grams_in_order' ], 20, 2 ); 112 add_action( 'woocommerce_update_order', [ '\uAfrica_Shipping\app\WooCommerce', 'include_service_code_in_order' ],10, 2 ); 113 add_action( 'woocommerce_update_order', [ '\uAfrica_Shipping\app\WooCommerce', 'include_items_meta' ], 20, 2 ); 108 114 add_filter( 'woocommerce_admin_billing_fields', array( '\uAfrica_Shipping\app\WooCommerce', 'add_suburb_to_admin_address_fields' ), 20, 1 ); 109 115 add_filter( 'woocommerce_admin_shipping_fields', array( '\uAfrica_Shipping\app\WooCommerce', 'add_suburb_to_admin_address_fields' ), 20, 1 ); 110 add_filter( 'woocommerce_checkout_fields', array( '\uAfrica_Shipping\app\WooCommerce', 'add_suburb_to_checkout_fields' ), 20, 1 );111 add_action( 'woocommerce_new_order', [ '\uAfrica_Shipping\app\WooCommerce', 'include_service_code_in_order' ], 10, 2 );112 add_action( 'woocommerce_update_order', [ '\uAfrica_Shipping\app\WooCommerce', 'include_service_code_in_order' ],10, 2 );113 add_filter( 'woocommerce_after_shipping_rate', [ '\uAfrica_Shipping\app\WooCommerce', 'shipping_methods_description' ], 10 , 2 );
Note: See TracChangeset
for help on using the changeset viewer.