Commit 716d0072915 for woocommerce
commit 716d00729150b1bac24d037ad410c88fd57ddc99
Author: Luigi Teschio <gigitux@gmail.com>
Date: Wed Oct 14 17:14:24 2026 +0200
Fix CSP nonce support for JavaScript detection (#69811)
* Fix CSP nonce support for JavaScript detection
* Add changelog entry for JavaScript detection CSP fix
* Add an ID to the JavaScript detection script
diff --git a/plugins/woocommerce/changelog/fix-61141-no-js-script-csp b/plugins/woocommerce/changelog/fix-61141-no-js-script-csp
new file mode 100644
index 00000000000..bfa0d8a305e
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-61141-no-js-script-csp
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Allow JavaScript detection to work with nonce-based Content Security Policies.
diff --git a/plugins/woocommerce/includes/wc-template-functions.php b/plugins/woocommerce/includes/wc-template-functions.php
index f355cdc618d..e922d0d7d8a 100644
--- a/plugins/woocommerce/includes/wc-template-functions.php
+++ b/plugins/woocommerce/includes/wc-template-functions.php
@@ -398,16 +398,16 @@ function wc_body_class( $classes ) {
* @return void
*/
function wc_no_js() {
- $type_attr = current_theme_supports( 'html5', 'script' ) ? '' : " type='text/javascript'";
- ?>
- <script<?php echo $type_attr; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
+ wp_print_inline_script_tag(
+ "
(function () {
var c = document.body.className;
c = c.replace(/woocommerce-no-js/, 'woocommerce-js');
document.body.className = c;
})();
- </script>
- <?php
+ ",
+ array( 'id' => 'wc-no-js' )
+ );
}
/**