show wc_add notices on particular page in woo commerce custom plugin development

Question

I am new WordPress plugin development. I am working on a plugin where I create a custom cart page like the woo commerce cart. And I add wc add notice when an item removes from the cart page it shows a notice on this page as well as when I refresh shop show on the shop/arched page also.I don’t know how to handle it. Sorry for the bad English and Thank You in advance.

            public function WhatsApp_cart_page_setting1() {
        if ( empty( WC()->session->get( 'WhatsApp_cart' ) ) ) {
            return;
        }
        if ( isset( $_GET['index_to_remove'] ) ) {
            $index        = sanitize_text_field( wp_unslash( $_GET['index_to_remove'] ) );
            $cart_session = WC()->session->get( 'WhatsApp_cart' );
            unset( $cart_session[ $index ] );
            WC()->session->set( 'WhatsApp_cart', $cart_session );
            $page = get_page_by_path( 'whatsapp-cart' );

            global $post;

            $whatsapp_slug = $post->post_name;
            if ( $whatsapp_slug === 'whatsapp-cart' ) {
                            wc_add_notice( 'Item removed from whatsapp cart successfully', 'success' );
            }
        }
        ?>
0
Fakhar alam 4 months 0 Answers 11 views 0

Leave an answer