Skip to content

Commit

Permalink
v2.9.9
Browse files Browse the repository at this point in the history
  • Loading branch information
kousikmukherjee committed May 25, 2023
1 parent ee6fbbf commit 08e1338
Show file tree
Hide file tree
Showing 4 changed files with 1,285 additions and 1,039 deletions.
4 changes: 2 additions & 2 deletions cost-of-goods-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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: 2.9.8
Version: 2.9.9
Author: WPFactory
Author URI: https://wpfactory.com
Text Domain: cost-of-goods-for-woocommerce
Expand Down Expand Up @@ -72,7 +72,7 @@ final class Alg_WC_Cost_of_Goods {
* @var string
* @since 1.0.0
*/
public $version = '2.9.8';
public $version = '2.9.9';

/**
* @var Alg_WC_Cost_of_Goods The single instance of the class
Expand Down
16 changes: 15 additions & 1 deletion includes/class-alg-wc-cog-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ function get_product_handling_fee( $product_id, $args = null ) {
/**
* get_product_price.
*
* @version 2.5.2
* @version 2.9.9
* @since 2.3.9
*
* @param $product
Expand All @@ -411,6 +411,19 @@ function get_product_handling_fee( $product_id, $args = null ) {
* @return mixed
*/
function get_product_price( $product, $args = null ) {

// Check if $product is a valid product object. If not, try loading it.
if ( !( $product instanceof WC_Product ) ) {
$product_id = $product;
$product = wc_get_product( $product_id );

// If it's still not a valid product object, log an error and return false
if ( !( $product instanceof WC_Product ) ) {
error_log( "Invalid product ID: $product_id" );
return false; // or you might return a default value instead
}
}

$args = wp_parse_args( $args, array(
'method' => get_option( 'alg_wc_cog_products_get_price_method', 'wc_get_price_excluding_tax' ),
'params' => array(),
Expand All @@ -419,6 +432,7 @@ function get_product_price( $product, $args = null ) {
$params = array_merge( array( $product ), $args['params'] );
$return = call_user_func_array( $args['method'], $params );
return $args['return_zero_if_empty'] && empty( $return ) ? 0 : (float) $return;

}

/**
Expand Down
Loading

0 comments on commit 08e1338

Please sign in to comment.