Changing the Add To Cart button text in WooCommerce for items with variations

前端 未结 2 993
抹茶落季
抹茶落季 2020-12-04 03:36

I\'m running WooCommerce version 2.5.5. The following lines of code don\'t seem to change the Add To Cart button text on my product page for an item with variations:

<
2条回答
  •  独厮守ぢ
    2020-12-04 04:03

    The correct filter for the single product page is 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 );
    

提交回复
热议问题