Wordpress 如何使用';WooCommerce的折扣规则';电子商务插件

Wordpress 如何使用';WooCommerce的折扣规则';电子商务插件,wordpress,woocommerce,Wordpress,Woocommerce,我正在使用“WooCommerce折扣规则”插件。当使用“WooCommerce的折扣规则”时,当在function.php文件中使用此钩子代码时,我可以在每种产品上获得100%的折扣。但它在销售中完美地展示每件事物是完美的,但当我使用hook时,它并没有在产品上以百分比形式完美地展示销售,只是在每件产品上展示100%的折扣。 现在我想以正确的值获得百分比形式的折扣。 当我搜索时,到处都能找到我对woocommerce\u sale\u flash的钩子,但它只适用于woocommerce插件i

我正在使用“WooCommerce折扣规则”插件。当使用“WooCommerce的折扣规则”时,当在function.php文件中使用此钩子代码时,我可以在每种产品上获得100%的折扣。但它在销售中完美地展示每件事物是完美的,但当我使用hook时,它并没有在产品上以百分比形式完美地展示销售,只是在每件产品上展示100%的折扣。 现在我想以正确的值获得百分比形式的折扣。 当我搜索时,到处都能找到我对woocommerce\u sale\u flash的钩子,但它只适用于woocommerce插件i what for‘woocommerce折扣规则’插件。 但在“wooCommerce折扣规则”插件中,我没有找到任何钩子可以在产品左上方的百分比格式中看到折扣

add_filter( 'woocommerce_sale_flash', 'ask_percentage_sale', 11, 3 );
function ask_percentage_sale( $text, $post, $product ) {
    $discount = 0;
    if ( $product->get_type() == 'variable' ) {
        $available_variations = $product->get_available_variations(); 
        $maximumper = 0;
        for ($i = 0; $i < count($available_variations); ++$i) {
            $variation_id=$available_variations[$i]['variation_id'];
            $variable_product1= new WC_Product_Variation( $variation_id );
            $regular_price = $variable_product1->get_regular_price();
            $sales_price = $variable_product1->get_sale_price();
            if( $sales_price ) {
                $percentage= round( ( ( $regular_price - $sales_price ) / $regular_price ) * 100 ) ;
                if ($percentage > $maximumper) {
                    $maximumper = $percentage;
                }
            }        
        }
        $text = '<span class="onsale">' . $maximumper  . '%</span>';
    } elseif ( $product->get_type() == 'simple' ) {
        $percentage = round( ( ( $product->get_regular_price() - $product->get_sale_price() ) / $product->get_regular_price() ) * 100 );
        $text = '<span class="onsale">' . $percentage . '% off</span>';
    }   
 
    return $text;
}
添加过滤器('woocommerce\u sale\u flash','ask\u percentage\u sale',11,3);
函数询问百分比销售($text、$post、$product){
$折扣=0;
如果($product->get_type()=='variable'){
$available_variations=$product->get_available_variations();
$maximumper=0;
对于($i=0;$iget_regular_price();
$sales_price=$variable_product1->get_sale_price();
if(售价){
$percentage=四舍五入(($regular_price-$sales_price)/$regular_price)*100);
如果($percentage>$maximumper){
$maximumper=$percentage;
}
}        
}
$text='.$maximumper'%';
}elseif($product->get_type()=='simple'){
$percentage=round(($product->get\u regular\u price()-$product->get\u sale\u price())/$product->get\u regular\u price())*100);
$text=''.$percentage.'%off';
}   
返回$text;
}
我尝试了这段代码,但是对于woocommerce销售产品插件,它的显示百分比是正确的,但是对于“Woo折扣规则”,它的显示百分比不是正确的,它总是显示100%的百分比。请告诉我任何方向,以获得折扣的百分比也