Created
May 26, 2021 18:27
-
-
Save BrianHenryIE/05c598dcd2ef4531bc30aea11a414678 to your computer and use it in GitHub Desktop.
to add a button inside payment settings?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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