Skip to content

Commit

Permalink
v3.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
pablo-sg-pacheco committed Aug 18, 2023
1 parent 29136fa commit dad2533
Show file tree
Hide file tree
Showing 6 changed files with 375 additions and 272 deletions.
257 changes: 11 additions & 246 deletions cost-of-goods-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) ) {
/**
Expand All @@ -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;
}

Expand All @@ -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[] = '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=alg_wc_cost_of_goods' ) . '">' . __( 'Settings', 'woocommerce' ) . '</a>';
if ( 'cost-of-goods-for-woocommerce.php' === basename( __FILE__ ) ) {
$custom_links[] = '<a target="_blank" style="font-weight: bold; color: green;" href="https://wpfactory.com/item/cost-of-goods-for-woocommerce/">' .
__( 'Go Pro', 'cost-of-goods-for-woocommerce' ) . '</a>';
}
$custom_links[] = '<a href="' . admin_url( 'tools.php?page=bulk-edit-costs' ) . '">' . __( 'Bulk edit costs', 'woocommerce' ) . '</a>';
$custom_links[] = '<a href="' . admin_url( 'tools.php?page=bulk-edit-prices' ) . '">' . __( 'Bulk edit prices', 'woocommerce' ) . '</a>';
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' ) ) {
/**
Expand All @@ -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();
} );

Expand Down
11 changes: 9 additions & 2 deletions includes/class-alg-wc-cog-orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
*/
Expand Down
Loading

0 comments on commit dad2533

Please sign in to comment.