• Zdravím Vás. Rie?im dilemu, ke? mám aj nadrozmerny tovar, ktory packeta nezoberie (presahuje rozmery). Takéto produkty ozna?ujem product tagom “Nadrozmerné” a v takom prípade chcem skry? mo?nosti doru?i? Packetou. Pou?ívam na to php snippet

    add_filter('woocommerce_package_rates', 'shipping_based_on_country_subtotal_and_free_available', 100, 2);
    function shipping_based_on_country_subtotal_and_free_available($rates, $package)
    {
        //var_dump($rates);
    
        $free = array();
        $condition = false;
    
        foreach (WC()->cart->get_cart() as $cart_item) {
            $product_id = $cart_item['product_id'];
    
            if (has_tag(30, $product_id)) {
                $condition = true;
                break;
            }
        }
    
        // Loop through shipping rates for current shipping package
        foreach ($rates as $rate_key => $rate) {
            if ($condition) {
                $targeted_rate_id = 'packetery_carrier_zpointcz';
    
                if ($targeted_rate_id === $rate_key) {
                    unset($rates[$targeted_rate_id]);
                }
            } 
        }
        return $rates;
    }

    Bohu?ia?, tento snippet nefunguje, dokonca mám pocit, ?e Packeta sa nespráva ako be?ná shipping method, ale ako nie?o iné. Vedeli by ste mi poradi?, ako túto vec viem dosiahnu??

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support kovalmatyas

    (@kovalmatyas)

    Dobry den,
    v následující verzi na?eho pluginu (1.3.3), vyjde funkcionalita p?ímo v na?em pluginu, která bude toto umo?ňovat.
    Bude mo?né u jednotlivych produkt? nastavovat to, ?e se ur?ité p?epravní mo?nosti v rámci na?eho pluginu nebudou zobrazovat.
    Nebude tedy nutné vyu?ívat vlastní filtr.

    S pozdravem,
    Matyá? Kova? – Zásilkovna E-Commerce Support

    Zdravím, super. Ja som si u? ten filter spravil. Problém bol v priorite na danom hooku, trebalo nastavi? vy??iu + tro?ku prerobi? kód. V kone?nom d?sledku mám toto a funguje

    add_filter('woocommerce_package_rates', 'shipping_based_on_country_subtotal_and_free_available', 9999999999, 2);
    function shipping_based_on_country_subtotal_and_free_available($rates, $package)
    {
        $condition = false;
    
        foreach (WC()->cart->get_cart() as $cart_item) {
            $product_id = $cart_item['product_id'];
    
            if (has_term( 30, 'product_tag', $product_id)) {
                $condition = true;
                
            }
        }
    
        // Loop through shipping rates for current shipping package
        foreach ($rates as $rate_key => $rate) {
            if ($condition) {
                $targeted_rate_id = array(
    				'packetery_carrier_zpointcz',
    				'packetery_carrier_106',
    				'packetery_carrier_zpointsk'
    			);
    			
    			if(in_array($rate_key,$targeted_rate_id)) {
                    unset($rates[$rate_key]);
                }
            } 
        }
    	
        return $rates;
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Packeta sa nespráva ako be?ny shipping?’ is closed to new replies.