0

I need your help. I find this one to add a price directly on the 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 $button_text . ' - Just ' . strip_tags( $product_price );
    }
}

Good snippet. It works. How can I exclude specific product? 'Cause with YITH Gift Cards, it display just "Add to card - 0€".

Or, how can I display variation price with "Yith Gift Card" when customer choose specific price or enter it manually?

The simplest will be to hide price, but it will be cool that the price change directly on the button.

Source: Display price on add to cart button from the functions.php file in Woocommerce

Thank's for your help.

Dam's
  • 11
  • Can you be more specific about what the issue is? See [ask], [help/on-topic]. – AMC Apr 10 '20 at 23:17
  • @AMC yes. With this snippet, the price is displayed in the add to cart button product pages and others. (Add to Cart - 12€). Unfortunatly, it does'nt work with the Yith plugin "Gift Card". If I choose a predifined price (like 10€ - 20€ - 30€,...) or entered manually (like 12,50€), the price doesn't display in the cart button (Add to Cart - 0€) – Dam's Apr 12 '20 at 05:56

0 Answers0