Created
May 22, 2021 23:43
-
-
Save hmbashar/c3c458c08f5ed97b0a346cd5b945305a to your computer and use it in GitHub Desktop.
woocommerce add to card text change with multi language
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* custom_woocommerce_template_loop_add_to_cart | |
*/ | |
add_filter( 'woocommerce_product_add_to_cart_text' , 'custom_woocommerce_product_add_to_cart_text' ); | |
function custom_woocommerce_product_add_to_cart_text() { | |
global $product; | |
$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; | |
$text = "View Product"; | |
if (preg_match('/en/', $url)) { | |
$text = "View details"; | |
} elseif (preg_match('/it/', $url)) { | |
$text = "Vedi i dettagli"; | |
} | |
$product_type = $product->product_type; | |
switch ( $product_type ) { | |
case 'external': | |
return __( $text, 'woocommerce' ); | |
break; | |
case 'grouped': | |
return __( $text, 'woocommerce' ); | |
break; | |
case 'simple': | |
return __( $text, 'woocommerce' ); | |
break; | |
case 'variable': | |
return __( $text, 'woocommerce' ); | |
break; | |
default: | |
return __( $text, 'woocommerce' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment