Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kimcoleman/7100c786d16f88b20e00c68ab48f1549 to your computer and use it in GitHub Desktop.
Save kimcoleman/7100c786d16f88b20e00c68ab48f1549 to your computer and use it in GitHub Desktop.
<?php
/**
* Add custom card classes to the Terms of Service (TOS) field in PMPro checkout.
*
* This function uses the 'pmpro_element_class' filter to add custom classes
* to the TOS fieldset, form fields, and other elements within the TOS area.
*
* @param array $class Array of element class names.
* @param string $element The element to return class names for.
*
* @return array Modified array of class names.
*/
function my_pmpro_add_tos_card_classes( $class, $element ) {
// Add 'pmpro_card' class to the fieldset for the TOS fields.
if ( $element === 'pmpro_tos_fields' ) {
$class[] = 'pmpro_card';
}
// Add 'pmpro_card_content' class to the form fields within the TOS fieldset.
if ( $element === 'pmpro_form_fields' ) {
$class[] = 'pmpro_card_content';
}
return $class;
}
add_filter( 'pmpro_element_class', 'my_pmpro_add_tos_card_classes', 10, 2 );
@a-grealish
Copy link

I modified this slightly as this version would apply the pmpro_card_contents to other cards as well as the tos element. My php is not great, but this seemed to work:

/**
 * Add custom card classes to the Terms of Service (TOS) field in PMPro checkout.
 *
 * This function uses the 'pmpro_element_class' filter to add custom classes 
 * to the TOS fieldset, form fields, and other elements within the TOS area.
 *
 * @param array  $class   Array of element class names.
 * @param string $element The element to return class names for.
 * 
 * @return array Modified array of class names.
 */
function my_pmpro_add_tos_card_classes( $class, $element ) {
    static $in_tos_section = false;

    if ( $element === 'pmpro_tos_fields' ) {
        $in_tos_section = true;
        $class[] = 'pmpro_card';
    }

    if ( $element === 'pmpro_form_fields' && $in_tos_section ) {
        $class[] = 'pmpro_card_content';
        $in_tos_section = false;
    }

    return $class;
}

add_filter( 'pmpro_element_class', 'my_pmpro_add_tos_card_classes', 10, 2 );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment