Created
April 10, 2014 19:46
-
-
Save messica/10416304 to your computer and use it in GitHub Desktop.
Add new custom fields to Advanced Settings with an array of options. Supports 'text','select', and 'textarea' as field_types.
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 | |
//Add new custom fields to Advanced Settings with an array of options. Supports 'text','select', and 'textarea' as field_types. | |
// | |
//Example: | |
// | |
function my_advanced_settings() { | |
$custom_fields = array( | |
'field1' => array( | |
'field_name' => 'test1', | |
'field_type' => 'text', | |
'label' => 'label1', | |
'description' => 'description' | |
) , | |
'field2' => array( | |
'field_name' => 'tes22', | |
'field_type' => 'text', | |
'label' => 'label2', | |
'description' => 'another descrioption' | |
) | |
); | |
return $custom_fields; | |
} | |
add_filter('pmpro_custom_advanced_settings','my_advanced_settings'); | |
// | |
//Available options: | |
// | |
//'field_name' => 'string', // "id" and "name" attributes | |
//'field_type' => 'string', // type of field | |
//'label' => 'string', // field label | |
//'description' => 'string' // description, shows up under field | |
//'value' => 'string' //default value | |
//'options' => array() // array of options (for select fields) | |
// | |
//These values can then be used anywhere like so: | |
// | |
//$test1 = pmpro_getOption('custom_test1'); |
Thanks for the heads up on that. I'll fix up the PMPro WooCommerce one ASAP.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I guess we need to change above example code: below is the bit of code used for Paid Memberships Pro - WooCommerce Add On
//existing function
function pmprowoo_custom_settings() {
$fields = array(
'field1' => array(
'field_name' => 'pmprowoo_discounts_on_subscriptions',
'field_type' => 'select',
'label' => 'Apply Member Discounts to WC Subscription Products?',
'value' => 'No',
'options' => array('Yes','No')
)
);
return $fields;
}
add_filter('pmpro_custom_advanced_settings', 'pmprowoo_custom_settings');
So if another plugin author try to use filer pmpro_custom_advanced_settings, their code will be lost.
above function need to rewrite as below:
resource ro follow: http://hookr.io/filters/pmpro_custom_advanced_settings/
function pmprowoo_custom_settings( $fields ) {
$fields['field1'] = array(
'field_name' => 'pmprowoo_discounts_on_subscriptions',
'field_type' => 'select',
'label' => 'Apply Member Discounts to WC Subscription Products?',
'value' => 'No',
'options' => array('Yes','No')
);
return $fields;
}
add_filter('pmpro_custom_advanced_settings', 'pmprowoo_custom_settings', 10,1);