简体   繁体   English

WP-Woocommerce内部服务器错误500代码段

[英]WP-Woocommerce internal server error 500 code snippet

When I add this code to functions.php I get internal server error.... what's wrong? 当我将此代码添加到functions.php时,出现内部服务器错误...。怎么了?

Purpose of the snippet: This code is to replace prices in products that have variations (price 1, price 2) it will output "from 1$" showing the lower price... 摘录的目的:此代码用于替换具有变化的产品(价格1,价格2)中的价格,它将输出“从1美元起”,显示较低的价格...

after debbuging got this from the log: 调试后从日志中得到了以下信息:

 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

snippet was found in https://gist.github.com/kloon/8981075 片段位于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;}

You should develop with wp_debug enable. 您应该使用wp_debug enable进行开发。 In your wp-config.php file, search for: 在您的wp-config.php文件中,搜索:

define('WP_DEBUG', false);

and change to: 并更改为:

define('WP_DEBUG', true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM