Plugin Directory

Changeset 2290829

Timestamp:
04/24/2020 09:00:16 AM (4 years ago)
Author:
LiamMcArthur
Message:

Re-worked entire module to make automatically completing orders much more streamlined

Location:
autocomplete-woocommerce-orders
Files:
6 added
3 edited

Legend:

Unmodified
Added
Removed
  • autocomplete-woocommerce-orders/trunk/autocomplete-woocommerce-orders.php

    r2289186 r2290829  
    44 * Plugin URI: https://wordpress.org/plugins/autocomplete-woocommerce-orders/
    55 * Description: Autocomplete your WooCommerce orders with ease. This plugins works with most major payment providers including PayPal, SagePay and Stripe.
    6  * Version: 1.2.2
     6 * Version: 1.
    77 * Author: Liam McArthur
    88 * Author URI: https://www.silkwave.co.uk
  • autocomplete-woocommerce-orders/trunk/includes/class-admin.php

    r2289186 r2290829  
    4646            ), 10);
    4747        }
    48         add_action('init', array($this, 'silkwave_autocomplete_orders'), 0);
     48        add_);
    4949    }
    5050
    51     function silkwave_autocomplete_orders()
     51    )
    5252    {
     53
    5354        $mode = get_option('wc_' . $this->id . '_mode');
    54         if ($mode == 'all') {
    55             add_action('woocommerce_thankyou', 'silkwave_autocomplete_all_orders');
    5655
    57             function silkwave_autocomplete_all_orders($order_id)
    58             {
    59                 global $woocommerce;
     56        switch ($mode) {
     57            case 'none':
     58                $order_status = 'processing';
     59                break;
     60            case 'all':
     61            case 'paid':
     62                $order_status = 'completed';
     63                break;
     64            case 'virtual':
     65                $order = wc_get_order($order_id);
    6066
    61                 if (!$order_id) {
    62                     return;
    63                 }
    64                 $order = new WC_Order($order_id);
    65                 $order->update_status('completed');
    66             }
    67         } elseif ($mode == 'paid') {
    68             add_filter('woocommerce_payment_complete_order_status', 'silkwave_autocomplete_paid_orders', 10, 2);
    69             function silkwave_autocomplete_paid_orders($order_status, $order_id)
    70             {
    71                 return 'completed';
    72             }
    73         } elseif ($mode == 'virtual') {
    74             add_action( 'woocommerce_payment_complete_order_status', 'silkwave_auto_complete_virtual_paid_order', 10, 3 );
    75             function silkwave_auto_complete_virtual_paid_order( $status, $order_id, $order ) {
    76                 $virtual_order = null;
    77                 if ( count( $order->get_items() ) > 0 ) {
    78                     foreach ( $order->get_items() as $item ) {
    79                         if ( 'line_item' == $item['type'] ) {
    80                             if ( defined( 'WOOCOMMERCE_VERSION' ) && version_compare( WOOCOMMERCE_VERSION, '3.0', '<' ) ) {
    81                                 $_product = $order->get_product_from_item( $item );
     67                if ($order && $order_status === 'processing' && in_array($order->get_status(), ['pending', 'on-hold', 'failed'], true)) {
     68
     69                    $virtual = false;
     70                    $items = $order->get_items();
     71
     72                    if (count($items ) > 0) {
     73                        foreach ($items  as $item) {
     74                            if (is_callable([$item, 'get_product'])) {
     75                                $product = $item->get_product();
     76                            } elseif (is_callable([$order, 'get_product_from_item'])) {
     77                                $product = $order->get_product_from_item($item);
    8278                            } else {
    83                                 $_product = $item->get_product();
     79                                $;
    8480                            }
    85                             if ( ! $_product->is_virtual() ) {
    86                                 $virtual_order = false;
     81
     82                            if (!$product->is_virtual()) {
     83                                $virtual = false;
    8784                                break;
    88                             } else {
    89                                 $virtual_order = true;
    9085                            }
     86
    9187                        }
    9288                    }
     89
     90
     91
    9392                }
    94                 if ( $virtual_order ) {
    95                     return 'completed';
    96                 }
    97             }
     93                break;
    9894        }
     95
    9996    }
    10097
  • autocomplete-woocommerce-orders/trunk/readme.txt

    r2289186 r2290829  
    4343== Changelog ==
    4444
     45
     46
     47
    4548= 1.2.2 =
    4649* Added logic back in for automatically completing Virtual orders
Note: See TracChangeset for help on using the changeset viewer.