PATH:
home
/
lab2454c
/
dansact.com
/
wp-content
/
plugins
/
woocommerce
/
includes
<?php /** * Cart fees API. * * Developers can add fees to the cart via WC()->cart->fees_api() which will reference this class. * * We suggest using the action woocommerce_cart_calculate_fees hook for adding fees. * * @package WooCommerce\Classes * @version 3.2.0 */ defined( 'ABSPATH' ) || exit; /** * WC_Cart_Fees class. * * @since 3.2.0 */ final class WC_Cart_Fees { /** * An array of fee objects. * * @var object[] */ private $fees = array(); /** * Reference to cart object. * * @since 3.2.0 * @var WC_Cart */ private $cart; /** * New fees are made out of these props. * * @var array */ private $default_fee_props = array( 'id' => '', 'name' => '', 'tax_class' => '', 'taxable' => false, 'amount' => 0, 'total' => 0, ); /** * Constructor. Reference to the cart. * * @since 3.2.0 * @throws Exception If missing WC_Cart object. * @param WC_Cart $cart Cart object. */ public function __construct( &$cart ) { if ( ! is_a( $cart, 'WC_Cart' ) ) { throw new Exception( 'A valid WC_Cart object is required' ); } $this->cart = $cart; } /** * Register methods for this object on the appropriate WordPress hooks. */ public function init() {} /** * Add a fee. Fee IDs must be unique. * * @since 3.2.0 * @param array $args Array of fee properties. * @return object Either a fee object if added, or a WP_Error if it failed. */ public function add_fee( $args = array() ) { $fee_props = (object) wp_parse_args( $args, $this->default_fee_props ); $fee_props->name = $fee_props->name ? $fee_props->name : __( 'Fee', 'woocommerce' ); $fee_props->tax_class = in_array( $fee_props->tax_class, array_merge( WC_Tax::get_tax_classes(), WC_Tax::get_tax_class_slugs() ), true ) ? $fee_props->tax_class : ''; $fee_props->taxable = wc_string_to_bool( $fee_props->taxable ); $fee_props->amount = wc_format_decimal( $fee_props->amount ); if ( empty( $fee_props->id ) ) { $fee_props->id = $this->generate_id( $fee_props ); } if ( array_key_exists( $fee_props->id, $this->fees ) ) { return new WP_Error( 'fee_exists', __( 'Fee has already been added.', 'woocommerce' ) ); } $this->fees[ $fee_props->id ] = $fee_props; return $this->fees[ $fee_props->id ]; } /** * Get fees. * * @return array */ public function get_fees() { uasort( $this->fees, array( $this, 'sort_fees_callback' ) ); return $this->fees; } /** * Set fees. * * @param object[] $raw_fees Array of fees. */ public function set_fees( $raw_fees = array() ) { $this->fees = array(); foreach ( $raw_fees as $raw_fee ) { $this->add_fee( $raw_fee ); } } /** * Remove all fees. * * @since 3.2.0 */ public function remove_all_fees() { $this->set_fees(); } /** * Sort fees by amount. * * @param stdClass $a Fee object. * @param stdClass $b Fee object. * @return int */ protected function sort_fees_callback( $a, $b ) { /** * Filter sort fees callback. * * @since 3.8.0 * @param int Sort order, -1 or 1. * @param stdClass $a Fee object. * @param stdClass $b Fee object. */ return apply_filters( 'woocommerce_sort_fees_callback', $a->amount > $b->amount ? -1 : 1, $a, $b ); } /** * Generate a unique ID for the fee being added. * * @param string $fee Fee object. * @return string fee key. */ private function generate_id( $fee ) { return sanitize_title( $fee->name ); } }
[+]
..
[-] 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
[+]
react-admin
[-] 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]