Вопрос

I'm trying to create a new shipping method for woocommerce. So i created a plugin as suggested. I'm trying to get the product dimensions height, width, length, weight, and besides the destination city. For now i'm stack in the dimensions, that it's the product variations for what i've read. But I tried to do the following but they seem to be empty.

So I have this in the calculate_shipping function:

foreach ( $woocommerce->cart->get_cart() as $item_id => $values ) {

            $_product = $values['data'];
            //debug: $firephp->log($_product, 'Iterators0');

            $_variation_id = $values['variation_id'];
            //debug: $firephp->log($_variation_id, 'Iterators1');

            $_variation = $values['variation'];
            //debug: $firephp->log($_variation, 'Iterators2');

            if ( $values['quantity'] > 0 && $_product->needs_shipping() ) {
                //my calculation
                $shipping_total += $this->fee * $values['quantity'];
            }
 }

Any help will be appreciated.

Thanks, Gary

Нет правильного решения

Другие советы

Try this , it should return that value of the weight. You can then adapt it for the other values you wanting to get.

foreach ( $woocommerce->cart->get_cart() as $item_id => $values ) {

            $_product = $values['data'];
            $weight = $_product->weight;

            }
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top