仅在所有 WooCommerce 单一产品上显示价格后缀

Show a price suffix only on all WooCommerce single products(仅在所有 WooCommerce 单一产品上显示价格后缀)
本文介绍了仅在所有 WooCommerce 单一产品上显示价格后缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在使用显示仅在所有 WooCommerce 产品循环上的价格后缀 回答我上一个问题的代码,以便在除产品详细信息页面 (WooCommerce) 之外的所有页面上的价格后显示价格后缀.

I am using Show Price Suffix only on all WooCommerce Product loops answer code to my previous question, to display a price suffix after the price on all pages except the Product Detail Page (WooCommerce).

我只想为产品详细信息页面添加另一个价格后缀.后缀应包含链接且字体大小应可编辑.

I want to have another price suffix only for the Product Detail Page. The suffix should include a link and the font size should be editable.

有人可以帮我吗?

推荐答案

要仅使用自定义链接在单个产品上显示价格后缀,请尝试以下操作:

To display a price suffix on single products only with a custom link, try the following:

add_filter( 'woocommerce_get_price_suffix', 'additional_single_product_price_suffix', 999, 4 );
function additional_single_product_price_suffix( $html, $product, $price, $qty ){
    global $woocommerce_loop;

    // Not on single products
    if ( ( is_product() && isset($woocommerce_loop['name']) && empty($woocommerce_loop['name']) ) ) {
        // Define below the link for your price suffix
        $link = home_url( "/somelink.html" );

        $html .= ' <a href="' . $link . '" target="_blank" class="price-suffix">' . __('Suffix 2') . '</a>';
    }
    return $html;
}

内联 CSS 样式规则(可以添加到主题的 style.ccs 文件中):

Inline CSS style rules (can be added instead to the theme's styles.ccs file):

add_action('wp_head', 'product_price_suffix_css_styling_rules', 9999 );
function product_price_suffix_css_styling_rules() {
    // Only on single product pages
    if( is_product() ):
    ?><style>
        a.price-suffix, a.price-suffix:visited {font-size: 13px; color: #DC143C;}
        a.price-suffix:hover, a.price-suffix:active {color: #960404}
    </style><?php
    endif;
}

代码位于活动子主题(或活动主题)的 functions.php 文件中.经测试有效.

Code goes in functions.php file of your active child theme (or active theme). Tested and works.

如果价格后缀应在文本中包含链接,请使用以下内容:

If the price suffix should include a link inside the text, use the following:

add_filter( 'woocommerce_get_price_suffix', 'additional_single_product_price_suffix', 999, 4 );
function additional_single_product_price_suffix( $html, $product, $price, $qty ){
    global $woocommerce_loop;

    // Not on single products
    if ( ( is_product() && isset($woocommerce_loop['name']) && empty($woocommerce_loop['name']) ) ) {
        // Define below the link for your price suffix
        $link = home_url( "/somelink.html" );

        $html .= sprintf( ' <span class="price-suffix">' . __('Suffix %s') . '</span>', '<a href="' . $link . '"  target="_blank">' . __("link") . '</a>');
    }
    return $html;
}

内联 CSS 样式规则(可以添加到主题的 style.ccs 文件中):

Inline CSS style rules (can be added instead to the theme's styles.ccs file):

add_action('wp_head', 'product_price_suffix_css_styling_rules', 9999 );
function product_price_suffix_css_styling_rules() {
    // Only on single product pages
    if( is_product() ):
    ?><style>
        span.price-suffix {font-size: 13px; color: #000000;}
        span.price-suffix > a, span.price-suffix > a:visited {color: #DC143C}
        span.price-suffix > a:hover, span.price-suffix > a:active {color: #960404}
    </style><?php
    endif;
}

代码位于活动子主题(或活动主题)的 functions.php 文件中.经测试有效.

Code goes in functions.php file of your active child theme (or active theme). Tested and works.

这篇关于仅在所有 WooCommerce 单一产品上显示价格后缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Codeigniter htaccess to remove index.php and www(Codeigniter htaccess 删除 index.php 和 www)
htaccess mod_rewrite part of url to GET variable(htaccess mod_rewrite url 的一部分到 GET 变量)
Replacing a querystring parameter value using mod_rewrite(使用 mod_rewrite 替换查询字符串参数值)
.htaccess in subdirectory #39;overriding#39; parent htaccess(子目录“覆盖父 htaccess 中的 .htaccess)
How to rewrite SEO friendly url#39;s like stackoverflow(如何像stackoverflow一样重写SEO友好的url)
Is it okay to have a very long .htaccess file?(有一个很长的 .htaccess 文件可以吗?)