From dad2533c19f5a2405366be9fead67eaab314ebed Mon Sep 17 00:00:00 2001 From: Pablo Pacheco Date: Fri, 18 Aug 2023 20:14:16 -0300 Subject: [PATCH] v3.0.3 --- cost-of-goods-for-woocommerce.php | 257 +------------- includes/class-alg-wc-cog-orders.php | 11 +- includes/class-alg-wc-cog.php | 325 ++++++++++++++++++ .../class-alg-wc-cog-settings-orders.php | 2 +- langs/cost-of-goods-for-woocommerce.pot | 42 +-- readme.txt | 10 +- 6 files changed, 375 insertions(+), 272 deletions(-) create mode 100644 includes/class-alg-wc-cog.php diff --git a/cost-of-goods-for-woocommerce.php b/cost-of-goods-for-woocommerce.php index e0f7bad..8629d38 100644 --- a/cost-of-goods-for-woocommerce.php +++ b/cost-of-goods-for-woocommerce.php @@ -3,18 +3,20 @@ 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.0.2 +Version: 3.0.3 Author: WPFactory Author URI: https://wpfactory.com Text Domain: cost-of-goods-for-woocommerce Domain Path: /langs Copyright: © 2023 WPFactory -WC tested up to: 7.9 +WC tested up to: 8.0 License: GNU General Public License v3.0 License URI: http://www.gnu.org/licenses/gpl-3.0.html */ -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly +if ( ! defined( 'ABSPATH' ) ) { + exit; +} // Exit if accessed directly if ( ! function_exists( 'alg_wc_cog_is_plugin_active' ) ) { /** @@ -38,6 +40,10 @@ function alg_wc_cog_is_plugin_active( $plugin ) { ! alg_wc_cog_is_plugin_active( 'woocommerce/woocommerce.php' ) || ( 'cost-of-goods-for-woocommerce.php' === basename( __FILE__ ) && alg_wc_cog_is_plugin_active( 'cost-of-goods-for-woocommerce-pro/cost-of-goods-for-woocommerce-pro.php' ) ) ) { + if ( function_exists( 'alg_wc_cog' ) ) { + $cog = alg_wc_cog(); + $cog->set_free_version_filesystem_path( __FILE__ ); + } return; } @@ -46,249 +52,7 @@ function alg_wc_cog_is_plugin_active( $plugin ) { require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php'; } -if ( ! class_exists( 'Alg_WC_Cost_of_Goods' ) ) : - -/** - * Main Alg_WC_Cost_of_Goods Class - * - * @class Alg_WC_Cost_of_Goods - * @version 2.1.0 - * @since 1.0.0 - */ -final class Alg_WC_Cost_of_Goods { - - /** - * Pro. - * - * @since 2.9.4 - * - * @var Alg_WC_Cost_of_Goods_Pro - */ - public $pro; - - /** - * Plugin version. - * - * @var string - * @since 1.0.0 - */ - public $version = '3.0.2'; - - /** - * @var Alg_WC_Cost_of_Goods The single instance of the class - * @since 1.0.0 - */ - protected static $_instance = null; - - /** - * Core. - * - * @since 2.9.4 - * - * @var Alg_WC_Cost_of_Goods_Core - */ - public $core; - - /** - * Main Alg_WC_Cost_of_Goods Instance - * - * Ensures only one instance of Alg_WC_Cost_of_Goods is loaded or can be loaded. - * - * @version 1.0.0 - * @since 1.0.0 - * @static - * @return Alg_WC_Cost_of_Goods - Main instance - */ - public static function instance() { - if ( is_null( self::$_instance ) ) { - self::$_instance = new self(); - } - return self::$_instance; - } - - /** - * Initializes. - * - * @version 3.0.2 - * @since 2.8.1 - */ - function init(){ - // Localization - add_action( 'init', array( $this, 'localize' ) ); - - // Declare compatibility with custom order tables for WooCommerce - add_action( 'before_woocommerce_init', array( $this, 'declare_compatibility_with_hpos' ) ); - - // Pro - if ( 'cost-of-goods-for-woocommerce-pro.php' === basename( __FILE__ ) ) { - $this->pro = require_once( 'includes/pro/class-alg-wc-cog-pro.php' ); - } - - // Include required files - $this->includes(); - - // Admin - if ( is_admin() ) { - $this->admin(); - } - - // Generate documentation - add_filter( 'wpfpdh_documentation_params_' . plugin_basename( $this->get_filesystem_path() ), array( $this, 'handle_documentation_params' ), 10 ); - } - - /** - * Handle documentation params managed by the WP Factory - * - * @version 2.4.3 - * @since 2.4.3 - * - * @param $params - * - * @return mixed - */ - function handle_documentation_params( $params ) { - $params['wc_tab_id'] = 'alg_wc_cost_of_goods'; - $params['pro_settings_filter'] = 'alg_wc_cog_settings'; - return $params; - } - - /** - * localize. - * - * @version 2.3.3 - * @since 2.3.3 - * - */ - function localize() { - // Set up localisation - load_plugin_textdomain( 'cost-of-goods-for-woocommerce', false, dirname( plugin_basename( __FILE__ ) ) . '/langs/' ); - } - - /** - * declare_compatibility_with_hpos. - * - * @version 3.0.2 - * @since 3.0.2 - * - * @see https://github.com/woocommerce/woocommerce/wiki/High-Performance-Order-Storage-Upgrade-Recipe-Book#declaring-extension-incompatibility - */ - function declare_compatibility_with_hpos() { - if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) { - \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true ); - } - } - - /** - * Include required core files used in admin and on the frontend. - * - * @version 2.1.0 - * @since 1.0.0 - */ - function includes() { - // Functions - require_once( 'includes/alg-wc-cog-functions.php' ); - // Core - $this->core = require_once( 'includes/class-alg-wc-cog-core.php' ); - } - - /** - * admin. - * - * @version 1.4.1 - * @since 1.1.0 - */ - function admin() { - // Action links - add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'action_links' ) ); - // Settings - add_filter( 'woocommerce_get_settings_pages', array( $this, 'add_woocommerce_settings_tab' ) ); - // Version update - if ( get_option( 'alg_wc_cog_version', '' ) !== $this->version ) { - add_action( 'admin_init', array( $this, 'version_updated' ) ); - } - } - - /** - * Show action links on the plugin screen. - * - * @version 2.6.3 - * @since 1.0.0 - * @param mixed $links - * @return array - */ - function action_links( $links ) { - $custom_links = array(); - $custom_links[] = '' . __( 'Settings', 'woocommerce' ) . ''; - if ( 'cost-of-goods-for-woocommerce.php' === basename( __FILE__ ) ) { - $custom_links[] = '' . - __( 'Go Pro', 'cost-of-goods-for-woocommerce' ) . ''; - } - $custom_links[] = '' . __( 'Bulk edit costs', 'woocommerce' ) . ''; - $custom_links[] = '' . __( 'Bulk edit prices', 'woocommerce' ) . ''; - return array_merge( $custom_links, $links ); - } - - /** - * Add Cost of Goods settings tab to WooCommerce settings. - * - * @version 2.3.4 - * @since 1.0.0 - */ - function add_woocommerce_settings_tab( $settings ) { - if ( ! apply_filters( 'alg_wc_cog_create_wc_settings_tab_validation', true ) ) { - return $settings; - } - $settings[] = require_once( 'includes/settings/class-alg-wc-settings-cog.php' ); - return $settings; - } - - /** - * version_updated. - * - * @version 1.1.0 - * @since 1.1.0 - */ - function version_updated() { - update_option( 'alg_wc_cog_version', $this->version ); - } - - /** - * Get the plugin url. - * - * @version 1.0.0 - * @since 1.0.0 - * @return string - */ - function plugin_url() { - return untrailingslashit( plugin_dir_url( __FILE__ ) ); - } - - /** - * Get the plugin path. - * - * @version 1.0.0 - * @since 1.0.0 - * @return string - */ - function plugin_path() { - return untrailingslashit( plugin_dir_path( __FILE__ ) ); - } - - /** - * get_filesystem_path. - * - * @version 2.4.3 - * @since 2.4.3 - * - * @return string - */ - function get_filesystem_path(){ - return __FILE__; - } - -} - -endif; +require_once( 'includes/class-alg-wc-cog.php' ); if ( ! function_exists( 'alg_wc_cog' ) ) { /** @@ -306,6 +70,7 @@ function alg_wc_cog() { // Initializes the plugin. add_action( 'plugins_loaded', function () { $cog = alg_wc_cog(); + $cog->set_filesystem_path( __FILE__ ); $cog->init(); } ); diff --git a/includes/class-alg-wc-cog-orders.php b/includes/class-alg-wc-cog-orders.php index 82b1f0f..f938208 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.0.2 + * @version 3.0.3 * @since 2.1.0 * @author WPFactory */ @@ -227,6 +227,13 @@ class Alg_WC_Cost_of_Goods_Orders { */ public $column_order_status; + /** + * Order columns. + * + * @since 3.0.3. + */ + public $order_columns; + /** * Is columns sorting. * @@ -710,7 +717,7 @@ function shop_order_sortable_columns( $columns ) { * * @version 2.1.0 * @since 1.7.0 - * + * * @todo Most probably we can remove this after HPOS is officially released. * */ diff --git a/includes/class-alg-wc-cog.php b/includes/class-alg-wc-cog.php new file mode 100644 index 0000000..e54652b --- /dev/null +++ b/includes/class-alg-wc-cog.php @@ -0,0 +1,325 @@ +declare_compatibility_with_hpos( $this->get_filesystem_path() ); + if ( ! empty( $this->get_free_version_filesystem_path() ) ) { + $this->declare_compatibility_with_hpos( $this->get_free_version_filesystem_path() ); + } + } ); + + // Pro + if ( 'cost-of-goods-for-woocommerce-pro.php' === basename( $this->get_filesystem_path() ) ) { + $this->pro = require_once( 'pro/class-alg-wc-cog-pro.php' ); + } + + // Include required files + $this->includes(); + + // Admin + if ( is_admin() ) { + $this->admin(); + } + + // Generate documentation + add_filter( 'wpfpdh_documentation_params_' . plugin_basename( $this->get_filesystem_path() ), array( + $this, + 'handle_documentation_params' + ), 10 ); + } + + /** + * Declare compatibility with custom order tables for WooCommerce. + * + * @version 3.0.3 + * @since 3.0.2 + * + * @param $filesystem_path + * + * @return void + * @link https://github.com/woocommerce/woocommerce/wiki/High-Performance-Order-Storage-Upgrade-Recipe-Book#declaring-extension-incompatibility + * + */ + function declare_compatibility_with_hpos( $filesystem_path ) { + if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) { + \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', $filesystem_path, true ); + } + } + + /** + * Handle documentation params managed by the WP Factory + * + * @version 2.4.3 + * @since 2.4.3 + * + * @param $params + * + * @return mixed + */ + function handle_documentation_params( $params ) { + $params['wc_tab_id'] = 'alg_wc_cost_of_goods'; + $params['pro_settings_filter'] = 'alg_wc_cog_settings'; + + return $params; + } + + /** + * localize. + * + * @version 3.0.3 + * @since 2.3.3 + * + */ + function localize() { + // Set up localisation + load_plugin_textdomain( 'cost-of-goods-for-woocommerce', false, dirname( plugin_basename( $this->get_filesystem_path() ) ) . '/langs/' ); + } + + /** + * Include required core files used in admin and on the frontend. + * + * @version 3.0.3 + * @since 1.0.0 + */ + function includes() { + // Functions + require_once( 'alg-wc-cog-functions.php' ); + // Core + $this->core = require_once( 'class-alg-wc-cog-core.php' ); + } + + /** + * admin. + * + * @version 3.0.3 + * @since 1.1.0 + */ + function admin() { + // Action links + add_filter( 'plugin_action_links_' . plugin_basename( $this->get_filesystem_path() ), array( + $this, + 'action_links' + ) ); + // Settings + add_filter( 'woocommerce_get_settings_pages', array( $this, 'add_woocommerce_settings_tab' ) ); + // Version update + if ( get_option( 'alg_wc_cog_version', '' ) !== $this->version ) { + add_action( 'admin_init', array( $this, 'version_updated' ) ); + } + } + + /** + * Show action links on the plugin screen. + * + * @version 3.0.3 + * @since 1.0.0 + * + * @param mixed $links + * + * @return array + */ + function action_links( $links ) { + $custom_links = array(); + $custom_links[] = '' . __( 'Settings', 'woocommerce' ) . ''; + if ( 'cost-of-goods-for-woocommerce.php' === basename( $this->get_filesystem_path() ) ) { + $custom_links[] = '' . + __( 'Go Pro', 'cost-of-goods-for-woocommerce' ) . ''; + } + $custom_links[] = '' . __( 'Bulk edit costs', 'woocommerce' ) . ''; + $custom_links[] = '' . __( 'Bulk edit prices', 'woocommerce' ) . ''; + + return array_merge( $custom_links, $links ); + } + + /** + * Add Cost of Goods settings tab to WooCommerce settings. + * + * @version 3.0.3 + * @since 1.0.0 + */ + function add_woocommerce_settings_tab( $settings ) { + if ( ! apply_filters( 'alg_wc_cog_create_wc_settings_tab_validation', true ) ) { + return $settings; + } + $settings[] = require_once( 'settings/class-alg-wc-settings-cog.php' ); + + return $settings; + } + + /** + * version_updated. + * + * @version 1.1.0 + * @since 1.1.0 + */ + function version_updated() { + update_option( 'alg_wc_cog_version', $this->version ); + } + + /** + * Get the plugin url. + * + * @version 3.0.3 + * @since 1.0.0 + * @return string + */ + function plugin_url() { + return untrailingslashit( plugin_dir_url( $this->get_filesystem_path() ) ); + } + + /** + * Get the plugin path. + * + * @version 3.0.3 + * @since 1.0.0 + * @return string + */ + function plugin_path() { + return untrailingslashit( plugin_dir_path( $this->get_filesystem_path() ) ); + } + + /** + * get_filesystem_path. + * + * @version 3.0.3 + * @since 2.4.3 + * + * @return string + */ + function get_filesystem_path() { + return $this->file_system_path; + } + + /** + * set_filesystem_path. + * + * @version 3.0.3 + * @since 3.0.3 + * + * @param mixed $file_system_path + */ + public function set_filesystem_path( $file_system_path ) { + $this->file_system_path = $file_system_path; + } + + /** + * get_free_version_filesystem_path. + * + * @version 3.0.3 + * @since 3.0.3 + * + * @return mixed + */ + public function get_free_version_filesystem_path() { + return $this->free_version_file_system_path; + } + + /** + * set_free_version_filesystem_path. + * + * @version 3.0.3 + * @since 3.0.3 + * + * @param mixed $free_version_file_system_path + */ + public function set_free_version_filesystem_path( $free_version_file_system_path ) { + $this->free_version_file_system_path = $free_version_file_system_path; + } + + } + +endif; \ No newline at end of file diff --git a/includes/settings/class-alg-wc-cog-settings-orders.php b/includes/settings/class-alg-wc-cog-settings-orders.php index 7f8fd38..ed9525f 100644 --- a/includes/settings/class-alg-wc-cog-settings-orders.php +++ b/includes/settings/class-alg-wc-cog-settings-orders.php @@ -239,7 +239,7 @@ function get_settings() { $order_calculation_settings = array( array( 'title' => __( 'Calculations', 'cost-of-goods-for-woocommerce' ), - 'desc' => __( 'Define options for order cost and profit calc ulations.', 'cost-of-goods-for-woocommerce' ) . ' ' . + 'desc' => __( 'Define options for order cost and profit calculations.', 'cost-of-goods-for-woocommerce' ) . ' ' . __( "You will need to recalculate order's cost and profit after you change these settings.", 'cost-of-goods-for-woocommerce' ), 'type' => 'title', 'id' => 'alg_wc_cog_order_calculation_options', diff --git a/langs/cost-of-goods-for-woocommerce.pot b/langs/cost-of-goods-for-woocommerce.pot index 475fde8..d88dd4a 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.0.2\n" +"Project-Id-Version: cost-of-goods-for-woocommerce 3.0.3\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: 2023-07-29T00:38:21+02:00\n" +"POT-Creation-Date: 2023-08-19T01:12:20+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" @@ -36,10 +36,6 @@ msgstr "" msgid "https://wpfactory.com" msgstr "" -#: cost-of-goods-for-woocommerce-pro.php:224 -msgid "Go Pro" -msgstr "" - #: includes/alg-wc-cog-functions.php:218 msgid "Disabled options can be unlocked using %s" msgstr "" @@ -78,8 +74,8 @@ msgstr "" #: includes/analytics/class-alg-wc-cog-analytics-revenue.php:47 #: includes/analytics/class-alg-wc-cog-analytics-stock.php:88 #: includes/class-alg-wc-cog-orders-meta-boxes.php:148 -#: includes/class-alg-wc-cog-orders.php:670 -#: includes/class-alg-wc-cog-orders.php:780 +#: includes/class-alg-wc-cog-orders.php:677 +#: includes/class-alg-wc-cog-orders.php:787 #: includes/class-alg-wc-cog-products-add-stock.php:124 #: includes/class-alg-wc-cog-products-add-stock.php:141 #: includes/class-alg-wc-cog-products.php:248 @@ -103,8 +99,8 @@ msgstr "" #: includes/analytics/class-alg-wc-cog-analytics-revenue.php:48 #: includes/analytics/class-alg-wc-cog-analytics-stock.php:89 #: includes/class-alg-wc-cog-orders-meta-boxes.php:149 -#: includes/class-alg-wc-cog-orders.php:671 -#: includes/class-alg-wc-cog-orders.php:790 +#: includes/class-alg-wc-cog-orders.php:678 +#: includes/class-alg-wc-cog-orders.php:797 #: includes/class-alg-wc-cog-products.php:330 #: includes/pro/reports/class-wc-report-alg-cog-stock.php:123 #: includes/tools/class-alg-wc-cog-bulk-edit-tool.php:391 @@ -247,51 +243,51 @@ msgstr "" msgid "fee" msgstr "" -#: includes/class-alg-wc-cog-orders.php:306 +#: includes/class-alg-wc-cog-orders.php:313 #: includes/settings/class-alg-wc-cog-settings-orders.php:180 msgid "You are selling below the cost of goods." msgstr "" -#: includes/class-alg-wc-cog-orders.php:478 +#: includes/class-alg-wc-cog-orders.php:485 #: includes/settings/class-alg-wc-cog-settings-orders.php:295 #: includes/settings/class-alg-wc-cog-settings-tools.php:360 msgid "Taxes to profit" msgstr "" -#: includes/class-alg-wc-cog-orders.php:517 +#: includes/class-alg-wc-cog-orders.php:524 #: includes/settings/class-alg-wc-cog-settings-orders.php:288 #: includes/settings/class-alg-wc-cog-settings-tools.php:359 msgid "Fees to profit" msgstr "" -#: includes/class-alg-wc-cog-orders.php:557 +#: includes/class-alg-wc-cog-orders.php:564 #: includes/settings/class-alg-wc-cog-settings-orders.php:274 #: includes/settings/class-alg-wc-cog-settings-tools.php:358 msgid "Shipping to profit" msgstr "" -#: includes/class-alg-wc-cog-orders.php:559 +#: includes/class-alg-wc-cog-orders.php:566 msgid "Shipping to profit (%s)" msgstr "" -#: includes/class-alg-wc-cog-orders.php:674 -#: includes/class-alg-wc-cog-orders.php:1129 +#: includes/class-alg-wc-cog-orders.php:681 +#: includes/class-alg-wc-cog-orders.php:1136 #: includes/pro/class-alg-wc-cog-pro.php:623 #: includes/pro/class-alg-wc-cog-pro.php:642 msgid "Cost of goods" msgstr "" -#: includes/class-alg-wc-cog-orders.php:793 +#: includes/class-alg-wc-cog-orders.php:800 #: includes/settings/class-alg-wc-cog-settings-orders.php:48 msgid "Profit percent" msgstr "" -#: includes/class-alg-wc-cog-orders.php:796 +#: includes/class-alg-wc-cog-orders.php:803 #: includes/settings/class-alg-wc-cog-settings-orders.php:48 msgid "Profit margin" msgstr "" -#: includes/class-alg-wc-cog-orders.php:1165 +#: includes/class-alg-wc-cog-orders.php:1172 msgid "Handling Fee" msgstr "" @@ -359,6 +355,10 @@ msgstr "" msgid "New cost" msgstr "" +#: includes/class-alg-wc-cog.php:220 +msgid "Go Pro" +msgstr "" + #: includes/pro/class-alg-wc-cog-pro-extra-currencies-costs.php:54 #: includes/settings/class-alg-wc-cog-settings-currencies.php:95 #: includes/settings/class-alg-wc-cog-settings-currencies.php:101 @@ -1414,7 +1414,7 @@ msgid "Calculations" msgstr "" #: includes/settings/class-alg-wc-cog-settings-orders.php:242 -msgid "Define options for order cost and profit calc ulations." +msgid "Define options for order cost and profit calculations." msgstr "" #: includes/settings/class-alg-wc-cog-settings-orders.php:248 diff --git a/readme.txt b/readme.txt index 758b1db..0beca61 100644 --- a/readme.txt +++ b/readme.txt @@ -2,8 +2,8 @@ Contributors: wpcodefactory, karzin, kerbhavik, jaedm97, algoritmika, anbinder, omardabbas, kousikmukherjeeli Tags: woocommerce, cost, cost of goods, cog, cost of goods sold, cogs, woo commerce Requires at least: 4.4 -Tested up to: 6.2 -Stable tag: 3.0.2 +Tested up to: 6.3 +Stable tag: 3.0.3 License: GNU General Public License v3.0 License URI: http://www.gnu.org/licenses/gpl-3.0.html @@ -98,6 +98,12 @@ And then you can follow these steps: == Changelog == += 3.0.3 - 18/08/2023 = +* Fix - Undefined property: `Alg_WC_Cost_of_Goods_Orders::$order_columns`. +* Dev - Move main class to a separate file. +* Tested up to: 6.3. +* WC tested up to: 8.0. + = 3.0.2 - 28/07/2023 = * Dev - Add compatibility with HPOS. * WC tested up to: 7.9.