Rumah  >  Soal Jawab  >  teks badan

Hapuskan pemberitahuan dalam WooCommerce yang menyatakan "Daftar keluar tidak boleh dilakukan apabila troli kosong".

Apakah kod yang perlu saya tambahkan functions.php untuk mengalih keluar "Tidak boleh daftar keluar apabila troli kosong". Pemberitahuan dalam Woocommerce.

Saya menjumpai kod yang bertanggungjawab untuk memaparkan mesej ini dalam includes/wc-template-functions.php.

// When on the checkout with an empty cart, redirect to cart page.
if ( is_page( wc_get_page_id( 'checkout' ) ) && wc_get_page_id( 'checkout' ) !== wc_get_page_id( 'cart' ) && WC()->cart->is_empty() && empty( $wp->query_vars['order-pay'] ) && ! isset( $wp->query_vars['order-received'] ) && ! is_customize_preview() && apply_filters( 'woocommerce_checkout_redirect_empty_cart', true ) ) {
    wc_add_notice( __( 'Checkout is not available whilst your cart is empty.', 'woocommerce' ), 'notice' );
    wp_safe_redirect( wc_get_cart_url() );
    exit;

}

Menulis ganti fail teras bukan pilihan, ada cadangan?

P粉336536706P粉336536706307 hari yang lalu895

membalas semua(1)saya akan balas

  • P粉561438407

    P粉5614384072023-11-18 09:39:55

    Anda boleh menggunakan woocommerce_checkout_redirect_empty_cartTapis cangkuk. Memandangkan mesej hanya akan dipaparkan jika syarat ini benar

    add_filter( 'woocommerce_checkout_redirect_empty_cart', '__return_false' );
    

    Pilihan lain ialah menggunakan woocommerce_add_notice cangkuk penapis yang mengembalikan palsu jika mesej sepadan

    function filter_woocommerce_add_notice ( $message ) {
        // Equal to (Must be exactly the same).
        // If the message is displayed in another language, adjust where necessary!
        if ( $message == 'Checkout is not available whilst your cart is empty.' ) {
            return false;
        }   
        
        return $message;
    }
    add_filter( 'woocommerce_add_notice', 'filter_woocommerce_add_notice', 10, 1 );
    

    balas
    0
  • Batalbalas