diff --git a/plugins/woocommerce-admin/client/settings/content.js b/plugins/woocommerce-admin/client/settings/content.js index ab1f8814c45..d22fc705a2f 100644 --- a/plugins/woocommerce-admin/client/settings/content.js +++ b/plugins/woocommerce-admin/client/settings/content.js @@ -11,6 +11,20 @@ import { useDispatch } from '@wordpress/data'; */ import { SettingsCheckbox, SettingsInput } from './components'; +const SettingsScript = ( { content } ) => { + useEffect( () => { + const scriptElement = document.createElement( 'script' ); + scriptElement.type = 'text/javascript'; + scriptElement.innerHTML = content; + document.body.appendChild( scriptElement ); + + return () => { + document.body.removeChild( scriptElement ); + }; + }, [] ); + return null; +}; + export const Content = ( { data } ) => { const { settings } = data; console.log( settings ); @@ -135,6 +149,8 @@ export const Content = ( { data } ) => { /> ); + case 'script': + return ; default: return null; } diff --git a/plugins/woocommerce-admin/client/settings/index.js b/plugins/woocommerce-admin/client/settings/index.js index 3908a667e3e..8261a46f3f2 100644 --- a/plugins/woocommerce-admin/client/settings/index.js +++ b/plugins/woocommerce-admin/client/settings/index.js @@ -39,7 +39,6 @@ const appendSettingsScripts = () => { return Object.entries( settingsScripts ).reduce( ( scripts, [ key, script ] ) => { if ( ! ignoredSettingsScripts.includes( key ) ) { - console.log( 'script', key ); const scriptElement = document.createElement( 'script' ); scriptElement.src = script.src; 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 7848498401c..682403b8a5a 100644 --- a/plugins/woocommerce/includes/admin/settings/class-wc-settings-page.php +++ b/plugins/woocommerce/includes/admin/settings/class-wc-settings-page.php @@ -170,6 +170,18 @@ if ( ! class_exists( 'WC_Settings_Page', false ) ) : } // Otherwise, render the page's output method. } else { + if ( 'classes' === $section_id ) { + $tags = new WP_HTML_Tag_Processor( $html ); + while( $tags->next_tag( array( 'tag_name' => 'script' ) ) ) { + $script_type = $tags->get_attribute( 'type' ); + $script_contents = $tags->get_modifiable_text(); + $section_settings_data[] = array( + 'type' => 'script', + 'content' => $script_contents, + ); + } + } + $section_settings_data[] = array( 'type' => 'custom', 'content' => trim( $html ),