Skip to content

Instantly share code, notes, and snippets.

@WPprodigy
Last active December 25, 2019 05:29
Show Gist options
  • Select an option

  • Save WPprodigy/11769a6104b663a2fe609321e00fdd0b to your computer and use it in GitHub Desktop.

Select an option

Save WPprodigy/11769a6104b663a2fe609321e00fdd0b to your computer and use it in GitHub Desktop.
Change add to cart url and text for simple products.
add_filter( 'woocommerce_product_add_to_cart_url', 'wc_ninja_edit_add_to_cart_url', 10, 2 );
function wc_ninja_edit_add_to_cart_url( $url, $product ) {
if ( 'simple' === $product->get_type() ) {
$url = $product->get_permalink();
}
return $url;
}
add_filter( 'woocommerce_product_add_to_cart_text', 'wc_ninja_edit_add_to_cart_text', 10, 2 );
function wc_ninja_edit_add_to_cart_text( $text, $product ) {
if ( 'simple' === $product->get_type() ) {
$text = __( 'Select options', 'woocommerce' );
}
return $text;
}
@WPprodigy

WPprodigy commented Jan 2, 2018

Copy link
Copy Markdown
Author

Will need to disable the "Enable AJAX add to cart buttons on archives" option at WooCommerce > Settings > Products > Display.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment