Advertisement
nshelper

Untitled

Feb 16th, 2024
845
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.59 KB | None | 0 0
  1.  
  2.     public function custom_woocommerce_get_cart_contents( $cart_contents ) {
  3.         //return $cart_contents;
  4.         foreach ( $cart_contents as $key => $cart_item ) {
  5.             do_action( 'woocommerce/cart_loop/start', $cart_item );
  6.             $product_id                = isset( $cart_item['variation_id'] ) && $cart_item['variation_id'] ? $cart_item['variation_id'] : $cart_item['product_id'];
  7.             $_product                  = wc_get_product( $product_id );
  8.             $product_price             = $_product->get_price( 'edit' );
  9.             $product_price_by_currency = YayCurrencyHelper::calculate_price_by_currency( $product_price, false, $this->apply_currency );
  10.             $product_price_by_currency = FixedPriceHelper::get_price_fixed_by_apply_currency( $_product, $product_price_by_currency, $this->apply_currency );
  11.  
  12.             if ( isset( $cart_item['subscription_renewal'] ) ) {
  13.                 $order_id       = $cart_item['subscription_renewal']['renewal_order_id'];
  14.                 $order_currency = YayCurrencyHelper::get_order_currency_by_order_id( $order_id, $this->converted_currency );
  15.                 if ( $order_currency ) {
  16.                     $currency_code = $order_currency['currency'];
  17.                     if ( $this->default_currency != $currency_code && ( $currency_code != $this->apply_currency['currency'] || YayCurrencyHelper::disable_fallback_option_in_checkout_page( $this->apply_currency ) ) ) {
  18.                         $cart_contents[ $key ]['data']->subscription_renewal_price_original         = $product_price_by_currency;
  19.                         $cart_contents[ $key ]['data']->subscription_renewal_price_original_default = $product_price;
  20.                     }
  21.                     $cart_contents[ $key ]['data']->subscription_renewal_price_currency = $currency_code;
  22.                 }
  23.             }
  24.  
  25.             if ( isset( $cart_item['subscription_resubscribe'] ) ) {
  26.                 $order_id       = $cart_item['subscription_resubscribe']['subscription_id'];
  27.                 $order_currency = YayCurrencyHelper::get_order_currency_by_order_id( $order_id, $this->converted_currency );
  28.                 if ( $order_currency ) {
  29.                     $currency_code = $order_currency['currency'];
  30.                     if ( $this->default_currency != $currency_code && ( $currency_code != $this->apply_currency['currency'] || YayCurrencyHelper::disable_fallback_option_in_checkout_page( $this->apply_currency ) ) ) {
  31.                         $cart_contents[ $key ]['data']->subscription_resubscribe_price_original         = $product_price_by_currency;
  32.                         $cart_contents[ $key ]['data']->subscription_resubscribe_price_original_default = $product_price;
  33.                     }
  34.                     $cart_contents[ $key ]['data']->subscription_resubscribe_price_currency = $currency_code;
  35.                 }
  36.             }
  37.             do_action( 'woocommerce/cart_loop/end', $cart_item );
  38.         }
  39.         return $cart_contents;
  40.     }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement