Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Get pmpro-woocommerce global variables from the main blog. #197

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions pmpro-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,73 @@ function pmprowoo_init() {
}
add_action( 'init', 'pmprowoo_init' );

function pmprowoo_gobals_subsite() {
andrewlimaza marked this conversation as resolved.
Show resolved Hide resolved

// 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
*
Expand Down