Plugin Directory

Changeset 3158473


Ignore:
Timestamp:
09/27/2024 01:54:32 AM (6 months ago)
Author:
wizbee
Message:

2.4.0 update

Location:
easy-duplicate-woo-order
Files:
10 added
4 edited

Legend:

Unmodified
Added
Removed
  • easy-duplicate-woo-order/trunk/easy-duplicate-woo-order.php

    r3156507 r3158473  
    33Plugin Name: Easy Duplicate Woo Order
    44Description: Adds a custom action to duplicate WooCommerce orders easily.
    5 Version: 2.3.2
     5Version: 2.4.0
    66Plugin URI: https://www.wizbeeit.com/easy-duplicate-woo-order
    77Author: wizbee IT
  • easy-duplicate-woo-order/trunk/includes/wb-duplicate-order-admin-option.php

    r3155984 r3158473  
    4141            'default'  => 'wc-pending',
    4242        ),
     43        'copy_coupons' => array( // New setting for copying coupons
     44            'name'     => __('Copy Coupons', 'easy-duplicate-woo-order'),
     45            'type'     => 'checkbox',
     46            'desc'     => __('Enable copying and applying of coupons from the original order.', 'easy-duplicate-woo-order'),
     47            'id'       => 'wizbee_duplicate_order_copy_coupons',
     48            'default'  => 'yes', // Default to enabled
     49        ),
    4350        'section_end' => array(
    4451            'type'     => 'sectionend',
  • easy-duplicate-woo-order/trunk/includes/wb-duplicate-order-function.php

    r3155984 r3158473  
    55}
    66
    7 
    87function wizbee_handle_duplicate_order_action($order) {
    98    if (!is_a($order, 'WC_Order')) {
    109        return;
    1110    }
    12    
     11
    1312    $order_id = $order->get_id();
    1413    $new_order = wc_create_order();
     14   
     15    // Copy customer
     16    $user_id = $order->get_customer_id();
     17    $new_order->set_customer_id($user_id);
    1518
    16     // Get the items from the old order
    17     $items = $order->get_items();
    18     foreach ($items as $item_id => $item) {
    19         $product_id = $item->get_product_id();
    20         $quantity = $item->get_quantity();
    21         $new_order->add_product(wc_get_product($product_id), $quantity);
    22     }
    23 
    24     // Copy order billing and shipping details
     19    // Copy billing and shipping addresses
    2520    $new_order->set_address($order->get_address('billing'), 'billing');
    2621    $new_order->set_address($order->get_address('shipping'), 'shipping');
    2722
     23    // Copy currency information
     24    $currency = $order->get_currency();
     25    $new_order->set_currency($currency);
     26   
     27    // Copy products from old order
     28    $items = $order->get_items();
     29    foreach ($items as $item_id => $originalOrderItem) {
     30        $itemName = $originalOrderItem['name'];
     31        $quantity = $originalOrderItem['qty'];
     32        $lineTotal = $originalOrderItem['line_total'];
     33        $lineTax = $originalOrderItem['line_tax'];
     34        $productID = $originalOrderItem['product_id'];
     35        $variationID = $originalOrderItem['variation_id'];
     36        $taxClass = $originalOrderItem['tax_class'];
     37        $lineSubtotal = $originalOrderItem['line_subtotal'];
     38        $lineSubtotalTax = $originalOrderItem['line_subtotal_tax'];
     39        // Add the product as a line item in the new order
     40        $new_item_id = wc_add_order_item($new_order->get_id(), [
     41            'order_item_name' => $itemName,
     42            'order_item_type' => 'line_item'
     43        ]);
     44        // Copy over all relevant item meta fields
     45        wc_add_order_item_meta($new_item_id, '_qty', $quantity);
     46        wc_add_order_item_meta($new_item_id, '_product_id', $productID);
     47        wc_add_order_item_meta($new_item_id, '_variation_id', $variationID);
     48        wc_add_order_item_meta($new_item_id, '_tax_class', $taxClass);
     49        wc_add_order_item_meta($new_item_id, '_line_total', wc_format_decimal($lineTotal));
     50        wc_add_order_item_meta($new_item_id, '_line_tax', wc_format_decimal($lineTax));
     51        wc_add_order_item_meta($new_item_id, '_line_subtotal', wc_format_decimal($lineSubtotal));
     52        wc_add_order_item_meta($new_item_id, '_line_subtotal_tax', wc_format_decimal($lineSubtotalTax));
     53    }
    2854
    29     // Get the selected order status from settings
     55
     56   
     57    // Copy shipping methods and costs
     58    $shipping_items = $order->get_items('shipping');
     59    foreach ($shipping_items as $shipping_item) {
     60        $new_shipping_item = new WC_Order_Item_Shipping();
     61        $new_shipping_item->set_method_title($shipping_item->get_method_title());
     62        $new_shipping_item->set_method_id($shipping_item->get_method_id());
     63        $new_shipping_item->set_total($shipping_item->get_total());
     64        $new_shipping_item->set_taxes($shipping_item->get_taxes());
     65        $new_order->add_item($new_shipping_item);
     66    }
     67
     68    // Copy fees
     69    $fee_items = $order->get_items('fee');
     70    foreach ($fee_items as $fee_item) {
     71        $new_fee_item = new WC_Order_Item_Fee();
     72        $new_fee_item->set_name($fee_item->get_name());
     73        $new_fee_item->set_total($fee_item->get_total());
     74        $new_fee_item->set_taxes($fee_item->get_taxes());
     75        $new_order->add_item($new_fee_item);
     76    }
     77
     78    // Copy taxes
     79    $tax_items = $order->get_items('tax');
     80    foreach ($tax_items as $tax_item) {
     81        $new_tax_item = new WC_Order_Item_Tax();
     82        $new_tax_item->set_tax_rate_id($tax_item->get_tax_rate_id());
     83        $new_tax_item->set_label($tax_item->get_label());
     84        $new_tax_item->set_compound($tax_item->get_compound());
     85        $new_tax_item->set_tax_total($tax_item->get_tax_total());
     86        $new_tax_item->set_shipping_tax_total($tax_item->get_shipping_tax_total());
     87        $new_order->add_item($new_tax_item);
     88    }
     89   // Copy coupons and apply them if enabled
     90    $copy_coupons = get_option('wizbee_duplicate_order_copy_coupons', 'yes'); // Get the copy coupons setting
     91    if ('yes' === $copy_coupons) { // Check if copying coupons is enabled
     92        $coupons = $order->get_used_coupons(); // Get the applied coupons
     93        foreach ($coupons as $coupon_code) {
     94            $new_order->apply_coupon($coupon_code); // Apply each coupon to the new order
     95        }
     96    }
     97
     98    // Set the selected status
    3099    $original_status = $order->get_status();
    31100    $selected_status = get_option('wizbee_duplicate_order_status', 'wc-pending');
    32 
    33     // Set the selected status directly
    34101    $new_order->set_status($selected_status);
    35102
    36     // Add a custom order note about the status change
     103    // Add a note about the status change
    37104    if ($original_status !== $selected_status) {
    38         // Translators: %1$s is the original order status, %2$s is the new selected status.
    39105        $new_order->add_order_note(sprintf(__('As per duplicate order setting, order status changed from %1$s to %2$s.', 'easy-duplicate-woo-order'),
    40106            wc_get_order_status_name($original_status),
     
    48114    // Save the new order
    49115    $new_order->save();
    50    
     116
    51117    // Add a custom order note about duplication
    52118    $original_order_url = admin_url('post.php?post=' . $order_id . '&action=edit');
    53     // Translators: %1$s is link, #%2$d is the link text.
    54119    $new_order->add_order_note(sprintf(__('Duplicated from order <a href="%1$s">#%2$d</a>', 'easy-duplicate-woo-order'), esc_url($original_order_url), $order_id));
     120
    55121    $new_order_url = admin_url('post.php?post=' . $new_order->get_id() . '&action=edit');
    56     // Translators: %1$s is link, #%2$d is the link text.
    57     $order->add_order_note(sprintf(__('This order duplicated to order <a href="%1$s">#%2$d</a>', 'easy-duplicate-woo-order'), esc_url($new_order_url), $new_order->get_id()));
     122    $order->add_order_note(sprintf(__('This order duplicated to order <a href="%1$s">#%2$d</a>', 'easy-duplicate-woo-order'), esc_url($new_order_url), $new_order->get_id()));
    58123
    59124    // Store the new order ID in a transient
  • easy-duplicate-woo-order/trunk/readme.txt

    r3156507 r3158473  
    55Tested up to: 6.6
    66Requires PHP: 7.2
    7 Stable tag: 2.3.2
     7Stable tag: 2.4.0
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    2323* **Retain Order Details:** The duplicated order retains the same products, billing, and shipping details as the original order.
    2424* **Order Notes with Links:** Automatically adds order notes to both the original and duplicated orders with links to each other, providing a clear reference between the orders.
    25 * **Translation ready**
     25* **Multi-currency support**
    2626
    2727## Why Use Easy Duplicate Woo Order?
     
    39392. Ensure that **WooCommerce** is installed and activated.
    40403. **Activate** the plugin through the 'Plugins' screen in WordPress. If WooCommerce is not active, the plugin will deactivate itself and display an admin notice.
    41 4. **Configure** the default order status for duplicated orders by clicking on the "Settings" link from the plugins page or by navigating to WooCommerce > Settings > Duplicate Order.
     414. **Configure** the default order status and coupon for duplicated orders by clicking on the "Settings" link from the plugins page or by navigating to WooCommerce > Settings > Duplicate Order.
    4242
    4343== Frequently Asked Questions ==
     
    6464
    6565== Changelog ==
     66
     67= 2.4.0 =
     68* Added - Option to control default copy and apply of coupon code.
     69* Added - Multi-currency support.
     70* Fixed - Shipping not copied to new order.
     71* Fixed - Fees not copied to new order.
     72* Improved - All order metadata fields are copied to the new order.
    6673
    6774= 2.3.2 =
Note: See TracChangeset for help on using the changeset viewer.