Skip to content

Instantly share code, notes, and snippets.

@frankschrijvers
Last active July 17, 2021 04:07
Show Gist options
  • Save frankschrijvers/2575f5f662de313a639b2dcfa890d36c to your computer and use it in GitHub Desktop.
Save frankschrijvers/2575f5f662de313a639b2dcfa890d36c to your computer and use it in GitHub Desktop.
Set WooCommerce product button text to productname
<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.
add_filter( 'woocommerce_product_single_add_to_cart_text', 'wps_custom_cart_button_text' );
/**
* Set product button text to productname
*/
function wps_custom_cart_button_text() {
global $product;
$id = get_the_ID();
$title = get_the_title( $id );
return __( 'buy ' . $title, 'your_theme_text_domain' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment