Skip to main content

Change Rendered Text for (Add to Cart, Price (Prefix/Suffix), Update Total)

// CUSTOM ADD TO CART BUTTON
add_filter( 'woocommerce_product_add_to_cart_text', 'custom_add_to_cart_price', 20, 2 ); // Shop and other archives pages
add_filter( 'woocommerce_product_single_add_to_cart_text', 'custom_add_to_cart_price', 20, 2 ); // Single product pages
function custom_add_to_cart_price( $button_text, $product ) {
    // Variable products
    if( $product->is_type('variable') ) {
        // shop and archives
        if( ! is_product() ){
            $product_price = wc_price( wc_get_price_to_display( $product, array( 'price' => $product->get_variation_price() ) ) );
            return $button_text . ' - From ' . strip_tags( $product_price );
        } 
        // Single product pages
        else {
            return $button_text;
        }
    } 
    // All other product types
    else {
        $product_price = wc_price( wc_get_price_to_display( $product ) );
        return 'BUY THIS ITEM FOR ' . strip_tags( $product_price );
    }
}
#region ADD SUFFIX/PREFIX TO PRICES
// https://www.businessbloomer.com/woocommerce-add-prefix-suffix-product-prices/
// Adds Suffix to WooCommerce prices
/**
 * @snippet       Adds suffix to WooCommerce prices
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 3.8
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
add_filter('woocommerce_get_price_suffix', 'bbloomer_add_price_suffix', 99, 4);
function bbloomer_add_price_suffix($html, $product, $price, $qty)
{
    $html .= ' suffix here';
    return $html;
}
// Adds prefix to WooCommerce prices
/**
 * @snippet       Adds prefix to WooCommerce prices
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 3.8
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
add_filter('woocommerce_get_price_html', 'bbloomer_add_price_prefix', 99, 2);
function bbloomer_add_price_prefix($price, $product)
{
    $price = 'Prefix here ' . $price;
    return $price;
}
#endregion
#region CHANGE TEXT 'Update totals' text on cart page to Recalculate Shipping
add_filter('gettext', 'woocomerce_text_strings', 20, 3);
function woocomerce_text_strings($translated_text, $text, $domain)
{
    switch ($translated_text) {
        case 'Update totals':
            $translated_text = __('Recalculate Shipping', 'woocommerce');
            break;
    }
    return $translated_text;
}
#endregion