在哪里可以为woocommerce包装器添加另一个类?

sis*_*isi 5 woocommerce

Woocommerce有一个类为“ woocommmerce”的div,我想添加另一个类或删除该类。那是哪个文件

   <div class="woocommerce"></div>
Run Code Online (Sandbox Code Playgroud)

hon*_*k31 0

没有现成的过滤器或类似的东西可以让你做到这一点,但你可以过滤the_content, 来完成它。

function so33675604_add_class_to_checkout( $content ) {
    //condition to check for the proper page
    if ( is_checkout() ) :
        //disable error reporting for falsy formatted html code
        libxml_use_internal_errors(true);

        //parse the $content html (treat content as UTF-8, don't add any doctype or other html wrappers)
        $html = new DOMDocument();
        $html->loadHTML( mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD );

        //search for the very first div
        $container = $html->getElementsByTagName('div')->item(0);
        //add classes (remember to put woocommerce, since thats been used by some js functions)
        $container->setAttribute('class', 'woocommerce oink');

        //return the result
        return $html->saveHTML();
    endif;
    return $content;
}
//add the filter (priority must be high, so it runs later, after the shortcodes have been processed)
add_filter( 'the_content', 'so33675604_add_class_to_checkout', 100 );
Run Code Online (Sandbox Code Playgroud)

请注意,此函数使用条件语句,这些条件语句可能在 wp-ajax 调用中不起作用/您可能会找到另一种方法来检查,if checkout(或其他),可能通过 global wp_query