Woocommerce 如何使销售徽章响应产品形象

Woocommerce 如何使销售徽章响应产品形象,woocommerce,badge,Woocommerce,Badge,我在电子商务中使用woocommerce插件网站实现了销售徽章,但在其上没有响应产品图像。 我想要响应销售徽章,当图像尺寸较小时,其销售徽章尺寸会随着产品图像尺寸的变化而自动调整。 现在的代码,我正在使用,但不工作的显示销售徽章图像大小在移动视图中大,在桌面视图中小,如何使其与产品图像响应 我使用此代码进行销售,以在产品上显示 add_filter( 'woocommerce_sale_flash', 'add_percentage_to_sale_bubble' ); function add

我在电子商务中使用woocommerce插件网站实现了销售徽章,但在其上没有响应产品图像。 我想要响应销售徽章,当图像尺寸较小时,其销售徽章尺寸会随着产品图像尺寸的变化而自动调整。 现在的代码,我正在使用,但不工作的显示销售徽章图像大小在移动视图中大,在桌面视图中小,如何使其与产品图像响应

我使用此代码进行销售,以在产品上显示

add_filter( 'woocommerce_sale_flash', 'add_percentage_to_sale_bubble' );
function add_percentage_to_sale_bubble( $html ) {
    global $product;
    $percentage = round( ( ( $product->regular_price - $product->sale_price ) / $product->regular_price ) * 100 );
    $output =' <span class="onsale">'.$percentage.'%'.'<br>'.' OFF</span>';
    return $output;
}
手推车

add_filter( 'woocommerce_format_sale_price', 'woocommerce_custom_sales_price', 10, 3 );
function woocommerce_custom_sales_price( $price, $regular_price, $sale_price ) {
    // Getting the clean numeric prices (without html and currency)
    $_reg_price = floatval( strip_tags($regular_price) );
    $_sale_price = floatval( strip_tags($sale_price) );

    // Percentage calculation and text
    $percentage = round( ( $_reg_price - $_sale_price ) / $_reg_price * 100 ).'%';
  //  $percentage_txt = ' ' . __(' Save ', 'woocommerce' ) . $percentage;
 $percentage_txt = ' '.$percentage.'<br>' .'OFF';
    $formatted_regular_price = is_numeric( $regular_price ) ? wc_price( $regular_price ) : $regular_price;
    $formatted_sale_price    = is_numeric( $sale_price )    ? wc_price( $sale_price )    : $sale_price;

   if(is_cart()){
    
      echo  ' <ins>' . $formatted_regular_price.'<br><span class="percentage_text1"><span class="percentage_cart_text">'. $percentage_txt . '</span></span></ins>';
 }else{
         
    
   echo  ' <ins>' . $formatted_regular_price.'<br><span class="percentage_text1"><span class="percentage_wishlist_text">'. $percentage_txt . '</span></span></ins>';
     }
}
add_filter('woocommerce_format_sale_price','woocommerce_custom_sales_price',10,3);
功能商业\自定义\销售\价格($price、$常规\价格、$sale\价格){
//获取干净的数字价格(无html和货币)
$\u reg\u price=floatval(带标签($regular\u price));
$_sale_price=floatval(带标签($sale_price));
//百分比计算和文本
$percentage=四舍五入($注册价格-$销售价格)/$注册价格*100)。'%';
//$percentage_txt='.'.\u('Save','woocommerce')。$percentage;
$percentage_txt='.$percentage.
'.'OFF'; $formatted_regular_price=是否为数字($regular_price)?wc_price($regular_price):$regular_price; $formatted_sale_price=是否为数字($sale_price)?wc_price($sale_price):$sale_price; if(is_cart()){ 回显“.$FORMATED_REQUAL_price.”
“.$PERCENTION_txt.”; }否则{ 回显“.$FORMATED_REQUAL_price.”
“.$PERCENTION_txt.”; } }
现在我想销售徽章图标与产品形象负责

add_filter( 'woocommerce_format_sale_price', 'woocommerce_custom_sales_price', 10, 3 );
function woocommerce_custom_sales_price( $price, $regular_price, $sale_price ) {
    // Getting the clean numeric prices (without html and currency)
    $_reg_price = floatval( strip_tags($regular_price) );
    $_sale_price = floatval( strip_tags($sale_price) );

    // Percentage calculation and text
    $percentage = round( ( $_reg_price - $_sale_price ) / $_reg_price * 100 ).'%';
  //  $percentage_txt = ' ' . __(' Save ', 'woocommerce' ) . $percentage;
 $percentage_txt = ' '.$percentage.'<br>' .'OFF';
    $formatted_regular_price = is_numeric( $regular_price ) ? wc_price( $regular_price ) : $regular_price;
    $formatted_sale_price    = is_numeric( $sale_price )    ? wc_price( $sale_price )    : $sale_price;

   if(is_cart()){
    
      echo  ' <ins>' . $formatted_regular_price.'<br><span class="percentage_text1"><span class="percentage_cart_text">'. $percentage_txt . '</span></span></ins>';
 }else{
         
    
   echo  ' <ins>' . $formatted_regular_price.'<br><span class="percentage_text1"><span class="percentage_wishlist_text">'. $percentage_txt . '</span></span></ins>';
     }
}