製品の詳細ページ(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ファイルに入ります。テストされ、動作します。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加