Changeset 3159415
- Timestamp:
- 09/29/2024 04:04:21 AM (6 months ago)
- Location:
- easy-duplicate-woo-order
- Files:
-
- 12 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
easy-duplicate-woo-order/trunk/easy-duplicate-woo-order.php
r3158473 r3159415 3 3 Plugin Name: Easy Duplicate Woo Order 4 4 Description: Adds a custom action to duplicate WooCommerce orders easily. 5 Version: 2. 4.05 Version: 2.5.0 6 6 Plugin URI: https://www.wizbeeit.com/easy-duplicate-woo-order 7 7 Author: wizbee IT … … 58 58 function wizbee_enqueue_duplicate_order_script() { 59 59 if (is_admin()) { 60 wp_enqueue_script('wizbee-duplicate-order-script', plugin_dir_url(__FILE__) . 'assets/js/easy-duplicate-order-redirect-script.js', array('jquery'), '1. 0.0', true);60 wp_enqueue_script('wizbee-duplicate-order-script', plugin_dir_url(__FILE__) . 'assets/js/easy-duplicate-order-redirect-script.js', array('jquery'), '1.1', true); 61 61 $redirect_order_id = get_transient('wizbee_duplicate_order_redirect'); 62 62 wp_localize_script('wizbee-duplicate-order-script', 'wizbeeOrderData', array( … … 69 69 add_action('admin_enqueue_scripts', 'wizbee_enqueue_duplicate_order_script'); 70 70 71 if (isset($_GET['page']) && $_GET['page'] === 'wc-settings' && isset($_GET['tab']) && $_GET['tab'] === 'wizbee_duplicate_order') { 72 // Enqueue your JavaScript file 73 wp_enqueue_script('wizbee-admin-script', plugin_dir_url(__FILE__) . 'assets/js/admin-settings.js', array('jquery'), '1.1', true); 74 } -
easy-duplicate-woo-order/trunk/includes/wb-duplicate-order-admin-option.php
r3158473 r3159415 23 23 } 24 24 25 // Define settings fields 25 26 26 function wizbee_get_settings() { 27 27 $order_statuses = wc_get_order_statuses(); … … 41 41 'default' => 'wc-pending', 42 42 ), 43 'copy_coupons' => array( // New setting for copying coupons 44 'name' => __('Copy Coupons', 'easy-duplicate-woo-order'), 43 'copy_old_price' => array( 44 'name' => __('Copy Old Price', 'easy-duplicate-woo-order'), 45 'type' => 'checkbox', 46 'desc' => __('Enable copying of price from the original order.<br>Enable if you use multi currency', 'easy-duplicate-woo-order'), 47 'id' => 'wizbee_duplicate_order_copy_old_price', 48 'default' => 'yes', 49 ), 50 'apply_coupons' => array( 51 'name' => __('Apply Coupons', 'easy-duplicate-woo-order'), 45 52 'type' => 'checkbox', 46 53 '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 54 'id' => 'wizbee_duplicate_order_apply_coupons', 55 'default' => 'yes', 56 'class' => 'coupons-options', 57 ), 58 'copy_fees' => array( 59 'name' => __('Copy Fee', 'easy-duplicate-woo-order'), 60 'type' => 'checkbox', 61 'desc' => __('Enable copying of fees from the original order.', 'easy-duplicate-woo-order'), 62 'id' => 'wizbee_duplicate_order_copy_fees', 63 'default' => 'yes', 64 'class' => 'fee-options', 65 ), 66 'copy_shipping' => array( 67 'name' => __('Copy Shipping', 'easy-duplicate-woo-order'), 68 'type' => 'checkbox', 69 'desc' => __('Enable copying of shipping information.', 'easy-duplicate-woo-order'), 70 'id' => 'wizbee_duplicate_order_copy_shipping', 71 'default' => 'yes', 72 'class' => 'ship-options', 49 73 ), 50 74 'section_end' => array( -
easy-duplicate-woo-order/trunk/includes/wb-duplicate-order-function.php
r3158473 r3159415 12 12 $order_id = $order->get_id(); 13 13 $new_order = wc_create_order(); 14 15 // Copy customer16 $user_id = $order->get_customer_id();17 $new_order->set_customer_id($user_id);18 14 19 // Copy billing and shipping addresses 15 // Copy customer 16 $user_id = $order->get_customer_id(); 17 $new_order->set_customer_id($user_id); 18 19 // Copy billing and shipping addresses 20 20 $new_order->set_address($order->get_address('billing'), 'billing'); 21 21 $new_order->set_address($order->get_address('shipping'), 'shipping'); 22 22 23 // Copy currency information 24 $currency = $order->get_currency(); 25 $new_order->set_currency($currency); 26 27 // Copy products from old order 23 // settings 24 $copy_old_price = get_option('wizbee_duplicate_order_copy_old_price', 'yes'); 25 $copy_fees = get_option('wizbee_duplicate_order_copy_fees', 'yes'); 26 $copy_shipping = get_option('wizbee_duplicate_order_copy_shipping', 'yes'); 27 $apply_coupons = get_option('wizbee_duplicate_order_apply_coupons', 'yes'); 28 29 // Product items 28 30 $items = $order->get_items(); 29 foreach ($items as $item_id => $originalOrderItem) { 30 $itemName = $originalOrderItem['name']; 31 foreach ($items as $item_id => $originalOrderItem) { 31 32 $quantity = $originalOrderItem['qty']; 32 $lineTotal = $originalOrderItem['line_total'];33 $line Tax = $originalOrderItem['line_tax'];33 $variationID = $originalOrderItem['variation_id']; 34 $lineSubtotal = $originalOrderItem['line_subtotal']; 34 35 $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']; 36 $product = wc_get_product($productID); 37 38 if ('yes' === $copy_old_price) { 39 if ('yes' === $apply_coupons) { 40 $lineTotal = $originalOrderItem['line_total']; 41 } else { 42 $lineSubtotal = $originalOrderItem['line_subtotal'] / $quantity; 43 $lineNewSubtotal = $lineSubtotal; 44 $lineTotal = $lineNewSubtotal * $quantity; 45 } 46 } else { 47 $lineTotal = $product ? $product->get_price() * $quantity : 0; 48 } 49 39 50 // Add the product as a line item in the new order 40 51 $new_item_id = wc_add_order_item($new_order->get_id(), [ 41 'order_item_name' => $ itemName,42 'order_item_type' => 'line_item' 52 'order_item_name' => $originalOrderItem['name'], 53 'order_item_type' => 'line_item', 43 54 ]); 44 // Copy over all relevant item meta fields 55 $original_meta_data = $originalOrderItem->get_meta_data(); 56 foreach ($original_meta_data as $meta) { 57 wc_add_order_item_meta($new_item_id, $meta->key, $meta->value, true); // Add original meta to the new item 58 } 59 // Copy item meta and set calculated price 45 60 wc_add_order_item_meta($new_item_id, '_qty', $quantity); 46 61 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); 62 wc_add_order_item_meta($new_item_id, '_variation_id', $variationID); 49 63 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 64 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 65 } 54 66 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); 67 // Copy currency 68 if ('yes' === $copy_old_price) { 69 $currency = $order->get_currency(); 70 $new_order->set_currency($currency); 66 71 } 67 72 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); 73 // Copy fees, shipping, and coupons 74 if ('yes' === $copy_fees) { 75 $fee_items = $order->get_items('fee'); 76 foreach ($fee_items as $fee_item) { 77 $new_fee_item = new WC_Order_Item_Fee(); 78 $new_fee_item->set_name($fee_item->get_name()); 79 $new_fee_item->set_total($fee_item->get_total()); 80 //$new_fee_item->set_taxes($fee_item->get_taxes()); 81 $new_order->add_item($new_fee_item); 82 } 76 83 } 77 84 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); 85 if ('yes' === $copy_shipping) { 86 $shipping_items = $order->get_items('shipping'); 87 foreach ($shipping_items as $shipping_item) { 88 $new_shipping_item = new WC_Order_Item_Shipping(); 89 $new_shipping_item->set_method_title($shipping_item->get_method_title()); 90 $new_shipping_item->set_method_id($shipping_item->get_method_id()); 91 $new_shipping_item->set_total($shipping_item->get_total()); 92 //$new_shipping_item->set_taxes($shipping_item->get_taxes()); 93 // Copy shipping item meta data 94 $meta_data = $shipping_item->get_meta_data(); 95 foreach ($meta_data as $meta) { 96 $new_shipping_item->add_meta_data($meta->key, $meta->value, true); 97 } 98 99 $new_order->add_item($new_shipping_item); 100 } 88 101 } 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 102 103 if ('yes' === $apply_coupons) { 104 $coupons = $order->get_used_coupons(); 93 105 foreach ($coupons as $coupon_code) { 94 $new_order->apply_coupon($coupon_code); // Apply each coupon to the new order106 $new_order->apply_coupon($coupon_code); 95 107 } 96 108 } 97 109 98 110 // Set the selected status 99 $original_status = $order->get_status();100 111 $selected_status = get_option('wizbee_duplicate_order_status', 'wc-pending'); 101 112 $new_order->set_status($selected_status); 102 113 103 // Add a note about the status change 104 if ($original_status !== $selected_status) { 105 $new_order->add_order_note(sprintf(__('As per duplicate order setting, order status changed from %1$s to %2$s.', 'easy-duplicate-woo-order'), 106 wc_get_order_status_name($original_status), 107 wc_get_order_status_name($selected_status) 108 )); 109 } 110 111 // Recalculate totals for the new order 114 112 115 $new_order->calculate_totals(); 113 114 // Save the new order115 116 $new_order->save(); 116 117 117 // Add a custom order note about duplication118 // Add notes for tracking 118 119 $original_order_url = admin_url('post.php?post=' . $order_id . '&action=edit'); 119 120 $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)); -
easy-duplicate-woo-order/trunk/readme.txt
r3158473 r3159415 2 2 Contributors: wizbee 3 3 Tags: woocommerce, duplicate order, manage order, order clone 4 Requires at least: 5.04 Requires at least: 6.0 5 5 Tested up to: 6.6 6 6 Requires PHP: 7.2 7 Stable tag: 2. 4.07 Stable tag: 2.5.0 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 65 65 == Changelog == 66 66 67 = 2.5.0 = 68 * Added - Option to control default copy of price, coupon, fees, and shipping from admin setting. 69 * Fix - Error if tax is enabled. 70 * Fix - Product variation handling. 71 * Improved - Copy of product meta data. 72 * Various other fixes and improvements. 73 67 74 = 2.4.0 = 68 75 * Added - Option to control default copy and apply of coupon code.
Note: See TracChangeset
for help on using the changeset viewer.