在单个产品页面上显示WooCommerce价格变量

时间:2020-07-15 14:03:25

标签: wordpress woocommerce

我实际上是在WooCommerce上工作,我想在单个产品页面上显示一个自定义标签,其中包含产品价格除以12。

目前,我正在使用自定义字段手动输入价格,但我想自动执行

如何获取产品价格变量并将其除以12

类似的东西 如果产品的正常价格除以12,如果没有,就得到销售价格

感谢您的帮助。


编辑:

我可以在单个产品页面和产品循环上用以下代码显示价格除以12的结果:

add_filter( 'woocommerce_get_price_html', 'change_displayed_sale_price_html', 10, 2 );
function change_displayed_sale_price_html( $price, $product ) {
     // Only on sale products on frontend and excluding min/max price on variable products
    if( $product->is_type('simple') ){
         // Get product prices
         $regular_price = (float) $product->get_regular_price(); // Regular price
         $sale_price = (float) $product->get_price(); // Active price (the "Sale price" when on-sale)
         
         $precision = 2; // Max number of decimals

         if (empty($sale_price)) {
            $cuotaprecioregular = round ($regular_price / 12, $precision);
            $price .= sprintf( __('<p class="saved-sale">12 cuotas de: %s</p>', 'woocommerce' ), $cuotaprecioregular );
         }
         else {
            $cuotapreciosale = round ($sale_price / 12, $precision);
            $price .= sprintf( __('<p class="saved-sale">12 cuotas de: %s</p>', 'woocommerce' ), $cuotapreciosale );
         }
    }
    return $price;
}

但是我还要尝试在弹出的产品页面上显示产品价格,以20%的增量递增。使用此功能,价格显示为低于原始价格

我该怎么做,但只能在所需的弹出窗口中显示?

0 个答案:

没有答案