在woocommerce结帐和购物车页面上添加弹出通知

时间:2021-06-10 06:21:51

标签: php wordpress woocommerce hook-woocommerce

如果客户在澳大利亚地区低于 100 美元,如果在其他地方低于 250 美元,我想添加一个弹出窗口

这是我目前正在测试的代码

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' );
    }    

}

这在默认的 woocommerce 错误通知/警报上运行良好,但我希望它弹出

我认为某些代码属于@LoicTheAztec,我只是对其进行了修改

0 个答案:

没有答案