Created
March 21, 2023 09:39
-
-
Save ipokkel/c91209ba50cc36250ccbbf601b3dad1c to your computer and use it in GitHub Desktop.
Show or hide (toggle) your check payment type user field group if the check payment option is selected. #pmpropbc #pmpro-pay-by-check
This file contains hidden or 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 | |
/** | |
* Toggle the Payment Type user field on the checkout page when using the Pay by Check gateway. | |
* The Payment Type field is moved to below the Choose Your Payment Method part on the checkout page. | |
* | |
* This is a partner recipe for the guide | |
* Let Users Select Offline Payment Methods Using the “Pay by Check” Gateway | |
* @link https://www.paidmembershipspro.com/let-users-select-offline-payment-methods-using-the-pay-by-check-gateway/ | |
* | |
* This recipe assumes the following: | |
* | |
* 1. You have already created a custom user field group that has the name Payment Type. | |
* 2. The group is set to display on the checkout page | |
* 3. You have already created a custom user field that has the name payment_type inside this group. | |
* 4. You have implemented the customization code recipe in the aforementioned guide. | |
* @link https://raw.githubusercontent.com/strangerstudios/pmpro-snippets-library/dev/checkout/select-offline-payment-type-check-gateway.php | |
* 5. The PMPro Pay By Check Add On is enabled. | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function toggle_payment_type_field_visibility_for_check() { | |
// Let's only do this if Pay By Check is active and we're on the checkout page. | |
if ( ! pmpro_is_checkout() || ! function_exists( 'pmpropbc_getOptions' ) ) { | |
return; | |
} | |
?> | |
<script> | |
jQuery(document).ready(function ($) { | |
"use strict"; | |
jQuery('#pmpro_checkout_box-payment-type').hide(); | |
$('#pmpro_payment_method input[type="radio"]').on('click change keyup', function () { | |
if ($(this).val() === 'check') { | |
$('#pmpro_checkout_box-payment-type').show(); | |
} else { | |
$('#pmpro_checkout_box-payment-type').hide(); | |
} | |
}); | |
}); | |
</script> | |
<?php | |
} | |
add_action( 'wp_footer', 'toggle_payment_type_field_visibility_for_check' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment