From 7dc233333af2e3c5a824563996ff973f4827e4b0 Mon Sep 17 00:00:00 2001 From: WP Date: Tue, 18 Apr 2023 00:34:26 -0300 Subject: [PATCH] v2.9.6 --- cost-of-goods-for-woocommerce.php | 6 ++--- includes/class-alg-wc-cog-products.php | 31 ++++++++++++++----------- langs/cost-of-goods-for-woocommerce.pot | 4 ++-- readme.txt | 6 ++++- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/cost-of-goods-for-woocommerce.php b/cost-of-goods-for-woocommerce.php index 58fe5e0..8fb20d0 100644 --- a/cost-of-goods-for-woocommerce.php +++ b/cost-of-goods-for-woocommerce.php @@ -3,13 +3,13 @@ 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: 2.9.5 +Version: 2.9.6 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.5 +WC tested up to: 7.6 License: GNU General Public License v3.0 License URI: http://www.gnu.org/licenses/gpl-3.0.html */ @@ -72,7 +72,7 @@ final class Alg_WC_Cost_of_Goods { * @var string * @since 1.0.0 */ - public $version = '2.9.5'; + public $version = '2.9.6'; /** * @var Alg_WC_Cost_of_Goods The single instance of the class diff --git a/includes/class-alg-wc-cog-products.php b/includes/class-alg-wc-cog-products.php index ca81ea6..49e2603 100644 --- a/includes/class-alg-wc-cog-products.php +++ b/includes/class-alg-wc-cog-products.php @@ -2,7 +2,7 @@ /** * Cost of Goods for WooCommerce - Products Class. * - * @version 2.9.5 + * @version 2.9.6 * @since 2.1.0 * @author WPFactory */ @@ -451,24 +451,29 @@ function get_product_profit( $product_id ) { /** * get_product_profit_html. * - * @version 2.3.9 + * @version 2.9.6 * @since 1.0.0 */ function get_product_profit_html( $product_id, $template = '%profit% (%profit_percent%)' ) { $product = wc_get_product( $product_id ); - if ( $product->is_type( 'variable' ) ) { - return $this->get_variable_product_html( $product_id, 'profit', $template ); - } else { - if ( '' === ( $profit = $this->get_product_profit( $product_id ) ) ) { - return ''; + if ( is_a( $product, 'WC_Product' ) ) { + if ( $product->is_type( 'variable' ) ) { + return $this->get_variable_product_html( $product_id, 'profit', $template ); } else { - $placeholders = array( - '%profit%' => wc_price( $profit ), - '%profit_percent%' => sprintf( '%0.2f%%', ( 0 != ( $cost = $this->get_product_cost( $product_id ) ) ? $profit / $cost * 100 : '' ) ), - '%profit_margin%' => sprintf( '%0.2f%%', ( 0 != ( $price = $this->get_product_price( $product ) ) ? $profit / $price * 100 : '' ) ), - ); - return str_replace( array_keys( $placeholders ), $placeholders, $template ); + if ( '' === ( $profit = $this->get_product_profit( $product_id ) ) ) { + return ''; + } else { + $placeholders = array( + '%profit%' => wc_price( $profit ), + '%profit_percent%' => sprintf( '%0.2f%%', ( 0 != ( $cost = $this->get_product_cost( $product_id ) ) ? $profit / $cost * 100 : '' ) ), + '%profit_margin%' => sprintf( '%0.2f%%', ( 0 != ( $price = $this->get_product_price( $product ) ) ? $profit / $price * 100 : '' ) ), + ); + + return str_replace( array_keys( $placeholders ), $placeholders, $template ); + } } + } else { + return ''; } } diff --git a/langs/cost-of-goods-for-woocommerce.pot b/langs/cost-of-goods-for-woocommerce.pot index 11e5e9d..6e3f8aa 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 2.9.5\n" +"Project-Id-Version: cost-of-goods-for-woocommerce 2.9.6\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-04-18T02:21:50+02:00\n" +"POT-Creation-Date: 2023-04-18T05:33:59+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" diff --git a/readme.txt b/readme.txt index 1e54971..8976d3a 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: wpcodefactory, karzin, kerbhavik, jaedm97, algoritmika, anbinder 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: 2.9.5 +Stable tag: 2.9.6 License: GNU General Public License v3.0 License URI: http://www.gnu.org/licenses/gpl-3.0.html @@ -98,6 +98,10 @@ And then you can follow these steps: == Changelog == += 2.9.6 - 18/04/2023 = +* Fix - `class-alg-wc-cog-products.php:456` - Call to a member function is_type() on bool. +* WC tested up to: 7.6. + = 2.9.5 - 17/04/2023 = * Fix - Products - Cost archive - New price column doesn't take decimals into account. * Dev - Tools - Bulk edit costs - New option: Filter by cost, allowing to select only products with no costs or with costs.