xxxxxxxxxx
add_filter('woocommerce_product_single_add_to_cart_text', 'exploretech_change_woocommerce_custom_add_to_cart_text', 11, 2);
function exploretech_change_woocommerce_custom_add_to_cart_text($text, $product) {
if ('31' ==$product->get_id()) {
return 'Customized Text';
}
$product_categories = $product->get_category_ids();
if (in_array('19', $product_categories)) {
//if product has category with id=19 (say Tshirts)
return 'ExploreTech Customized Text';
}
return $text;
}
xxxxxxxxxx
add_filter( 'wc_add_to_cart_message_html', 'exploretech_custom_add_to_cart_message_html' );
function exploretech_custom_add_to_cart_message_html() {
$ext_custom_message = "You have successfully added the product, thanks for shopping with us";
return $ext_custom_message;
}
xxxxxxxxxx
// To change add to cart text on single product page
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woocommerce_custom_single_add_to_cart_text' );
function woocommerce_custom_single_add_to_cart_text() {
return __( 'Buy Now', 'woocommerce' );
}
// To change add to cart text on product archives(Collection) page
add_filter( 'woocommerce_product_add_to_cart_text', 'woocommerce_custom_product_add_to_cart_text' );
function woocommerce_custom_product_add_to_cart_text() {
return __( 'Buy Now', 'woocommerce' );
}
xxxxxxxxxx
add_filter( 'gettext', 'change_cart_totals_text', 20, 3 );
function change_cart_totals_text( $translated, $text, $domain ) {
if( is_cart() && $translated == 'Cart totals' ){
$translated = __('Your custom text', 'woocommerce');
}
return $translated;
}
xxxxxxxxxx
add_filter('woocommerce_product_single_add_to_cart_text', 'exploretech_change_woocommerce_custom_add_to_cart_text', 11, 2);
function exploretech_change_woocommerce_custom_add_to_cart_text($text, $product) {
return "My Custom Text";
}
xxxxxxxxxx
add_action( 'woocommerce_before_add_to_cart_button', 'misha_before_add_to_cart_btn' );
function misha_before_add_to_cart_btn(){
echo 'Some custom text here';
}
with the help of the code below you will be able to replace the add to cart button on single product pages.
xxxxxxxxxx
function hwn_remove_add_to_cart_using_remove_action(){
global $product;
$tshirt_with_logo_product_id = 32;
if ($product->get_id() == $tshirt_with_logo_product_id) {
add_action('woocommerce_single_product_summary','hwn_text_to_replace_add_to_cart_button',31 );
}
}
function hwn_text_to_replace_add_to_cart_button(){
echo "This product can not currently be purchased via our online store, please contact us for more details.";
}
add_action('woocommerce_single_product_summary', 'hwn_remove_add_to_cart_using_remove_action', 2 );
function hwn_remove_add_to_cart_using_is_purchasable($product_purchasable,$product) {
$tshirt_with_logo_product_id = 32;
if( $product->get_id() == $tshirt_with_logo_product_id ) {
return false;
}
return $product_purchasable;
}
add_filter('woocommerce_is_purchasable', 'hwn_remove_add_to_cart_using_is_purchasable',10,2);
xxxxxxxxxx
add_filter('woocommerce_product_add_to_cart_text', 'exploretech_change_woocommerce_custom_add_to_cart_text', 11, 2);
function exploretech_change_woocommerce_custom_add_to_cart_text($text, $product) {
return "My Custom Text";
}
xxxxxxxxxx
add_filter('woocommerce_product_single_add_to_cart_text', 'exploretech_change_woocommerce_custom_add_to_cart_text', 11, 2);
function exploretech_change_woocommerce_custom_add_to_cart_text($text, $product) {
$extech_product_type = $product->get_type();
if ('simple' == $extech_product_type) {
return "Simple Product";
}
if ('variable' == $extech_product_type) {
return 'Variable Product';
}
return $text;
//You can also do this with switch statement
}
xxxxxxxxxx
// Add this code in wpcode snippets plugin
<?php
add_filter( 'woocommerce_product_single_add_to_cart_text', 'custom_add_to_cart_button_text' );
add_filter( 'woocommerce_product_add_to_cart_text', 'custom_add_to_cart_button_text' );
function custom_add_to_cart_button_text( $text ) {
global $product;
$text = "Contact Us";
return $text;
}
add_filter( 'woocommerce_add_to_cart_redirect', 'custom_add_to_cart_redirect' );
function custom_add_to_cart_redirect() {
return 'https://yourdomain.com/contact-us';
}
?>