Php 在ROEN主题中过滤用于销售Flash徽章的WooCommerce功能时,产品图像消失

Php 在ROEN主题中过滤用于销售Flash徽章的WooCommerce功能时,产品图像消失,php,wordpress,woocommerce,add-filter,Php,Wordpress,Woocommerce,Add Filter,我试图显示用户在WooCommerce的销售徽章上节省了多少百分比。为了在不覆盖“特色”销售徽章的情况下实现这一点,我必须在functions.php中添加一些过滤器。现在一切都很好,除了产品页面上的产品图片消失了,我一辈子都不明白为什么。主题文件product-image.php中的“onsale-featured”代码与“onsale”代码几乎相同,我不明白为什么在产品上市时图像会消失,但在产品上市时图像却不会消失 我在functions.php中的代码 add_filter('woocom

我试图显示用户在WooCommerce的销售徽章上节省了多少百分比。为了在不覆盖“特色”销售徽章的情况下实现这一点,我必须在functions.php中添加一些过滤器。现在一切都很好,除了产品页面上的产品图片消失了,我一辈子都不明白为什么。主题文件product-image.php中的“onsale-featured”代码与“onsale”代码几乎相同,我不明白为什么在产品上市时图像会消失,但在产品上市时图像却不会消失

我在functions.php中的代码

add_filter('woocommerce_sale_flash', 'my_custom_sale_flash' );
function my_custom_sale_flash($text) {
    global $product;
    if($product->is_on_sale()){
        $percentage = round( ( ( $product->regular_price - $product->sale_price ) / $product->regular_price ) * 100 );
        return '<span class="onsale">SPAR '.$percentage.' %</span>';  
    }elseif($product->is_featured()){
    return '<span class="onsale featured">Utvalgt</span>';
    }else if(!$product->is_in_stock()){
        return '<span class="onsale">Utsolgt</span>';
    }else  if(!$product->get_price()){
        return '<span class="onsale">GRATIS</span>';
}
} 
add_filter('woocommerce_sale_flash'、'my_custom_sale_flash');
功能my_custom_sale_flash($text){
全球$产品;
如果($product->正在销售()){
$percentage=round(($product->regular\u price-$product->sale\u price)/$product->regular\u price)*100);
返回“SPAR”。$百分比。“%”;
}elseif($product->is_精选()){
返回“Utvalgt”;
}否则如果(!$product->库存中(){
返回“Utsolgt”;
}否则如果(!$product->get_price()){
返回“免费”;
}
} 
ROEN主题中product-image.php中的代码

<?php
/**
 * Single Product Image
 *
 * @author      WooThemes
 * @package     WooCommerce/Templates
 * @version     2.0.14
 */

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

global $post, $woocommerce, $product;

?>
<div class="images">

    <?php
        if ( has_post_thumbnail() ) {

            $image_title        = "";
            $image_link         = wp_get_attachment_url( get_post_thumbnail_id() );
            $image              = get_the_post_thumbnail( $post->ID, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ), array('title' => $image_title) );

            $attachment_count   = count( $product->get_gallery_attachment_ids() );

            if ( $attachment_count > 0 ) {
                $gallery = '[product-gallery]';
                $zoom = "";
            } else {
                $gallery = '';
                $zoom = 'zoom';
            }



            $html = '';

            if($product->is_featured()){
                $html = apply_filters('woocommerce_sale_flash', '<span class="featured onsale">'.__('Featured','ROEN').'</span>', $post, $product);
            }else if($product->is_on_sale()){
                $html = apply_filters('woocommerce_sale_flash', '<span class="onsale">'.__( 'Sale!', 'woocommerce' ).'</span>', $post, $product);
            }else if(!$product->is_in_stock()){
                $html = '<span class="outofstock">'.__('Out of Stock','ROEN').'</span>';
            }else  if(!$product->get_price()){
                $html = '<span class="free onsale">'.__('Free','ROEN').'</span>';
            }

            echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '<a href="%s" itemprop="image" class="woocommerce-main-image '.$zoom.'" title="%s"  rel="prettyPhoto' . $gallery . '" data-url="%s">%s'.$html.'</a>', $image_link, $image_title, $image_link ,  $image ), $post->ID );
        } else {

            echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '<img src="%s" alt="Placeholder" />', woocommerce_placeholder_img_src() ), $post->ID );

        }
    ?>

    <?php do_action( 'woocommerce_product_thumbnails' ); ?>

</div>


我通过换衣服把这个修好了

echo应用过滤器('woocommerce\u single\u product\u image\u html',sprintf(''.$image\u link,$image\u title,$image\u link,$image),$post->ID)

echo应用过滤器('woocommerce\u single\u product\u image\u html',sprintf(''.$image\u link,$image\u title,$image\u link,$image,$html),$post->ID)

事实证明Wordpress不喜欢销售徽章上显示的我的跨度中的百分号,因为ROEN主题的编码方式

我告诉你,老兄,这个主题有很多奇怪的代码