我要让所有的input产品和购物车页面标签带班qty有type="number",并readonly="readonly"通过与PHP修改DOM属性。当我将其限制为购物车和产品页面时,它“仅”使延迟加载插件和自动优化插件停止为这两个页面工作,而其他页面则很好。我也无法在管理页面上发现任何控制台错误。当我允许它为每个页面运行时,会发生以下情况:产品和购物车页面的控制台中没有错误。Ajax 请求将 Ajax 添加到购物车插件中断。我收到多个控制台错误,这些错误会破坏许多管理页面的布局,移动和隐藏部分内容。这些输出缓冲区修改感觉就像黑客攻击导致的错误/不兼容。难道是因为libxml_use_internal_errors(true);它隐藏了警告并且实际上没有解决任何问题?这是我的functions.php:add_action( 'template_redirect', 'acau_activate_buffer', 99999 );function acau_activate_buffer() { // cart and product page only, WooCommerce required for below line to work, remove to reproduce issues without WooCommerce if ( ! is_cart() && ! is_product() ) return; ob_start();}add_action('shutdown', function() { // cart and product page only, WooCommerce required for below line to work, remove to reproduce issues without WooCommerce if ( ! is_cart() && ! is_product() ) return; $final = ''; // Collect output from all previous buffers. $levels = ob_get_level(); for ($i = 0; $i < $levels; $i++) { $final .= ob_get_clean(); } echo apply_filters('acau_output', $final);}, -99999);// Filter final output.add_filter('acau_output', function($output) { $dom = new DOMDocument(); libxml_use_internal_errors(true); $dom->loadHTML(mb_convert_encoding($output, 'HTML-ENTITIES', 'UTF-8')); foreach ($dom->getElementsByTagName('input') as $node) { $classes = explode (' ', $node->getAttribute('class') ); if ( in_array ( 'qty', $classes ) ) { $node->setAttribute('type', 'number'); $node->setAttribute('readonly', 'readonly'); } } $newHtml = $dom->saveHtml(); return $newHtml;});
1 回答
- 1 回答
- 0 关注
- 172 浏览
添加回答
举报
0/150
提交
取消