Untitled

mail@pastecode.io avatar
unknown
php
2 years ago
802 B
3
Indexable
Never
<?php 
    function ml_validate_field_values( $value, $field, $modifier ) {
        //If not logged in add style
        if ( ! is_user_logged_in() ) {
            echo '<style type="text/css">.showbysub { display: none !important; }</style>';
        } else {
            //If logged in but does not has subscription with ID "916" add style
            if ( function_exists( 'wcs_user_has_subscription' ) ) {
                $has_active_subscription = wcs_user_has_subscription( get_current_user_id(), 916, 'active' );
                if ( ! $has_active_subscription ) {
                    echo '<style type="text/css">.showbysub { display: none !important; }</style>';
                }
            }
        }        
    }
    add_action( 'wp_head', 'ml_validate_field_values');
?>