【问题标题】:Increase product price font size only on WooCommerce single product pages仅在 WooCommerce 单个产品页面上增加产品价格字体大小
【发布时间】:2022-02-17 12:12:36
【问题描述】:

我添加了一个编码,只显示可变产品的最低价格,它工作得很好(见下文)

add_action( 'woocommerce_before_single_product', 'move_variations_single_price', 1 );
function move_variations_single_price(){
    global $product, $post;

    if ( $product->is_type( 'variable' ) ) {
        // removing the variations price for variable products
        remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );

        // Change location and inserting back the variations price
        add_action( 'woocommerce_single_product_summary', 'replace_variation_single_price', 10 );
    }
}

function replace_variation_single_price(){
    global $product;

    // Main Price
    $prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
    $price = $prices[0] !== $prices[1] ? sprintf( __( 'From: %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( __( 'From: %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );

    if ( $price !== $saleprice && $product->is_on_sale() ) {
        $price = '<del>' . $saleprice . $product->get_price_suffix() . '</del> <ins>' . $price . $product->get_price_suffix() . '</ins>';
    }

    ?>
    <style>
        div.woocommerce-variation-price,
        div.woocommerce-variation-availability,
        div.hidden-variable-price {
            height: 0px !important;
            overflow:hidden;
            position:relative;
            line-height: 0px !important;
            font-size: 0% !important;
        }
    </style>
    <script>
    jQuery(document).ready(function($) {
        $('select').blur( function(){
            if( '' != $('input.variation_id').val() ){
                if($('p.availability'))
                    $('p.availability').remove();
                $('p.price').html($('div.woocommerce-variation-price > span.price').html()).append('<p class="availability">'+$('div.woocommerce-variation-availability').html()+'</p>');
                console.log($('input.variation_id').val());
            } else {
                $('p.price').html($('div.hidden-variable-price').html());
                if($('p.availability'))
                    $('p.availability').remove();
                console.log('NULL');
            }
        });
    });
    </script>
    <?php

    echo '<p class="price">'.$price.'</p>
    <div class="hidden-variable-price" >'.$price.'</div>';
}    

然后,我使用以下代码尝试增加字体大小以适应价格,这也很有效:

span.woocommerce-Price-amount.amount {
    font-size: 1.5em;
}

但它也会影响所有其他页面,例如结帐页面。

有没有办法隔离此代码,以影响产品摘要区域中的较大字体?

【问题讨论】:

  • 请发送您的网站网址,然后我会为您提供 css

标签: css wordpress woocommerce


【解决方案1】:

请在您的子 CSS 文件中添加以下代码。

.single-product span.amount {

    font-size: 1.5em;

}

【讨论】:

  • 非常感谢!这不再影响其他页面,但我忘了提一件事。我在标题处显示了购物车的总美元价值。此代码仍会增加标题处购物车值的字体大小。非常感谢您的进一步建议。谢谢!
猜你喜欢
  • 2021-11-03
  • 1970-01-01
  • 1970-01-01
  • 2019-12-04
  • 1970-01-01
  • 2017-09-01
  • 2019-01-09
  • 2014-02-24
  • 1970-01-01
相关资源
最近更新 更多