![](/img/trans.png)
[英]WooCommerce: Show price suffix only on single product Page - Not for related products
[英]Show a price suffix only on all WooCommerce single products
我只在所有 WooCommerce 產品循環上使用顯示價格后綴回答我上一個問題的代碼,以便在除產品詳細信息頁面 (WooCommerce) 之外的所有頁面上顯示價格后綴。
我只想為產品詳細信息頁面設置另一個價格后綴。 后綴應該包含一個鏈接,並且字體大小應該是可編輯的。
誰能幫我?
要僅使用自定義鏈接在單個產品上顯示價格后綴,請嘗試以下操作:
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 樣式規則(可以添加到主題的 styles.ccs 文件中) :
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 文件。 測試和工作。
如果價格后綴應在文本中包含鏈接,請使用以下內容:
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 樣式規則(可以添加到主題的 styles.ccs 文件中) :
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 文件。 測試和工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.