From c9d2546a3da164a70d6c7eb5fdbcb1122ec57397 Mon Sep 17 00:00:00 2001 From: Theuns Coetzee Date: Fri, 15 Sep 2023 22:22:18 +0200 Subject: [PATCH 1/3] Enhancement: Get pmprowoo globals from main blog. --- pmpro-woocommerce.php | 67 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/pmpro-woocommerce.php b/pmpro-woocommerce.php index 3093721..111f218 100644 --- a/pmpro-woocommerce.php +++ b/pmpro-woocommerce.php @@ -64,6 +64,73 @@ function pmprowoo_init() { } add_action( 'init', 'pmprowoo_init' ); +function pmprowoo_gobals_subsite() { + + // Let's only do this in a multisite environment if we're not on the main site. + if ( ! is_multisite() || is_main_site() ) { + return; + } + + // Is PMPro network subsite installed? + if ( ! function_exists( 'pmpro_multisite_membership_init' ) ) { + return; + } + + // Is the WooCommerce integration active? + if ( ! function_exists( 'pmprowoo_init' ) ) { + return; + } + + // Let's make sure these plugins are not network activated. + $subsite_only_plugins = array( + 'pmpro-network-subsite', + 'pmpro-woocommerce', + ); + + foreach ( $subsite_only_plugins as $plugin ) { + if ( is_plugin_active_for_network( $plugin . '/' . $plugin . '.php' ) ) { + return; + } + } + global $pmprowoo_product_levels, $pmprowoo_gift_codes, $pmprowoo_member_discounts, $pmprowoo_discounts_on_subscriptions; + + // Get the main site ID. + $main_site_id = get_main_site_id(); + + // Get all Product Membership Levels + if ( empty( $pmprowoo_product_levels ) ) { + $pmprowoo_product_levels = get_blog_option( $main_site_id, '_pmprowoo_product_levels' ); + if ( empty( $pmprowoo_product_levels ) ) { + $pmprowoo_product_levels = array(); + } + } + + // Get all Gift Membership Codes + if ( empty( $pmprowoo_gift_codes ) ) { + $pmprowoo_gift_codes = get_blog_option( $main_site_id, '_pmprowoo_gift_codes' ); + if ( empty( $pmprowoo_gift_codes ) ) { + $pmprowoo_gift_codes = array(); + } + } + + // Get all Membership Discounts + if ( empty( $pmprowoo_member_discounts ) ) { + $pmprowoo_member_discounts = get_blog_option( $main_site_id, '_pmprowoo_member_discounts' ); + if ( empty( $pmprowoo_member_discounts ) ) { + $pmprowoo_member_discounts = array(); + } + } + + // Apply Discounts to Subscriptions + if ( empty( $pmprowoo_discounts_on_subscriptions ) ) { + $pmprowoo_discounts_on_subscriptions = get_blog_option( $main_site_id, '_pmprowoo_discounts_on_subscriptions' ); + if ( empty( $pmprowoo_discounts_on_subscriptions ) ) { + $pmprowoo_discounts_on_subscriptions = array(); + } + } +} +add_action( 'init', 'pmprowoo_gobals_subsite', 11 ); + /** * Disable other membership products if a membership product is in the cart already * From 64c906fd1d71f740c616cd3a92b125200c9f4680 Mon Sep 17 00:00:00 2001 From: Andrew Lima Date: Wed, 13 Mar 2024 08:35:52 +0200 Subject: [PATCH 2/3] Fix minor typo in function name --- pmpro-woocommerce.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pmpro-woocommerce.php b/pmpro-woocommerce.php index 111f218..34c7c87 100644 --- a/pmpro-woocommerce.php +++ b/pmpro-woocommerce.php @@ -64,7 +64,7 @@ function pmprowoo_init() { } add_action( 'init', 'pmprowoo_init' ); -function pmprowoo_gobals_subsite() { +function pmprowoo_globals_subsite() { // Let's only do this in a multisite environment if we're not on the main site. if ( ! is_multisite() || is_main_site() ) { @@ -129,7 +129,7 @@ function pmprowoo_gobals_subsite() { } } } -add_action( 'init', 'pmprowoo_gobals_subsite', 11 ); +add_action( 'init', 'pmprowoo_globals_subsite', 11 ); /** * Disable other membership products if a membership product is in the cart already @@ -1045,4 +1045,4 @@ function pmprowoo_compatible_for_hpos() { \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true ); } } -add_action( 'before_woocommerce_init', 'pmprowoo_compatible_for_hpos' ); \ No newline at end of file +add_action( 'before_woocommerce_init', 'pmprowoo_compatible_for_hpos' ); From 6ccc311aa16789ea5eeb9f368f1c913e1033f11c Mon Sep 17 00:00:00 2001 From: Andrew Lima Date: Mon, 8 Apr 2024 12:01:59 +0200 Subject: [PATCH 3/3] Move to compatibility file. --- includes/multisite.php | 82 ++++++++++++++++++++++++++++++++++++++++++ pmpro-woocommerce.php | 74 ++++---------------------------------- 2 files changed, 88 insertions(+), 68 deletions(-) create mode 100644 includes/multisite.php diff --git a/includes/multisite.php b/includes/multisite.php new file mode 100644 index 0000000..45361c7 --- /dev/null +++ b/includes/multisite.php @@ -0,0 +1,82 @@ +