2015-11-12 68 views
4

Woocommerce有一個類「woocommmerce」div我想添加另一個類或刪除類。那是哪個文件?我可以在哪裏添加woocommerce包裝的另一個類?

<div class="woocommerce"></div> 
+0

我找到了。它位於includes/class-wc-shortcodes.php – sisi

+0

如果在function.php中有這種方法嗎?添加一個類或更改類名稱。因爲當我更新我的woocommerce插件時,它會再次覆蓋。 – sisi

回答

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); 

請注意,這個函數使用條件語句和這些可能無法在WP-AJAX調用工作/你會找到另一種方法來檢查,如果檢出(或其它),很可能是通過全球wp_query

相關問題