Hide Account Funds Top Up in My Account from WooCommerce 'Customer' Role
An easy way to disable/hide the topup form is by copying the "Account Funds" template (myaccount/account-funds.php
) from the plugin folder to your theme folder — i.e. copy this file:
wp-content/plugins/woocommerce-account-funds/templates/myaccount/account-funds.php
to:
wp-content/themes/your-theme/woocommerce/myaccount/account-funds.php
And then find and change the following:
<?php echo $topup; ?>
to:
<?php// If the current user is **not** a "customer", show the topup form.if ( ! current_user_can( 'customer' ) ) { echo $topup;}?>
See full code here. (for "WooCommerce Account Funds" version 2.1.16)
You could also instead edit the topup form template itself (myaccount/topup-form.php
) like this.
And I'd also add this to the theme functions file:
// If the user is a "customer", bypass the action which handles top-ups.add_action( 'wp', function(){ if ( isset( $_POST['wc_account_funds_topup'] ) && current_user_can( 'customer' ) ) { unset( $_POST['wc_account_funds_topup'] ); }}, 0 );