diff --git a/includes/class-wc-gateway-dummy.php b/includes/class-wc-gateway-dummy.php index b6c3a88..89ebddc 100644 --- a/includes/class-wc-gateway-dummy.php +++ b/includes/class-wc-gateway-dummy.php @@ -47,9 +47,10 @@ public function __construct() { $this->init_settings(); // Define user set variables. - $this->title = $this->get_option( 'title' ); - $this->description = $this->get_option( 'description' ); - $this->instructions = $this->get_option( 'instructions', $this->description ); + $this->title = $this->get_option( 'title' ); + $this->description = $this->get_option( 'description' ); + $this->instructions = $this->get_option( 'instructions', $this->description ); + $this->hide_for_non_admin_users = $this->get_option( 'hide_for_non_admin_users' ); // Actions. add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); @@ -66,7 +67,12 @@ public function init_form_fields() { 'title' => __( 'Enable/Disable', 'woocommerce-gateway-dummy' ), 'type' => 'checkbox', 'label' => __( 'Enable Dummy Payments', 'woocommerce-gateway-dummy' ), - 'default' => 'yes' + 'default' => 'yes', + ), + 'hide_for_non_admin_users' => array( + 'type' => 'checkbox', + 'label' => __( 'Hide at checkout for non-admin users', 'woocommerce-gateway-dummy' ), + 'default' => 'no', ), 'title' => array( 'title' => __( 'Title', 'woocommerce-gateway-dummy' ), diff --git a/woocommerce-gateway-dummy.php b/woocommerce-gateway-dummy.php index f7382e7..f0f236f 100644 --- a/woocommerce-gateway-dummy.php +++ b/woocommerce-gateway-dummy.php @@ -53,7 +53,18 @@ public static function init() { * @param array */ public static function add_gateway( $gateways ) { - $gateways[] = 'WC_Gateway_Dummy'; + + $options = get_option( 'woocommerce_dummy_settings', array() ); + + if ( isset( $options['hide_for_non_admin_users'] ) ) { + $hide_for_non_admin_users = $options['hide_for_non_admin_users']; + } else { + $hide_for_non_admin_users = 'no'; + } + + if ( ( 'yes' === $hide_for_non_admin_users && current_user_can( 'manage_options' ) ) || 'no' === $hide_for_non_admin_users ) { + $gateways[] = 'WC_Gateway_Dummy'; + } return $gateways; } @@ -96,7 +107,7 @@ public static function woocommerce_gateway_dummy_woocommerce_block_support() { add_action( 'woocommerce_blocks_payment_method_type_registration', function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) { - $payment_method_registry->register( new WC_Gateway_Dummy_Blocks_Support ); + $payment_method_registry->register( new WC_Gateway_Dummy_Blocks_Support() ); } ); }