Last active
December 20, 2016 12:04
-
-
Save Farmatique/a82e1c25b242a402d5b685f6ae55be30 to your computer and use it in GitHub Desktop.
Wordpress change add-to-cart button in woocommerce
This file contains hidden or 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
function custom_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' ); | |
} | |
} | |
add_filter( 'woocommerce_loop_add_to_cart_link', 'custom_add_product_link' ); | |
function custom_add_product_link( $link ) { | |
global $product; | |
$product_id = $product->id; | |
$product_sku = $product->get_sku(); | |
$link = '<a href="'.get_site_url().'/shop/?add-to-cart='.$product_id.'" rel="nofollow" data-product_id="'.$product_id.'" data-product_sku="'.$product_sku.'" data-quantity="1" class="button add_to_cart_button product_type_simple">'.custom_woocommerce_product_add_to_cart_text().'</a>'; | |
return $link; | |
} | |
// from https://surefirewebservices.com/change-add-cart-link-text-woocommerce-archive-page/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment