From 3f67b4aa3fc698eb582470824cf4349573e391ec Mon Sep 17 00:00:00 2001 From: Pablo Pacheco Date: Wed, 15 May 2024 18:40:40 -0300 Subject: [PATCH] v3.4.1 --- cost-of-goods-for-woocommerce.php | 2 +- includes/class-alg-wc-cog-orders.php | 52 +++++++++++-------- includes/class-alg-wc-cog.php | 2 +- .../class-alg-wc-cog-settings-advanced.php | 12 ++--- langs/cost-of-goods-for-woocommerce.pot | 30 +++++------ readme.txt | 8 ++- 6 files changed, 59 insertions(+), 47 deletions(-) diff --git a/cost-of-goods-for-woocommerce.php b/cost-of-goods-for-woocommerce.php index 152850f..74ffac9 100644 --- a/cost-of-goods-for-woocommerce.php +++ b/cost-of-goods-for-woocommerce.php @@ -3,7 +3,7 @@ Plugin Name: Cost of Goods for WooCommerce Plugin URI: https://wpfactory.com/item/cost-of-goods-for-woocommerce/ Description: Save product purchase costs (cost of goods) in WooCommerce. Beautifully. -Version: 3.4.0 +Version: 3.4.1 Author: WPFactory Author URI: https://wpfactory.com Text Domain: cost-of-goods-for-woocommerce diff --git a/includes/class-alg-wc-cog-orders.php b/includes/class-alg-wc-cog-orders.php index 54c552b..713ecd6 100644 --- a/includes/class-alg-wc-cog-orders.php +++ b/includes/class-alg-wc-cog-orders.php @@ -2,7 +2,7 @@ /** * Cost of Goods for WooCommerce - Orders Class. * - * @version 3.3.7 + * @version 3.4.1 * @since 2.1.0 * @author WPFactory */ @@ -387,8 +387,8 @@ function add_hooks() { add_action( 'woocommerce_before_save_order_items', array( $this, 'save_order_items_ajax' ), PHP_INT_MAX, 2 ); // Save order items costs on new order. add_action( 'woocommerce_new_order', array( $this, 'update_order_items_costs_on_new_order' ), 10 ); - add_action( 'woocommerce_store_api_checkout_order_processed', array( $this, 'save_cost_input_shop_order_new' ), 10 ); add_action( 'woocommerce_new_order', array( $this, 'save_cost_input_shop_order_new' ), PHP_INT_MAX, 2 ); + add_action( 'woocommerce_store_api_checkout_order_processed', array( $this, 'save_cost_input_shop_order_new' ), 10 ); add_action( 'woocommerce_api_create_order', array( $this, 'save_cost_input_shop_order_new' ), PHP_INT_MAX ); add_action( 'woocommerce_cli_create_order', array( $this, 'save_cost_input_shop_order_new' ), PHP_INT_MAX ); add_action( 'kco_before_confirm_order', array( $this, 'save_cost_input_shop_order_new' ), PHP_INT_MAX ); @@ -665,7 +665,7 @@ function add_order_shipping_cost_to_profit( $order_values, $order_info ) { /** * get_new_order_hooks_for_cost_updating. * - * @version 3.3.6 + * @version 3.4.1 * @since 2.6.3 * * @return array @@ -677,7 +677,9 @@ function get_new_order_hooks_for_cost_updating() { 'woocommerce_cli_create_order' => 'woocommerce_cli_create_order', 'kco_before_confirm_order' => 'kco_before_confirm_order', 'woocommerce_checkout_order_processed' => 'woocommerce_checkout_order_processed', - 'woocommerce_store_api_checkout_order_processed' => 'woocommerce_store_api_checkout_order_processed' + 'woocommerce_store_api_checkout_order_processed' => 'woocommerce_store_api_checkout_order_processed', + 'save_post_shop_order' => 'woocommerce_store_api_checkout_order_processed', + 'woocommerce_process_shop_order_meta' => 'woocommerce_process_shop_order_meta', ); } @@ -960,7 +962,7 @@ function update_order_item_costs_on_order_meta_update( $meta_id, $post_id, $meta /** * update_order_items_costs_on_new_order. * - * @version 3.3.6 + * @version 3.4.1 * @since 3.3.6 * * @param $order_id @@ -968,12 +970,14 @@ function update_order_item_costs_on_order_meta_update( $meta_id, $post_id, $meta * @return void */ function update_order_items_costs_on_new_order( $order_id ) { - remove_action( 'woocommerce_new_order', array( $this, 'update_order_items_costs_on_new_order' ), 10 ); - $this->update_order_items_costs( array( - 'order_id' => $order_id, - 'is_new_order' => true, - 'is_no_costs_only' => false - ) ); + if ( in_array( current_filter(), get_option( 'alg_wc_cog_new_order_hooks_for_cost_update', array_keys( $this->get_new_order_hooks_for_cost_updating() ) ) ) ) { + remove_action( 'woocommerce_new_order', array( $this, 'update_order_items_costs_on_new_order' ), 10 ); + $this->update_order_items_costs( array( + 'order_id' => $order_id, + 'is_new_order' => true, + 'is_no_costs_only' => false + ) ); + } } /** @@ -1015,24 +1019,26 @@ function update_order_items_costs_new_item( $item_id, $item, $order_id ) { /** * save_cost_input_shop_order_save_post. * - * @version 3.3.6 + * @version 3.4.1 * @since 1.1.0 */ function save_cost_input_shop_order_save_post( $post_id, $post ) { - remove_action( 'save_post_shop_order', array( $this, 'save_cost_input_shop_order_save_post' ), 9 ); - remove_action( 'woocommerce_process_shop_order_meta', array( $this, 'save_cost_input_shop_order_save_post' ), 9 ); - - $this->update_order_items_costs( array( - 'order_id' => $post_id, - 'is_new_order' => false, - ) ); + if ( in_array( current_filter(), get_option( 'alg_wc_cog_new_order_hooks_for_cost_update', array_keys( $this->get_new_order_hooks_for_cost_updating() ) ) ) ) { + remove_action( 'save_post_shop_order', array( $this, 'save_cost_input_shop_order_save_post' ), 9 ); + remove_action( 'woocommerce_process_shop_order_meta', array( $this, 'save_cost_input_shop_order_save_post' ), 9 ); - if ( $this->do_force_on_order_update ) { $this->update_order_items_costs( array( - 'order_id' => $post_id, - 'is_new_order' => true, - 'is_no_costs_only' => true + 'order_id' => $post_id, + 'is_new_order' => false, ) ); + + if ( $this->do_force_on_order_update ) { + $this->update_order_items_costs( array( + 'order_id' => $post_id, + 'is_new_order' => true, + 'is_no_costs_only' => true + ) ); + } } } diff --git a/includes/class-alg-wc-cog.php b/includes/class-alg-wc-cog.php index 5305392..f2d3c73 100644 --- a/includes/class-alg-wc-cog.php +++ b/includes/class-alg-wc-cog.php @@ -35,7 +35,7 @@ final class Alg_WC_Cost_of_Goods { * @since 1.0.0 * @var string */ - public $version = '3.4.0'; + public $version = '3.4.1'; /** * @since 1.0.0 diff --git a/includes/settings/class-alg-wc-cog-settings-advanced.php b/includes/settings/class-alg-wc-cog-settings-advanced.php index 1c4c4e0..379480c 100644 --- a/includes/settings/class-alg-wc-cog-settings-advanced.php +++ b/includes/settings/class-alg-wc-cog-settings-advanced.php @@ -2,7 +2,7 @@ /** * Cost of Goods for WooCommerce - Advanced Section Settings. * - * @version 3.1.3 + * @version 3.4.1 * @since 1.7.0 * @author WPFactory */ @@ -44,7 +44,7 @@ function get_allowed_user_roles_option() { /** * get_settings. * - * @version 3.1.3 + * @version 3.4.1 * @since 1.7.0 * @todo [later] "Force costs update on ...": better title and desc (3x) */ @@ -71,7 +71,7 @@ function get_settings() { 'custom_attributes' => apply_filters( 'alg_wc_cog_settings', array( 'disabled' => 'disabled' ) ), ), array( - 'title' => __( 'Force costs update', 'cost-of-goods-for-woocommerce' ), + 'title' => __( 'Order item costs', 'cost-of-goods-for-woocommerce' ), 'desc' => __( 'Auto fill empty order items costs on order update', 'cost-of-goods-for-woocommerce' ), 'id' => 'alg_wc_cog_orders_force_on_update', 'default' => 'no', @@ -101,8 +101,8 @@ function get_settings() { 'type' => 'checkbox', ), array( - 'title' => __( 'Costs update hooks', 'cost-of-goods-for-woocommerce' ), - 'desc' => __( 'Hooks from new orders that will trigger cost update.', 'cost-of-goods-for-woocommerce' ), + 'title' => __( 'Order calculation hooks', 'cost-of-goods-for-woocommerce' ), + 'desc' => __( 'Hooks that will update order cost/profit calculation.', 'cost-of-goods-for-woocommerce' ), 'id' => 'alg_wc_cog_new_order_hooks_for_cost_update', 'type' => 'multiselect', 'class' => 'chosen_select', @@ -110,7 +110,7 @@ function get_settings() { 'options' => alg_wc_cog()->core->orders->get_new_order_hooks_for_cost_updating() ), array( - 'title' => __( 'Metadata', 'cost-of-goods-for-woocommerce' ), + 'title' => __( 'Order metadata', 'cost-of-goods-for-woocommerce' ), 'desc' => __( 'Avoid empty order metadata from being saved to database', 'cost-of-goods-for-woocommerce' ), 'id' => 'alg_wc_cog_avoid_empty_order_metadata_saving', 'default' => 'yes', diff --git a/langs/cost-of-goods-for-woocommerce.pot b/langs/cost-of-goods-for-woocommerce.pot index 8f2cf45..29df42e 100644 --- a/langs/cost-of-goods-for-woocommerce.pot +++ b/langs/cost-of-goods-for-woocommerce.pot @@ -2,14 +2,14 @@ # This file is distributed under the GNU General Public License v3.0. msgid "" msgstr "" -"Project-Id-Version: cost-of-goods-for-woocommerce 3.4.0\n" +"Project-Id-Version: cost-of-goods-for-woocommerce 3.4.1\n" "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/cost-of-goods-for-woocommerce\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"POT-Creation-Date: 2024-05-08T23:20:03+02:00\n" +"POT-Creation-Date: 2024-05-15T23:39:57+02:00\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "X-Generator: WP-CLI 2.7.1\n" "X-Domain: cost-of-goods-for-woocommerce\n" @@ -75,8 +75,8 @@ msgstr "" #: includes/analytics/class-alg-wc-cog-analytics-revenue.php:47 #: includes/analytics/class-alg-wc-cog-analytics-stock.php:281 #: includes/class-alg-wc-cog-orders-meta-boxes.php:155 -#: includes/class-alg-wc-cog-orders.php:748 -#: includes/class-alg-wc-cog-orders.php:858 +#: includes/class-alg-wc-cog-orders.php:750 +#: includes/class-alg-wc-cog-orders.php:860 #: includes/class-alg-wc-cog-products-add-stock.php:352 #: includes/class-alg-wc-cog-products-add-stock.php:408 #: includes/class-alg-wc-cog-products.php:301 @@ -104,8 +104,8 @@ msgstr "" #: includes/analytics/class-alg-wc-cog-analytics-revenue.php:48 #: includes/analytics/class-alg-wc-cog-analytics-stock.php:282 #: includes/class-alg-wc-cog-orders-meta-boxes.php:156 -#: includes/class-alg-wc-cog-orders.php:749 -#: includes/class-alg-wc-cog-orders.php:868 +#: includes/class-alg-wc-cog-orders.php:751 +#: includes/class-alg-wc-cog-orders.php:870 #: includes/class-alg-wc-cog-products.php:383 #: includes/pro/class-alg-wc-cog-pro-compatibility-wpsyncsheets.php:53 #: includes/pro/reports/class-wc-report-alg-cog-stock.php:123 @@ -280,24 +280,24 @@ msgstr "" msgid "Shipping to profit (%s)" msgstr "" -#: includes/class-alg-wc-cog-orders.php:752 -#: includes/class-alg-wc-cog-orders.php:1190 +#: includes/class-alg-wc-cog-orders.php:754 +#: includes/class-alg-wc-cog-orders.php:1196 #: includes/pro/class-alg-wc-cog-pro.php:638 #: includes/pro/class-alg-wc-cog-pro.php:657 msgid "Cost of goods" msgstr "" -#: includes/class-alg-wc-cog-orders.php:871 +#: includes/class-alg-wc-cog-orders.php:873 #: includes/settings/class-alg-wc-cog-settings-orders.php:48 msgid "Profit percent" msgstr "" -#: includes/class-alg-wc-cog-orders.php:874 +#: includes/class-alg-wc-cog-orders.php:876 #: includes/settings/class-alg-wc-cog-settings-orders.php:48 msgid "Profit margin" msgstr "" -#: includes/class-alg-wc-cog-orders.php:1226 +#: includes/class-alg-wc-cog-orders.php:1232 msgid "Handling Fee" msgstr "" @@ -741,7 +741,7 @@ msgid "The administrator can't be blocked." msgstr "" #: includes/settings/class-alg-wc-cog-settings-advanced.php:74 -msgid "Force costs update" +msgid "Order item costs" msgstr "" #: includes/settings/class-alg-wc-cog-settings-advanced.php:75 @@ -765,15 +765,15 @@ msgid "Only triggers with meta not starting with _alg_wc_cog." msgstr "" #: includes/settings/class-alg-wc-cog-settings-advanced.php:104 -msgid "Costs update hooks" +msgid "Order calculation hooks" msgstr "" #: includes/settings/class-alg-wc-cog-settings-advanced.php:105 -msgid "Hooks from new orders that will trigger cost update." +msgid "Hooks that will update order cost/profit calculation." msgstr "" #: includes/settings/class-alg-wc-cog-settings-advanced.php:113 -msgid "Metadata" +msgid "Order metadata" msgstr "" #: includes/settings/class-alg-wc-cog-settings-advanced.php:114 diff --git a/readme.txt b/readme.txt index b1caf3c..cf3d9e3 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: wpcodefactory, omardabbas, karzin, anbinder, algoritmika, kousikmu Tags: woocommerce, cost, cost of goods, profit, profit calculator Requires at least: 6.1 Tested up to: 6.5 -Stable tag: 3.4.0 +Stable tag: 3.4.1 License: GNU General Public License v3.0 License URI: http://www.gnu.org/licenses/gpl-3.0.html @@ -344,6 +344,12 @@ Once activated, access the plugin's settings by navigating to “WooCommerce > S == Changelog == += 3.4.1 - 15/05/2024 = +* Fix - Advanced - Change option title from "Costs update hooks" to "Order calculation hooks". +* Fix - Advanced - Change option title from "Metadata" to "Order metadata". +* Fix - Advanced - Change option title from "Force costs update" to "Order item costs". +* Dev - Advanced - Order calculation hooks - Add all order calculation hooks to the corresponding option making it possible to avoid order metas by leaving the option empty. + = 3.4.0 - 08/05/2024 = * Dev - Tools - Add a stock status filter to Bulk edit costs and prices.