Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add new custom fields to Advanced Settings with an array of options. Supports 'text','select', and 'textarea' as field_types.
<?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');
@nurul-umbhiya

This comment has been minimized.

Copy link

commented Mar 31, 2016

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);

@ghost

This comment has been minimized.

Copy link

commented Apr 14, 2017

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
You can’t perform that action at this time.