Created
June 19, 2015 04:15
-
-
Save slash1andy/e69d5a68c205129b8cdd to your computer and use it in GitHub Desktop.
WooCommerce Change Add to Cart Link and Text
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
//* Change the Add to Cart Text | |
add_filter( 'woocommerce_product_add_to_cart_text' , 'woo_woocommerce_product_add_to_cart_text' ); | |
function woo_woocommerce_product_add_to_cart_text() { | |
global $product; | |
$product_type = $product->product_type; | |
switch ( $product_type ) { | |
case 'external': | |
return __( 'Buy product', 'woocommerce' ); | |
break; | |
case 'grouped': | |
return __( 'View products', 'woocommerce' ); | |
break; | |
case 'simple': | |
return __( 'Select Options', 'woocommerce' ); | |
break; | |
case 'variable': | |
return __( 'Select options', 'woocommerce' ); | |
break; | |
default: | |
return __( 'Read more', 'woocommerce' ); | |
} | |
} | |
//* Change the Add To Cart Link | |
add_filter( 'woocommerce_loop_add_to_cart_link', 'woo_add_product_link' ); | |
function woo_add_product_link( $link ) { | |
global $product; | |
$product_id = $product->id; | |
$product_sku = $product->get_sku(); | |
$link = '<a href="'.get_permalink().'" data-product_id="'.$product_id.'" data-product_sku="'.$product_sku.'" data-quantity="1" class="button add_to_cart_button product_type_variable">'.woo_woocommerce_product_add_to_cart_text().'</a>'; | |
return $link; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment