Skip to content

Instantly share code, notes, and snippets.

@BrianHenryIE
Created May 26, 2021 18:27
Show Gist options
  • Save BrianHenryIE/05c598dcd2ef4531bc30aea11a414678 to your computer and use it in GitHub Desktop.
Save BrianHenryIE/05c598dcd2ef4531bc30aea11a414678 to your computer and use it in GitHub Desktop.
to add a button inside payment settings?
<?php
/**
* Register the new field in the array of settings fields for the gateway
*
* @hooked woocommerce_settings_api_form_fields_{$gateway_id}
*
* @param array $settings The gateway's existing settings.
*
* @return array
*/
function add_my_field_to_settings( array $settings ): array {
$settings[] = array(
'id' => 'my_new_field_config',
'type' => 'my_new_field',
);
return $settings;
}
add_filter( "woocommerce_settings_api_form_fields_{$gateway_id}", 'add_my_field_to_settings' );
/**
* Output the settings field.
*
* @hooked woocommerce_admin_field_my_new_field
* @see \WC_Admin_Settings::output_fields()
*
* @param array<string, mixed> $value The get_settings() configuration with the saved $value in its `value` key.
*/
public function print_my_new_field( array $value ): void {
echo "<button>HERE</button>";
}
add_action('woocommerce_admin_field_my_new_field', 'print_my_new_field');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment