問題描述
我正在使用顯示僅在所有 WooCommerce 產(chǎn)品循環(huán)上的價格后綴 回答我上一個問題的代碼,以便在除產(chǎn)品詳細(xì)信息頁面 (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).
我只想為產(chǎn)品詳細(xì)信息頁面添加另一個價格后綴.后綴應(yīng)包含鏈接且字體大小應(yīng)可編輯.
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.
有人可以幫我嗎?
推薦答案
要僅使用自定義鏈接在單個產(chǎn)品上顯示價格后綴,請嘗試以下操作:
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;
}
內(nèi)聯(lián) CSS 樣式規(guī)則(可以添加到主題的 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 文件中.經(jīng)測試有效.
Code goes in functions.php file of your active child theme (or active theme). Tested and works.
如果價格后綴應(yīng)在文本中包含鏈接,請使用以下內(nèi)容:
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;
}
內(nèi)聯(lián) CSS 樣式規(guī)則(可以添加到主題的 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 文件中.經(jīng)測試有效.
Code goes in functions.php file of your active child theme (or active theme). Tested and works.
這篇關(guān)于僅在所有 WooCommerce 單一產(chǎn)品上顯示價格后綴的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!