Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // WooCommerce - Show price on add-to-cart button
- // credit for most of it: LoicTheAztec
- 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. ' - From ' . $product->get_variation_price( 'min' );
- }
- }
- // all other product types
- else {
- $product_price = wc_price( wc_get_price_to_display( $product ) );
- return $button_text . ' - Just ' . strip_tags( $product_price );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement