Last active
November 12, 2020 11:24
-
-
Save scgoeswild/bc48b7f44949c9d50cf2453087fdaad2 to your computer and use it in GitHub Desktop.
Change the Add To Cart Link and Text on WooCommerce Archive Page
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
<?php | |
//* Change the Add To Cart Link | |
add_filter( 'woocommerce_loop_add_to_cart_link', 'sfws_add_product_link' ); | |
function sfws_add_product_link( $link ) { | |
global $product; | |
$product_id = $product->id; | |
$product_sku = $product->get_sku(); | |
$link = '<a href="'.get_permalink().'" rel="nofollow" data-product_id="'.$product_id.'" data-product_sku="'.$product_sku.'" data-quantity="1" class="button add_to_cart_button product_type_variable">'.sfws_woocommerce_product_add_to_cart_text().'</a>'; | |
return $link; | |
} | |
?> |
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
<?php | |
//* Change Add To Cart to Select Options | |
//add_filter( 'woocommerce_product_add_to_cart_text' , 'sfws_woocommerce_product_add_to_cart_text' ); | |
function sfws_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' ); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment