hooks in checkout page not working

  • Unknown's avatar

    I am using a snippet code to display a message telling customers how much they need to spend to get free delivery. The code works on the single product page but not on the checkout page. I am assuming something wrong with the hook, any suggestions how I could solve this issue?

    The code:

    add_action( ‘woocommerce_single_product_summary’, ‘single_product_page_notice’, 6 );
    add_action( ‘woocommerce_before_checkout_form’, ‘checkout_notice’, 10 ); // Added priority 10

    function single_product_page_notice() {
    $min_amount = 300; // Adjust this threshold according to your free shipping settings
    $current = WC()->cart->subtotal;

    if ( $current < $min_amount ) {
    $remaining_amount = wc_price( $min_amount – $current );
    $message = sprintf( 'Buy %s worth of products more to get free shipping.', $remaining_amount );
    $shop_url = esc_url( wc_get_page_permalink( 'shop' ) );
    $notice = sprintf( '%s %s’, $message, $shop_url, ‘Continue shopping’ );
    echo $notice;
    }
    }

    function checkout_notice() {
    $min_amount = 300; // Adjust this threshold according to your free shipping settings
    $current = WC()->cart->subtotal;

    if ( $current < $min_amount ) {
    $remaining_amount = wc_price( $min_amount – $current );
    $message = sprintf( 'Add %s worth of products more to your cart for free shipping.', $remaining_amount );
    $checkout_url = esc_url( wc_get_page_permalink('checkout') );
    $notice = sprintf( '%s %s’, $message, $checkout_url, ‘Continue shopping’ );
    echo $notice;
    }
    }

    WP.com: Yes
    Jetpack: Yes
    Correct account: Yes

    The blog I need help with is: (visible only to logged in users)

  • Hi there,

    Thanks for reaching out! The WooCommerce Team will be best suited to assist you with this issue. Since you have WooCommerce installed on a WordPress.com Business Plan or have a paid WooCommerce extension on a self-hosted site, you can either start a live chat session or open a ticket while logged into your account at:

    https://woocommerce.com/contact-us/

    They’ll try to get to your inquiry as soon as possible.

    Thanks!

  • The topic ‘hooks in checkout page not working’ is closed to new replies.