當我將此代碼添加到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;}
有什麼用此代碼? – Gunaseelan 2014-10-30 11:49:45
這個代碼是取代有變化(價格1,價格2)的產品的價格,它會輸出「從1 $」,顯示更低的價格... – maha2 2014-10-30 13:26:01
你有任何暗示爲什麼這個片段打破了網站? – maha2 2014-10-30 13:39:44