2016-04-21 25 views
0

私はWooCommerceバージョン2.5.5を実行しています。WooCommerceの[カートに追加]ボタンのテキストを変更してアイテムを変更する

add_filter('variable_add_to_cart_text', 'my_custom_cart_button_text'); 

function my_custom_cart_button_text() { 

     return __('Buy Now', 'woocommerce'); 

} 

あなたは私が欠けているかを知ることが起こるでしょう:次のコード行は、バリエーションを持つアイテムのための私の製品ページ上のカートボタンテキストに追加を変更していないようですか?

答えて

3

更新: WooCommerce 3+

のためのあなたは(下referenceで参照)WooCommerce の以前のバージョン2.1のために廃止されたフックを使用しています。

まずあなたが条件で、これらの(新)フックに希望製品タイプをターゲットにすることができます:

  • :今、あなたはWoocommerceため2可能なフックを持って

    global $product; 
    
    if ($product->is_type('simple')) // for simple product 
        // Your text for simple product 
    
    if ($product->is_type('variable')) // for variable product 
        // Your text for variable product 
    
    if ($product->is_type('grouped')) // for grouped product 
        // Your text for grouped product 
    
    if ($product->is_type('external')) // for external product 
        // Your text for external product 
    

    単一製品ページ製品の種類の条件付き):

add_filter('woocommerce_product_add_to_cart_text', 'my_custom_cart_button_text', 10, 2); 

そして、あなたは以下となります。製品アーカイブページ製品タイプ条件付き)を標的とするための

add_filter('woocommerce_product_single_add_to_cart_text', 'my_custom_cart_button_text', 10, 2); 
  • そして、他のそれらの一方または両方を使用して、変数製品タイプ条件、この方法:See here

    function my_custom_cart_button_text($button_text, $product) { 
    
        if ($product->is_type('variable')) 
         $button_text = __('Buy Now', 'woocommerce'); 
    
        return $button_text 
    } 
    

    はまた、製品タイプ別のカスタムボタンテキストを持つことができます。


    参考:Change add to cart button text

+0

フィルタ名に商品タイプのフィルタは存在しません。彼らに私を指摘できますか? – helgatheviking

3

単一の製品ページの正しいフィルタがwoocommerce_product_single_add_to_cart_textです。

function my_custom_cart_button_text($text, $product) { 
    if($product->is_type('variable')){ 
     $text = __('Buy Now', 'woocommerce'); 
    } 
    return $text; 
} 
add_filter('woocommerce_product_single_add_to_cart_text', 'my_custom_cart_button_text', 10, 2); 
+0

アップしてくれてありがとう。それはコメントのための少し余りにもコードだったが、あなたは答えが非常に詳細である改訂され、私はあまりにもそれをupvoteします。 – helgatheviking

関連する問題