Add a popup notice on woocommerce checkout and cart page

Viewed 292

I would like to add a popup when the customer is less that $100 if zone is Australia and $250 if somewhere else

This is the code I am testing at the moment

add_action( 'woocommerce_cart_totals_after_shipping' , 'skyverge_add_checkout_content' );
add_action( 'woocommerce_review_order_after_shipping' , 'skyverge_add_checkout_content' );

function skyverge_add_checkout_content() {

    
    $targeted_zones_names = array('Australia'); // <======  <======  <======  <======  <======  

    // Get the customer shipping zone name
    $chosen_methods    = WC()->session->get( 'chosen_shipping_methods' ); // The chosen shipping mehod
    $chosen_method     = explode(':', reset($chosen_methods) );
    $shipping_zone     = WC_Shipping_Zones::get_zone_by( 'instance_id', $chosen_method[1] );
    $current_zone_name = $shipping_zone->get_zone_name();

    if ( $current_zone_name == 'Australia' ) {
        $min_amount = 100;
    } else {
        $min_amount = 250;
    }

    $current = WC()->cart->subtotal;

    if ( $current < $min_amount ) {
        $added_text = 'We are delighted to offer free global shipping for orders '.wc_price( $min_amount ).' or more. Would you like to add more to your cart?';
        //$added_text = 'Get free shipping if you order ' . wc_price( $min_amount - $current ) . ' more!';
        $return_to = wc_get_page_permalink( 'shop' );
        $notice = sprintf( '<a href="%s" class="button wc-forward">%s</a> %s', esc_url( $return_to ), 'Continue Shopping', $added_text );
        wc_print_notice( $notice, 'notice' );
    }    

}

This runs fine on the default woocommerce error notice/alert but I want it to popout

I think some of the code belongs to @LoicTheAztec and I just modified it

0 Answers
Related