This code snippet is a WordPress / WooCommerce function that hides the Unicredit payment method on the frontend of the website based on the user's capabilities. It goes into your theme's functions.php file.
/* https://websitefunctions.com */
function hide_payment_method_unicredit() {
if ( ! current_user_can( 'manage_options' ) ) {
echo '<style>.wc_payment_method.payment_method_unicredit { display: none !important; }</style>';
}
}
add_action( 'wp_head', 'hide_payment_method_unicredit' );
The function hide_payment_method_unicredit() is defined, and it checks if the current user has the capability to manage options. The current_user_can( 'manage_options' ) function checks if the user has the necessary permission. If the user does not have the 'manage_options' capability, it means they are not an administrator or a user with equivalent privileges.
Inside the if statement, an inline CSS style is echoed using echo. The CSS rule .wc_payment_method.payment_method_unicredit { display: none !important; } targets the HTML element with the class wc_payment_method and payment_method_unicredit and sets its display property to "none", effectively hiding it.
Finally, the add_action() function is used to hook the hide_payment_method_unicredit() function to the wp_head action, which means the function will be executed when the WordPress header is being generated.