Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hmbashar/c3c458c08f5ed97b0a346cd5b945305a to your computer and use it in GitHub Desktop.
Save hmbashar/c3c458c08f5ed97b0a346cd5b945305a to your computer and use it in GitHub Desktop.
woocommerce add to card text change with multi language
/**
* 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