• Resolved mic85b

    (@mic85b)


    Can somebody tell me why variable $czypokazywacpopupkoszykowy which is set to 1 in function “businessbloomer_hide_free_shipping_for_shipping_class()” dosn’t have value 1 in “function wyswietl_popup_koszyka_i_kasy()”? It has still value 0 wich is set in first line of code.

    <?php
    global czypokazywacpopupkoszykowy;
    $czypokazywacpopupkoszykowy = 0;
    
    add_action( 'wp_enqueue_scripts', 'porto_child_css', 1001 );
    
    
    
    
    
    // Load CSS
    function porto_child_css() {
    	// porto child theme styles
    	wp_deregister_style( 'styles-child' );
    	wp_register_style( 'styles-child', esc_url( get_stylesheet_directory_uri() ) . '/style.css' );
    	wp_enqueue_style( 'styles-child' );
    
    	if ( is_rtl() ) {
    		wp_deregister_style( 'styles-child-rtl' );
    		wp_register_style( 'styles-child-rtl', esc_url( get_stylesheet_directory_uri() ) . '/style_rtl.css' );
    		wp_enqueue_style( 'styles-child-rtl' );
    	}
    }
    
    
    
    add_filter( 'woocommerce_package_rates', 'businessbloomer_hide_free_shipping_for_shipping_class', -12, 2 );
    function businessbloomer_hide_free_shipping_for_shipping_class( $rates, $package ) {
    
        $shipping_class_target = 30;           // ID OF MY SHIPPING_CLASS
        $in_cart = false;
        foreach( WC()->cart->cart_contents as $key => $values ) {
            if( $values[ 'data' ]->get_shipping_class_id() == $shipping_class_target ) {
                $in_cart = true;
                break;
            } 
        }
        if( $in_cart ) {
            unset( $rates['inpost_paczkomaty:11'] );     //VALUE:ID OF MY SHIPPING METHOD
    		$czypokazywacpopupkoszykowy = 1;
        }
        return $rates;
    
    }
    
    
    
    
    add_action('wp_footer', 'wyswietl_popup_koszyka_i_kasy',9999);
    function wyswietl_popup_koszyka_i_kasy() {
    
    
    // Pobierz zmienn? $czypokazywacpopupkoszykowy korzystaj?c z filtra
    global $czypokazywacpopupkoszykowy;
    
    
    echo "zzz" .     $czypokazywacpopupkoszykowy;
    
         if ((is_cart() && $czypokazywacpopupkoszykowy == 1) || (is_checkout()) && $czypokazywacpopupkoszykowy == 1) { // Wy?wietlamy popup na stronie koszyka i kasy
    
    
    			$show_popup = true;
    
    
            if (isset($_COOKIE['popup_closed']) && $_COOKIE['popup_closed'] == 'true') {
                $show_popup = false;
            }
    
            if ($show_popup) {
                ?>
                <div id="custom-cart-popup" class="cart-popup">
                    <div class="popup-content">
                        <p>W koszyku znajduje si? co najmniej jeden produkt, który mo?na odebra? jedynie osobi?cie. Je?li chcesz z?o?y? zamówienie z opcj? wysy?ki pozostaw w koszyku jedynie produkty, które podlegaj? wysy?ce.</p>
                        <a href="#" id="close-popup" class="close-popup">Zamknij</a>
                    </div>
                </div>
    
                <style>
                    /* Stylizacja popupa */
                    .cart-popup {
                        display: none;
                        position: fixed;
                        top: 0;
                        left: 0;
                        width: 100%;
                        height: 100%;
                        background: rgba(0, 0, 0, 0.8);
                        z-index: 999;
                    }
    
                    .popup-content {
                        position: absolute;
                        top: 50%;
                        left: 50%;
                        transform: translate(-50%, -50%);
                        background: #fff;
                        padding: 20px;
    
                        box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
                        text-align: center;
                    }
    
                    .close-popup {
                        display: inline-block;
                        margin-top: 10px;
                        padding: 10px 20px;
                        background: #000000;
                        color: #ffffff;
                        text-decoration: none;
    
                    }
                </style>
    
                <script type="text/javascript">
                    jQuery(document).ready(function($) {
                        // Wy?wietlanie popupa na stronie koszyka i kasy po 60 sekundach
                        setTimeout(function() {
                            $('#custom-cart-popup').fadeIn();
                        }, 1000);
    
                        // Obs?uga zamkni?cia popupu
                        $('#close-popup').on('click', function(e) {
                            e.preventDefault();
                            $('#custom-cart-popup').fadeOut();
                            // Ustawiamy ciasteczko, aby nie wy?wietla? popupa ponownie przez 60 sekund
                            document.cookie = 'popup_closed=true; expires=' + new Date(new Date().getTime() + 120000).toUTCString() + '; path=/';
                        });
                    });
                </script>
                <?php
            }
        }
    }
    
    
    
    

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter mic85b

    (@mic85b)

    I have add “global $czypokazywacpopupkoszykowy;” to function

    businessbloomer_hide_free_shipping_for_shipping_class() 

    but still no effect.

    • This reply was modified 1 year ago by mic85b.
    Thread Starter mic85b

    (@mic85b)

    Nobody help me? ??

    anastas10s

    (@anastas10s)

    Hi there @mic85b ??

    Welcome to WooCommerce Support. I’d be happy to help you with this.

    Can somebody tell me why variable $czypokazywacpopupkoszykowy which is set to 1 in function “businessbloomer_hide_free_shipping_for_shipping_class()” dosn’t have value 1 in “function wyswietl_popup_koszyka_i_kasy()”? It has still value 0 wich is set in first line of code.

    This is best for inquiring at the page here, since businessbloomer_hide_free_shipping_for_shipping_class() was published there.

    Furthermore, there is no reference of czypokazywacpopupkoszykowy in the source code of WooCommerce core, and I could not find any further reference about it online, I’m afraid.

    I trust that points you in the right direction, but if you have more questions, let us know.

    We’re happy to help.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Global variable, add_filter and add_action’ is closed to new replies.