0

I want to add in the product page and archive, the text "free shipping" for products that have at least a certain price (say $ 49) free delivery, to later stylize it from css. I did this, but it doesn't work. Whoever gives me a helping hand, please, and if he has time, he can explain to me what I'm doing wrong, short.

add_action( 'woocommerce_before_shop_loop_item_title', 'single_product_label', 10, 1 );
function single_product_label() {

    if ( is_product() || is_shop() || is_product_category() || is_product_tag() ):
        global $post, $product;
                
        if ( $price >= 49  ) {
    if ( empty( $product->get_shipping_class() ) ) {
        echo '<span class="freshipp">FREE SHIPPING</span>';
      endif;
    }
  }

Best regards.

atto
  • 13
  • 2
  • Yes, I know about that, but it doesn't work for me. Although I changed the hooks. add_action( 'woocommerce_before_shop_loop_item_title', 'single_product_label', 10, 1 ); – atto Jan 29 '22 at 10:22
  • I tried that code, and made several changes trying to make it work for the storefront, but I couldn't. My knowledge is limited in php and I do not know how to find the right solution. Can anyone please help me? Can anyone adapt the code for standard hooks? Thanks. – atto Feb 01 '22 at 13:36
  • This code partially works. But it looks for all prices / products. – atto Feb 01 '22 at 13:53
  • add_action( 'woocommerce_single_product_summary', 'custom_single_product_summary_text', 15 ); function custom_single_product_summary_text() { global $product; $price_threshold = 49; if( $product->is_type('variable') ) { $price = $product->get_variation_price( 'min', true ); } else { $price = wc_get_price_to_display( $product ); } if ( $price < $price_threshold ) { $message = __("FREE SHIPPING", "text_domain"); } echo '

    ' . $message . '

    '; }
    – atto Feb 01 '22 at 13:54

0 Answers0