From 094fa28f900df39ececdfc4b3c7ad2922acd864e Mon Sep 17 00:00:00 2001 From: paul sealock Date: Tue, 4 Jun 2024 12:56:19 +1200 Subject: [PATCH] custom html and slotfills working --- .../client/settings/content.js | 15 ++++++ .../admin/settings/class-wc-settings-page.php | 50 ++++++++++++++++++- 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/plugins/woocommerce-admin/client/settings/content.js b/plugins/woocommerce-admin/client/settings/content.js index 66400b69ddf..53ab4e9ea65 100644 --- a/plugins/woocommerce-admin/client/settings/content.js +++ b/plugins/woocommerce-admin/client/settings/content.js @@ -13,6 +13,7 @@ import { SettingsCheckbox, SettingsInput } from './components'; export const Content = ( { data } ) => { const { settings } = data; + console.log( settings ); const [ formData, setFormData ] = useState( {} ); const [ isBusy, setIsBusy ] = useState( false ); const formRef = useRef( null ); @@ -119,6 +120,20 @@ export const Content = ( { data } ) => { return ( ); + case 'custom': + return ( +
+
+
+ ); default: return null; } diff --git a/plugins/woocommerce/includes/admin/settings/class-wc-settings-page.php b/plugins/woocommerce/includes/admin/settings/class-wc-settings-page.php index 93554ffebfd..1dab5aa6042 100644 --- a/plugins/woocommerce/includes/admin/settings/class-wc-settings-page.php +++ b/plugins/woocommerce/includes/admin/settings/class-wc-settings-page.php @@ -31,6 +31,42 @@ if ( ! class_exists( 'WC_Settings_Page', false ) ) : */ protected $label = ''; + /** + * Setting page label. + * + * @var string + */ + protected $types = array( + 'title', + 'info', + 'sectionend', + 'text', + 'password', + 'datetime', + 'datetime-local', + 'date', + 'month', + 'time', + 'week', + 'number', + 'email', + 'url', + 'tel', + 'color', + 'textarea', + 'select', + 'multiselect', + 'radio', + 'checkbox', + 'image_width', + 'single_select_page', + 'single_select_page_with_search', + 'single_select_country', + 'multi_select_countries', + 'relative_date_selector', + 'slotfill_placeholder', + ); + /** * Constructor. */ @@ -94,14 +130,26 @@ if ( ! class_exists( 'WC_Settings_Page', false ) ) : public function get_settings_page_data( $pages ) { $sections = $this->get_sections(); $sections_data = array(); + foreach ( $sections as $section_id => $section_label ) { $section_settings = $this->get_settings_for_section( $section_id ); $section_settings_data = array(); foreach( $section_settings as $section_setting ) { if ( isset( $section_setting['id'] ) ) { - $section_setting['value'] = isset( $section_setting['default'] ) ? get_option( $section_setting['id'], $section_setting['default'] ) : get_option( $section_setting['id'] ); + $section_setting['value'] = isset( $section_setting['default'] ) ? get_option( $section_setting['id'], $section_setting['default'] ) : get_option( $section_setting['id'] ); } + + if ( ! in_array( $section_setting['type'], $this->types ) ) { + ob_start(); + do_action( 'woocommerce_admin_field_' . $section_setting['type'], $section_setting); + $html = ob_get_contents(); + $section_setting['content'] = trim( $html ); + $section_setting['id'] = $section_setting['type']; + $section_setting['type'] = 'custom'; + ob_end_clean(); + } + $section_settings_data[] = $section_setting; } $sections_data[ $section_id ] = array(