PHP code example of joanrodas / custom-product-fields
1. Go to this page and download the library: Download joanrodas/custom-product-fields library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
joanrodas / custom-product-fields example snippets
use CCF\Section\ProductSection;
use CCF\Field\Field;
use CCF\Field\RepeatableField;
add_action('ccf_register_fields', function () {
ProductSection::create('section_slug', 'Section name', [
Field::create('text', 'text_field', 'Text Field')
->default_value('default')
Field::create('textarea', 'textarea_field', 'Textarea Field'),
Field::create('switch', 'switch_field', 'Switch Field'),
Field::create('checkbox', 'checkbox_field', 'Checkbox Field'),
Field::create('number', 'number_field', 'Number Field')
->min(3)
->max(23.5)
->step(0.1)
->set_datalist([1,2,5,10,15]),
Field::create('html', 'html_inside', 'Inside html')
->html('<b>Bold text</b>'),
Field::create('select', 'select_field', 'Select Field')->set_options('add_select_options'),
Field::create('rich_text', 'rich_text_field', 'Rich Text Field'),
RepeatableField::create('repeatable_field', 'Repeatable Field', [
Field::create('password', 'password_inside', 'Inside password'),
Field::create('url', 'url_inside', 'Inside url')
->set_datalist(['https://plubo.dev']),
Field::create('time', 'time_inside', 'Inside time')
->set_datalist(['10:20']),
Field::create('date', 'date_inside', 'Inside date')
->set_datalist(['2023-02-02', '2023-02-01']),
Field::create('color', 'color_field', 'Color Field')
->set_datalist(['#ffdede', '#f3d4de']),
]),
])
->if_tab('general')
// ->if_product_type(['simple', 'variable'])
// ->if_checked('virtual')
;
});
function add_select_options() {
return [
'option_1' => 'Option 1',
'option_2' => 'Option 2',
'option_3' => 'Option 3',
'option_4' => 'Option 4'
];
}