Created
November 20, 2018 20:34
-
-
Save wpmudev-sls/9e195f8d545bb58bbdcfd9e5a0771a48 to your computer and use it in GitHub Desktop.
[Pro Sites] - Hides the second available gateway when the Monthly and Quarterly periods are selected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: [Pro Sites] - Gateways Per Period | |
* Plugin URI: https://premium.wpmudev.org/ | |
* Description: Hides the second available gateway when the Monthly and Quarterly periods are selected | |
* Author: Panos Lyrakis @ WPMUDEV | |
* Author URI: https://premium.wpmudev.org/ | |
* License: GPLv2 or later | |
*/ | |
add_action( 'wp_footer', function(){ | |
global $psts; | |
if ( ! is_page() || get_the_ID() != $psts->get_setting( 'checkout_page' ) ) { | |
return; | |
} | |
?> | |
<script type="text/javascript"> | |
(function($,d){ | |
var WPMUDEV_PS_Man_Gateways = { | |
ps_selector : '', | |
target_gateway : '', | |
neutral_gateway : '', | |
init : function(){ | |
this.ps_selector = $( '#prosites-checkout-table select.chosen' ); | |
this.target_gateway = $( '#gateways ul li:eq( 1 )' ); | |
this.neutral_gateway = $( '#gateways ul li:eq( 0 )' ); | |
WPMUDEV_PS_Man_Gateways.monitor_change(); | |
$(d).on( 'change', this.ps_selector, function(){ | |
WPMUDEV_PS_Man_Gateways.monitor_change(); | |
}); | |
$(d).ajaxComplete(function( event, xhr, settings ) { | |
const action = WPMUDEV_PS_Man_Gateways.get_action( 'action', settings.data ); | |
if( 'check_prosite_blog' === action ){ | |
WPMUDEV_PS_Man_Gateways.init(); | |
} | |
}); | |
}, | |
monitor_change : function() { | |
let val = this.ps_selector.val(); | |
if ( 'price_12' != val ) { | |
this.target_gateway.hide(); | |
if ( ! this.neutral_gateway.hasClass( 'ui-state-active' ) ) { | |
this.neutral_gateway.find( 'a' ).click(); | |
} | |
} | |
else { | |
this.target_gateway.show(); | |
} | |
}, | |
get_action: function( name, url ){ | |
if ( ! url ){ | |
return ''; | |
} | |
name = name.replace(/[\[\]]/g, "\\$&"); | |
var regex = new RegExp( name + "(=([^&#]*)|&|#|$)" ), | |
results = regex.exec( url ); | |
if ( ! results ) return null; | |
if ( ! results[2] ) return ''; | |
return decodeURIComponent( results[2].replace(/\+/g, " ") ); | |
} | |
}; | |
$(d).ready(function(){ | |
WPMUDEV_PS_Man_Gateways.init(); | |
}); | |
})(jQuery, document); | |
</script> | |
<?php | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment