Plugin Directory

Changeset 2526845


Ignore:
Timestamp:
05/05/2021 06:43:49 PM (5 years ago)
Author:
askbux
Message:

Restock orders

Location:
bux-woocommerce/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • bux-woocommerce/trunk/bux-plugin.php

    r2503114 r2526845  
    44 * Plugin URI: https://bux.ph/static/bux-plugin-wp.zip
    55 * Description: Bux plugin for Woocommerce, you need to have Woocommerce installed
    6  * Version: 1.1.2
     6 * Version: 1.1.3
    77 * Author: UBX Philippines
    88 * Author URI: https://bux.ph
     
    4040            );
    4141}
     42
     43
     44   function restore_order_stock( $order ) {
     45        $items = $order->get_items();
     46
     47        if ( ! get_option('woocommerce_manage_stock') == 'yes' && ! count( $items ) > 0 )
     48                return; // We exit
     49
     50        foreach ( $order->get_items() as $item ) {
     51            $product_id = $item->get_product_id();
     52
     53            if ( $product_id > 0 ) {
     54                $product = $item->get_product();
     55
     56                if ( $product && $product->exists() && $product->managing_stock() ) {
     57
     58                    $initial_stock = $product->get_stock_quantity();
     59
     60                    $item_qty = apply_filters( 'woocommerce_order_item_quantity', $item->get_quantity(), $order, $item );
     61
     62                    wc_update_product_stock( $product, $item_qty, 'increase' );
     63
     64                    $updated_stock = $initial_stock + $item_qty;
     65
     66                    do_action( 'woocommerce_auto_stock_restored', $product, $item );
     67
     68                    $order_note[] = sprintf( __( 'Product ID #%s stock incremented from %s to %s.', 'woocommerce' ), $product_id, $initial_stock, $updated_stock);
     69
     70                }
     71            }
     72        }
     73
     74        $order_notes = count($order_note) > 1 ? implode(' | ', $order_note) : $order_note[0];
     75        $order->add_order_note( $order_notes );
     76    }
     77
    4278function bux_update_order($request) {
    4379
     
    6096    }
    6197    $order = wc_get_order($order_id);
     98    $pre_order_status = $order->get_status();
    6299
    63100        if (empty($order)) {
     
    65102
    66103        }
    67     $order->update_status( $order_status, __( 'Awaiting payment', 'bux-gateway' ) );
     104
     105    if($order_status == "wc-cancelled" && $pre_order_status != "wc-cancelled"){
     106        #only restore stock if not yet cancelled
     107        restore_order_stock($order);
     108        $order->update_status( $order_status, __( 'Payment Expired/Cancelled', 'bux-gateway' ) );
     109    }else if($order_status == "wc-processing" && $pre_order_status != "wc-processing"){
     110        $order->update_status( $order_status, __( 'Payment Successful', 'bux-gateway' ) );
     111    }else{
     112        $order->update_status( $order_status, __( 'Status Update', 'bux-gateway' ) );
     113
     114    }
    68115    return rest_ensure_response( '{"code": "success"}' );
    69116}
     117
    70118
    71119
     
    207255    ) );
    208256
    209     register_post_status( 'wc-paid-bux', array(
    210     'label' => _x( 'Paid via Bux', 'WooCommerce Order status', 'text_domain' ),
    211     'public' => true,
    212     'exclude_from_search' => false,
    213     'show_in_admin_all_list' => true,
    214     'show_in_admin_status_list' => true,
    215     'label_count' => _n_noop( 'Approved (%s)', 'Approved (%s)', 'text_domain' )
    216     ) );
    217 
    218     register_post_status( 'wc-pre-shipping', array(
    219     'label' => _x( 'Pre Shipping', 'WooCommerce Order status', 'text_domain' ),
    220     'public' => true,
    221     'exclude_from_search' => false,
    222     'show_in_admin_all_list' => true,
    223     'show_in_admin_status_list' => true,
    224     'label_count' => _n_noop( 'Approved (%s)', 'Approved (%s)', 'text_domain' )
    225     ) );
    226 
    227     register_post_status( 'wc-pre-transit', array(
    228     'label' => _x( 'Pre Transit', 'WooCommerce Order status', 'text_domain' ),
    229     'public' => true,
    230     'exclude_from_search' => false,
    231     'show_in_admin_all_list' => true,
    232     'show_in_admin_status_list' => true,
    233     'label_count' => _n_noop( 'Approved (%s)', 'Approved (%s)', 'text_domain' )
    234     ) );
    235 
    236     register_post_status( 'wc-in-transit', array(
    237     'label' => _x( 'In Transit', 'WooCommerce Order status', 'text_domain' ),
    238     'public' => true,
    239     'exclude_from_search' => false,
    240     'show_in_admin_all_list' => true,
    241     'show_in_admin_status_list' => true,
    242     'label_count' => _n_noop( 'Approved (%s)', 'Approved (%s)', 'text_domain' )
    243     ) );
    244 
    245     register_post_status( 'wc-delivered', array(
    246     'label' => _x( 'Delivered', 'WooCommerce Order status', 'text_domain' ),
    247     'public' => true,
    248     'exclude_from_search' => false,
    249     'show_in_admin_all_list' => true,
    250     'show_in_admin_status_list' => true,
    251     'label_count' => _n_noop( 'Approved (%s)', 'Approved (%s)', 'text_domain' )
    252     ) );
    253257}
    254258add_filter( 'init', 'bux_wc_register_post_statuses' );
    255 
    256 add_filter( 'woocommerce_reports_order_statuses', 'bux_include_custom_order_status_to_reports', 20, 1 );
    257 
    258 function bux_include_custom_order_status_to_reports( $statuses ){
    259 
    260     return array( 'pre-shipping', 'pre-transit', 'in-transit', 'paid-bux', 'delivered', 'completed' );
    261 }
    262259
    263260/*
     
    306303function bux_wc_add_order_statuses( $order_statuses ) {
    307304    $order_statuses['wc-pending-bux'] = _x( 'Pending Bux Payment', 'WooCommerce Order status', 'text_domain' );
    308     $order_statuses['wc-pre-shipping'] = _x( 'Pre Shipping', 'WooCommerce Order status', 'text_domain' );
    309     $order_statuses['wc-pre-transit'] = _x( 'Pre Transit', 'WooCommerce Order status', 'text_domain' );
    310     $order_statuses['wc-in-transit'] = _x( 'In Transit', 'WooCommerce Order status', 'text_domain' );
    311     $order_statuses['wc-delivered'] = _x( 'Delivered', 'WooCommerce Order status', 'text_domain' );
    312     $order_statuses['wc-paid-bux'] = _x( 'Paid via Bux', 'WooCommerce Order status', 'text_domain' );
    313305    return $order_statuses;
    314306}
  • bux-woocommerce/trunk/readme.txt

    r2503114 r2526845  
    1010Requires PHP: 5.2.4
    1111Stable tag: 1.1.2
    12 Version: 1.1.2
     12Version: 1.1.3
    1313Donate link: https://bux.ph/
    1414
     
    6565* Mobile View Thank you page
    6666
     67= 1.1.3 =
     68* Restock on expired notification from bux
     69
    6770== Upgrade Notice ==
    6871
     
    8891* Mobile View Thank you page
    8992
     93= 1.1.3 =
     94* Restock on expired notification from bux
     95
    9096== Screenshots ==
    9197
Note: See TracChangeset for help on using the changeset viewer.