使用woocommerce_after_shop_loop_item
アクションフックに引っかけ、このカスタム関数を、製品にリンクされているカスタムボタンを追加するには:
add_action('woocommerce_after_shop_loop_item', 'add_a_custom_button', 5);
function add_a_custom_button() {
global $product;
// Not for variable and grouped products that doesn't have an "add to cart" button
if($product->is_type('variable') || $product->is_type('grouped')) return;
// Output the custom button linked to the product
echo '<div style="margin-bottom:10px;">
<a class="button custom-button" href="' . esc_attr($product->get_permalink()) . '">' . __('View product') . '</a>
</div>';
}
コードは、あなたのアクティブな子テーマ(またはテーマ)のfunction.phpファイルに行きますまたは任意のプラグインファイルでも使用できます。
テスト済みで動作します。 あなたのスタイルを埋め込み
(コメントの作成に関連する):
add_action('wp_head', 'custom_button_styles', 9999);
function custom_button_styles() {
if(is_shop() || is_product_category() || is_product_tag()):
// The styles
?>
<style>
.button.custom-button { background-color: white !important;
color: black !important; border: 2px solid #4CAF50 !important; }
.button.custom-button:hover { background-color: black !important;
color: white !important; border: 2px solid black !important; }
</style>
<?php
endif;
}
コードは、あなたのアクティブな子テーマ(またはテーマ)のfunction.phpファイルやも任意のプラグインファイルになります。
テスト済みで動作します。
素晴らしい、それは動作します。どうもありがとうございます !もう1つの質問は、このボタンの背景色とテキストの色だけを編集することですか?ありがとう – NoiTrade88
同様、私は2つのボタンの間にかなりのギャップがあることを観察しましたが、この距離を減らすことはできますか?ありがとう – NoiTrade88
ありがとう、システムは私に新しい質問(新しいアカウント)を投稿することを許可していません、このオリジナルの質問に加えてダウン投票されました。 – NoiTrade88