PATH:
home
/
lab2454c
/
mact34.com
/
wp-content
/
plugins
/
woocommerce
/
includes
<?php /** * Order Line Item (shipping) * * @package WooCommerce\Classes * @version 3.0.0 * @since 3.0.0 */ defined( 'ABSPATH' ) || exit; /** * Order item shipping class. */ class WC_Order_Item_Shipping extends WC_Order_Item { /** * Order Data array. This is the core order data exposed in APIs since 3.0.0. * * @since 3.0.0 * @var array */ protected $extra_data = array( 'method_title' => '', 'method_id' => '', 'instance_id' => '', 'total' => 0, 'total_tax' => 0, 'taxes' => array( 'total' => array(), ), ); /** * Calculate item taxes. * * @since 3.2.0 * @param array $calculate_tax_for Location data to get taxes for. Required. * @return bool True if taxes were calculated. */ public function calculate_taxes( $calculate_tax_for = array() ) { if ( ! isset( $calculate_tax_for['country'], $calculate_tax_for['state'], $calculate_tax_for['postcode'], $calculate_tax_for['city'], $calculate_tax_for['tax_class'] ) ) { return false; } if ( wc_tax_enabled() ) { $tax_rates = WC_Tax::find_shipping_rates( $calculate_tax_for ); $taxes = WC_Tax::calc_tax( $this->get_total(), $tax_rates, false ); $this->set_taxes( array( 'total' => $taxes ) ); } else { $this->set_taxes( false ); } do_action( 'woocommerce_order_item_shipping_after_calculate_taxes', $this, $calculate_tax_for ); return true; } /* |-------------------------------------------------------------------------- | Setters |-------------------------------------------------------------------------- */ /** * Set order item name. * * @param string $value Value to set. * @throws WC_Data_Exception May throw exception if data is invalid. */ public function set_name( $value ) { $this->set_method_title( $value ); } /** * Set method title. * * @param string $value Value to set. * @throws WC_Data_Exception May throw exception if data is invalid. */ public function set_method_title( $value ) { $this->set_prop( 'name', wc_clean( $value ) ); $this->set_prop( 'method_title', wc_clean( $value ) ); } /** * Set shipping method id. * * @param string $value Value to set. * @throws WC_Data_Exception May throw exception if data is invalid. */ public function set_method_id( $value ) { $this->set_prop( 'method_id', wc_clean( $value ) ); } /** * Set shipping instance id. * * @param string $value Value to set. * @throws WC_Data_Exception May throw exception if data is invalid. */ public function set_instance_id( $value ) { $this->set_prop( 'instance_id', wc_clean( $value ) ); } /** * Set total. * * @param string $value Value to set. * @throws WC_Data_Exception May throw exception if data is invalid. */ public function set_total( $value ) { $this->set_prop( 'total', wc_format_decimal( $value ) ); } /** * Set total tax. * * @param string $value Value to set. * @throws WC_Data_Exception May throw exception if data is invalid. */ protected function set_total_tax( $value ) { $this->set_prop( 'total_tax', wc_format_decimal( $value ) ); } /** * Set taxes. * * This is an array of tax ID keys with total amount values. * * @param array $raw_tax_data Value to set. * @throws WC_Data_Exception May throw exception if data is invalid. */ public function set_taxes( $raw_tax_data ) { $raw_tax_data = maybe_unserialize( $raw_tax_data ); $tax_data = array( 'total' => array(), ); if ( isset( $raw_tax_data['total'] ) ) { $tax_data['total'] = array_map( 'wc_format_decimal', $raw_tax_data['total'] ); } elseif ( ! empty( $raw_tax_data ) && is_array( $raw_tax_data ) ) { // Older versions just used an array. $tax_data['total'] = array_map( 'wc_format_decimal', $raw_tax_data ); } $this->set_prop( 'taxes', $tax_data ); if ( 'yes' === get_option( 'woocommerce_tax_round_at_subtotal' ) ) { $this->set_total_tax( array_sum( $tax_data['total'] ) ); } else { $this->set_total_tax( array_sum( array_map( 'wc_round_tax_total', $tax_data['total'] ) ) ); } } /** * Set properties based on passed in shipping rate object. * * @param WC_Shipping_Rate $shipping_rate Shipping rate to set. */ public function set_shipping_rate( $shipping_rate ) { $this->set_method_title( $shipping_rate->get_label() ); $this->set_method_id( $shipping_rate->get_method_id() ); $this->set_instance_id( $shipping_rate->get_instance_id() ); $this->set_total( $shipping_rate->get_cost() ); $this->set_taxes( $shipping_rate->get_taxes() ); $this->set_meta_data( $shipping_rate->get_meta_data() ); } /* |-------------------------------------------------------------------------- | Getters |-------------------------------------------------------------------------- */ /** * Get order item type. * * @return string */ public function get_type() { return 'shipping'; } /** * Get order item name. * * @param string $context View or edit context. * @return string */ public function get_name( $context = 'view' ) { return $this->get_method_title( $context ); } /** * Get title. * * @param string $context View or edit context. * @return string */ public function get_method_title( $context = 'view' ) { $method_title = $this->get_prop( 'method_title', $context ); if ( 'view' === $context ) { return $method_title ? $method_title : __( 'Shipping', 'woocommerce' ); } else { return $method_title; } } /** * Get method ID. * * @param string $context View or edit context. * @return string */ public function get_method_id( $context = 'view' ) { return $this->get_prop( 'method_id', $context ); } /** * Get instance ID. * * @param string $context View or edit context. * @return string */ public function get_instance_id( $context = 'view' ) { return $this->get_prop( 'instance_id', $context ); } /** * Get total cost. * * @param string $context View or edit context. * @return string */ public function get_total( $context = 'view' ) { return $this->get_prop( 'total', $context ); } /** * Get total tax. * * @param string $context View or edit context. * @return string */ public function get_total_tax( $context = 'view' ) { return $this->get_prop( 'total_tax', $context ); } /** * Get taxes. * * @param string $context View or edit context. * @return array */ public function get_taxes( $context = 'view' ) { return $this->get_prop( 'taxes', $context ); } /** * Get tax class. * * @param string $context View or edit context. * @return string */ public function get_tax_class( $context = 'view' ) { return get_option( 'woocommerce_shipping_tax_class' ); } /* |-------------------------------------------------------------------------- | Array Access Methods |-------------------------------------------------------------------------- | | For backwards compatibility with legacy arrays. | */ /** * Offset get: for ArrayAccess/Backwards compatibility. * * @param string $offset Key. * @return mixed */ public function offsetGet( $offset ) { if ( 'cost' === $offset ) { $offset = 'total'; } return parent::offsetGet( $offset ); } /** * Offset set: for ArrayAccess/Backwards compatibility. * * @deprecated 4.4.0 * @param string $offset Key. * @param mixed $value Value to set. */ public function offsetSet( $offset, $value ) { wc_deprecated_function( 'WC_Order_Item_Shipping::offsetSet', '4.4.0', '' ); if ( 'cost' === $offset ) { $offset = 'total'; } parent::offsetSet( $offset, $value ); } /** * Offset exists: for ArrayAccess. * * @param string $offset Key. * @return bool */ public function offsetExists( $offset ) { if ( in_array( $offset, array( 'cost' ), true ) ) { return true; } return parent::offsetExists( $offset ); } }
[+]
..
[-] wc-page-functions.php
[edit]
[-] class-wc-countries.php
[edit]
[-] class-wc-ajax.php
[edit]
[-] class-wc-privacy.php
[edit]
[+]
customizer
[+]
gateways
[-] class-wc-order-refund.php
[edit]
[-] wc-stock-functions.php
[edit]
[-] class-wc-cart.php
[edit]
[-] class-wc-tracker.php
[edit]
[-] class-wc-frontend-scripts.php
[edit]
[-] class-wc-product-download.php
[edit]
[+]
widgets
[+]
admin
[-] class-wc-auth.php
[edit]
[-] class-wc-rest-authentication.php
[edit]
[-] class-wc-data-exception.php
[edit]
[-] class-wc-log-levels.php
[edit]
[-] wc-coupon-functions.php
[edit]
[-] class-wc-order-item-shipping.php
[edit]
[+]
integrations
[-] class-wc-payment-gateways.php
[edit]
[-] wc-order-functions.php
[edit]
[+]
shipping
[-] class-wc-order-item-coupon.php
[edit]
[-] class-wc-payment-tokens.php
[edit]
[-] wc-deprecated-functions.php
[edit]
[-] class-wc-product-grouped.php
[edit]
[+]
tracks
[-] wc-product-functions.php
[edit]
[-] class-wc-datetime.php
[edit]
[-] wc-user-functions.php
[edit]
[-] wc-widget-functions.php
[edit]
[-] class-wc-breadcrumb.php
[edit]
[-] class-wc-customer-download-log.php
[edit]
[-] class-wc-order-query.php
[edit]
[-] wc-template-hooks.php
[edit]
[-] class-wc-https.php
[edit]
[-] class-wc-order.php
[edit]
[-] wc-attribute-functions.php
[edit]
[-] class-wc-session-handler.php
[edit]
[-] class-wc-product-variation.php
[edit]
[-] class-wc-query.php
[edit]
[-] class-wc-coupon.php
[edit]
[-] class-wc-shipping-zone.php
[edit]
[-] wc-account-functions.php
[edit]
[-] wc-formatting-functions.php
[edit]
[-] class-wc-integrations.php
[edit]
[-] class-wc-validation.php
[edit]
[-] class-wc-webhook.php
[edit]
[+]
traits
[-] class-wc-checkout.php
[edit]
[-] wc-core-functions.php
[edit]
[+]
emails
[-] wc-cart-functions.php
[edit]
[-] class-wc-shipping.php
[edit]
[-] class-wc-customer-download.php
[edit]
[-] class-wc-geolite-integration.php
[edit]
[-] class-wc-data-store.php
[edit]
[-] class-wc-order-item-tax.php
[edit]
[-] class-wc-customer.php
[edit]
[-] class-wc-product-attribute.php
[edit]
[+]
legacy
[+]
import
[-] class-wc-cli.php
[edit]
[+]
wccom-site
[-] class-wc-form-handler.php
[edit]
[-] class-wc-tax.php
[edit]
[-] wc-order-item-functions.php
[edit]
[+]
blocks
[-] class-wc-cache-helper.php
[edit]
[-] class-wc-cart-totals.php
[edit]
[-] class-wc-emails.php
[edit]
[-] class-wc-product-query.php
[edit]
[-] class-wc-download-handler.php
[edit]
[-] class-wc-product-external.php
[edit]
[-] class-woocommerce.php
[edit]
[-] class-wc-logger.php
[edit]
[-] class-wc-shipping-zones.php
[edit]
[-] class-wc-order-item-meta.php
[edit]
[+]
walkers
[+]
shortcodes
[-] class-wc-cart-session.php
[edit]
[+]
rest-api
[-] class-wc-autoloader.php
[edit]
[-] class-wc-meta-data.php
[edit]
[-] wc-notice-functions.php
[edit]
[+]
queue
[-] class-wc-order-item.php
[edit]
[-] class-wc-shortcodes.php
[edit]
[-] wc-term-functions.php
[edit]
[-] wc-webhook-functions.php
[edit]
[-] class-wc-privacy-exporters.php
[edit]
[-] class-wc-privacy-background-process.php
[edit]
[-] class-wc-regenerate-images-request.php
[edit]
[-] class-wc-deprecated-filter-hooks.php
[edit]
[+]
interfaces
[-] class-wc-background-emailer.php
[edit]
[-] class-wc-geo-ip.php
[edit]
[+]
data-stores
[-] class-wc-comments.php
[edit]
[-] wc-conditional-functions.php
[edit]
[-] class-wc-product-factory.php
[edit]
[+]
theme-support
[+]
libraries
[-] class-wc-structured-data.php
[edit]
[-] class-wc-order-factory.php
[edit]
[-] class-wc-cart-fees.php
[edit]
[-] class-wc-deprecated-action-hooks.php
[edit]
[-] class-wc-order-item-fee.php
[edit]
[+]
cli
[-] class-wc-background-updater.php
[edit]
[-] class-wc-discounts.php
[edit]
[-] class-wc-rate-limiter.php
[edit]
[-] class-wc-geolocation.php
[edit]
[-] class-wc-privacy-erasers.php
[edit]
[-] class-wc-post-types.php
[edit]
[+]
export
[+]
log-handlers
[-] class-wc-regenerate-images.php
[edit]
[+]
abstracts
[-] class-wc-rest-exception.php
[edit]
[-] class-wc-order-item-product.php
[edit]
[-] class-wc-product-simple.php
[edit]
[-] wc-rest-functions.php
[edit]
[-] class-wc-post-data.php
[edit]
[-] class-wc-embed.php
[edit]
[+]
payment-tokens
[-] class-wc-template-loader.php
[edit]
[-] class-wc-product-variable.php
[edit]
[-] class-wc-install.php
[edit]
[-] class-wc-shipping-rate.php
[edit]
[-] class-wc-api.php
[edit]
[-] wc-template-functions.php
[edit]
[-] wc-update-functions.php
[edit]
[-] class-wc-register-wp-admin-settings.php
[edit]