2014-10-30 33 views
0

當我將此代碼添加到functions.php 我得到內部服務器錯誤.... 有什麼不對?WP-Woocommerce內部服務器錯誤500代碼片段

片斷的目的:此代碼來代替價格有變化的產品(價格1,價格2),將「1個$」,表示較低的價格輸出...

debbuging得到這個後從日誌:

PHP Warning: Cannot modify header information - headers already sent by (output started at /home/organicb/public_html/wp-content/themes/flatsome-child/functions.php:20) in /home/organicb/public_html/wp-includes/pluggable.php 

片段在https://gist.github.com/kloon/8981075

// Use WC 2.0 variable price format, now include sale price strikeout 
    add_filter('woocommerce_variable_sale_price_html', 'wc_wc20_variation_price_format', 10, 2); 
    add_filter('woocommerce_variable_price_html', 'wc_wc20_variation_price_format', 10, 2); 
    function wc_wc20_variation_price_format($price, $product) { 
     // Main Price 
     $prices 
     = array($product->get_variation_price('min', true), $product->get_variation_price('max', true)); 
     $price = $prices[0] !== $prices[1] ? sprintf(__('Desde: %1$s', 'woocommerce'), wc_price($prices[0])) : wc_price($prices[0]); 
     // Sale Price 
     $prices = array($product->get_variation_regular_price('min', true), $product->get_variation_regular_price('max', true)); 
     sort($prices); 
     $saleprice = $prices[0] !== $prices[1] ? sprintf(__('Desde: %1$s', 'woocommerce'), wc_price($prices[0])) : wc_price($prices[0]); 

     if ($price !== $saleprice) { 
      $price = '<del>' . $saleprice . '</del> <ins>' . $price . '</ins>'; 
     } 
     return $price;} 
+0

有什麼用此代碼? – Gunaseelan 2014-10-30 11:49:45

+0

這個代碼是取代有變化(價格1,價格2)的產品的價格,它會輸出「從1 $」,顯示更低的價格... – maha2 2014-10-30 13:26:01

+0

你有任何暗示爲什麼這個片段打破了網站? – maha2 2014-10-30 13:39:44

回答

0

發現你應該WP_DEBUG開發啓用。在您的wp-config.php文件,請搜索:

define('WP_DEBUG', false); 

,並更改爲:

define('WP_DEBUG', true); 
+0

會嘗試。謝謝。我似乎無法找到錯誤...是否有錯誤日誌?似乎我的阿賈克斯購物車和片段發生衝突...有時會給出錯誤500其他時間不... – maha2 2014-10-30 13:14:25

+0

使用這個來wordpress創建一個日誌文件define('WP_DEBUG_LOG',true); – ThemesCreator 2014-10-30 13:16:46

+0

非常感謝你,得到了日誌...顯然這是我的代碼片段的問題,'PHP警告:不能修改標題信息 - 已經發送的標題(輸出開始於/ home/organicb/public_html/wp-content/themes /flatsome-child/functions.php:20)位於/home/organicb/public_html/wp-includes/pluggable.php 1121行 – maha2 2014-10-30 13:19:54