Skip to content

Commit

Permalink
Merge pull request #22 from woocommerce/feature/issue_21
Browse files Browse the repository at this point in the history
Add new feature to hide if non-admin users on front end
  • Loading branch information
NickGreen authored Sep 29, 2023
2 parents 632902d + 0820b6b commit 186c2b4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
14 changes: 10 additions & 4 deletions includes/class-wc-gateway-dummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) );
Expand All @@ -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' ),
Expand Down
15 changes: 13 additions & 2 deletions woocommerce-gateway-dummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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() );
}
);
}
Expand Down

0 comments on commit 186c2b4

Please sign in to comment.