Skip to content

Commit

Permalink
improve shipping calc
Browse files Browse the repository at this point in the history
  • Loading branch information
luizbills committed Mar 8, 2023
1 parent 533b7f3 commit 808ed30
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions classes/Shipping_Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function get_package () {
}

public function calculate_shipping () {
$wc_shipping = WC()->shipping;
$wc_shipping = WC()->shipping();

// backup the current WC_Shipping::packages
$original_shipping_packages = $wc_shipping->packages;
Expand Down Expand Up @@ -157,22 +157,20 @@ public function calculate_shipping () {
public function modify_cart_info () {
$cart = WC()->cart;
$this->original_cart_info = [
'cart_contents_total' => $cart->cart_contents_total,
'cart_contents' => $cart->cart_contents,
'subtotal_ex_tax' => $cart->subtotal_ex_tax,
'subtotal' => $cart->subtotal,
'cart_contents' => $cart->get_cart_contents(),
'cart_contents_total' => $cart->get_cart_contents_total(),
'subtotal' => $cart->get_subtotal(),
];
$cart->cart_contents_total = $this->package['contents_cost'];
$cart->cart_contents = $this->package['contents'];
$cart->subtotal_ex_tax = $this->package['contents_cost'];
$cart->subtotal = $this->package['contents_cost'];
$cart->set_cart_contents( $this->package['contents' ]);
$cart->set_cart_contents_total( $this->package['contents_cost'] );
$cart->set_subtotal( $this->package['contents_cost'] );
}

public function restore_cart_info () {
if ( 0 === count( $this->original_cart_info ) ) return;
$cart = WC()->cart;
foreach ( $this->original_cart_info as $prop => $value ) {
$cart->$prop = $value;
$cart->{'set_' . $prop}( $value );
unset( $this->original_cart_info[ $prop ] );
}
}
Expand Down

0 comments on commit 808ed30

Please sign in to comment.