Plugin Directory

Changeset 2981027


Ignore:
Timestamp:
10/19/2023 07:24:06 AM (2 years ago)
Author:
bobgroup
Message:

Update to version 2.5.19 from GitHub

Location:
uafrica-shipping
Files:
6 edited
1 copied

Legend:

Unmodified
Added
Removed
  • uafrica-shipping/tags/2.5.19/app/class-woocommerce.php

    r2857508 r2981027  
    2323            // Grab total weight from cart.
    2424            $weight = $cart->get_cart_contents_weight();
    25         } elseif ( $order instanceof \WC_Order ) {
     25        } else {
    2626            // 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
    2732            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();
    2935                if ( $product === false ) {
    3036                    continue;
    3137                }
    3238
    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
    3746        $weight = wc_get_weight( $weight, 'g' );
    3847        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        }
    39106    }
    40107
  • uafrica-shipping/tags/2.5.19/readme.txt

    r2966422 r2981027  
    55Tested up to: 6.1.1
    66Requires PHP: 7.0.0
    7 Stable tag: 2.5.18
     7Stable tag: 2.5.19
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    7171
    7272== Changelog ==
     73
     74= 2.5.19 =
     75* Add order item information to order meta
    7376
    7477= 2.5.18 =
  • uafrica-shipping/tags/2.5.19/uafrica-shipping.php

    r2966422 r2981027  
    1313 * Requires at least: 5.0
    1414 * Requires PHP:      7.0
    15  * Version:           2.5.18
     15 * Version:           2.5.19
    1616 * License:           GPLv2 or later
    1717 *
     
    2525 */
    2626
    27 define( 'UAFRICA_SHIPPING_VERSION', '2.5.18' );
     27define( 'UAFRICA_SHIPPING_VERSION', '2.5.19' );
    2828// Endpoints for tracking orders.
    2929define( 'UAFRICA_SHIPPING_API_TRACKING_V3', 'https://api.bobgo.co.za/tracking?channel=DOMAIN&tracking_reference=NUMBER' );
     
    104104// WooCommerce-specific configs, hooks and filter.
    105105add_action( 'woocommerce_checkout_update_order_meta', array( '\uAfrica_Shipping\app\WooCommerce', 'include_total_grams_in_order' ), 20, 2 );
     106add_filter( 'woocommerce_checkout_fields', array( '\uAfrica_Shipping\app\WooCommerce', 'add_suburb_to_checkout_fields' ), 20, 1 );
     107add_filter( 'woocommerce_after_shipping_rate',  [ '\uAfrica_Shipping\app\WooCommerce', 'shipping_methods_description' ], 10 , 2 );
    106108add_action( 'woocommerce_new_order', [ '\uAfrica_Shipping\app\WooCommerce', 'include_total_grams_in_order' ], 20, 2 );
     109add_action( 'woocommerce_new_order', [ '\uAfrica_Shipping\app\WooCommerce', 'include_service_code_in_order' ], 10, 2 );
     110add_action( 'woocommerce_new_order', [ '\uAfrica_Shipping\app\WooCommerce', 'include_items_meta' ], 20, 2 );
    107111add_action( 'woocommerce_update_order', [ '\uAfrica_Shipping\app\WooCommerce', 'include_total_grams_in_order' ], 20, 2 );
     112add_action( 'woocommerce_update_order', [ '\uAfrica_Shipping\app\WooCommerce', 'include_service_code_in_order' ],10, 2 );
     113add_action( 'woocommerce_update_order', [ '\uAfrica_Shipping\app\WooCommerce', 'include_items_meta' ], 20, 2 );
    108114add_filter( 'woocommerce_admin_billing_fields', array( '\uAfrica_Shipping\app\WooCommerce', 'add_suburb_to_admin_address_fields' ), 20, 1 );
    109115add_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  
    2323            // Grab total weight from cart.
    2424            $weight = $cart->get_cart_contents_weight();
    25         } elseif ( $order instanceof \WC_Order ) {
     25        } else {
    2626            // 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
    2732            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();
    2935                if ( $product === false ) {
    3036                    continue;
    3137                }
    3238
    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
    3746        $weight = wc_get_weight( $weight, 'g' );
    3847        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        }
    39106    }
    40107
  • uafrica-shipping/trunk/readme.txt

    r2966422 r2981027  
    55Tested up to: 6.1.1
    66Requires PHP: 7.0.0
    7 Stable tag: 2.5.18
     7Stable tag: 2.5.19
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    7171
    7272== Changelog ==
     73
     74= 2.5.19 =
     75* Add order item information to order meta
    7376
    7477= 2.5.18 =
  • uafrica-shipping/trunk/uafrica-shipping.php

    r2966422 r2981027  
    1313 * Requires at least: 5.0
    1414 * Requires PHP:      7.0
    15  * Version:           2.5.18
     15 * Version:           2.5.19
    1616 * License:           GPLv2 or later
    1717 *
     
    2525 */
    2626
    27 define( 'UAFRICA_SHIPPING_VERSION', '2.5.18' );
     27define( 'UAFRICA_SHIPPING_VERSION', '2.5.19' );
    2828// Endpoints for tracking orders.
    2929define( 'UAFRICA_SHIPPING_API_TRACKING_V3', 'https://api.bobgo.co.za/tracking?channel=DOMAIN&tracking_reference=NUMBER' );
     
    104104// WooCommerce-specific configs, hooks and filter.
    105105add_action( 'woocommerce_checkout_update_order_meta', array( '\uAfrica_Shipping\app\WooCommerce', 'include_total_grams_in_order' ), 20, 2 );
     106add_filter( 'woocommerce_checkout_fields', array( '\uAfrica_Shipping\app\WooCommerce', 'add_suburb_to_checkout_fields' ), 20, 1 );
     107add_filter( 'woocommerce_after_shipping_rate',  [ '\uAfrica_Shipping\app\WooCommerce', 'shipping_methods_description' ], 10 , 2 );
    106108add_action( 'woocommerce_new_order', [ '\uAfrica_Shipping\app\WooCommerce', 'include_total_grams_in_order' ], 20, 2 );
     109add_action( 'woocommerce_new_order', [ '\uAfrica_Shipping\app\WooCommerce', 'include_service_code_in_order' ], 10, 2 );
     110add_action( 'woocommerce_new_order', [ '\uAfrica_Shipping\app\WooCommerce', 'include_items_meta' ], 20, 2 );
    107111add_action( 'woocommerce_update_order', [ '\uAfrica_Shipping\app\WooCommerce', 'include_total_grams_in_order' ], 20, 2 );
     112add_action( 'woocommerce_update_order', [ '\uAfrica_Shipping\app\WooCommerce', 'include_service_code_in_order' ],10, 2 );
     113add_action( 'woocommerce_update_order', [ '\uAfrica_Shipping\app\WooCommerce', 'include_items_meta' ], 20, 2 );
    108114add_filter( 'woocommerce_admin_billing_fields', array( '\uAfrica_Shipping\app\WooCommerce', 'add_suburb_to_admin_address_fields' ), 20, 1 );
    109115add_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.