namespace Google\Site_Kit_Dependencies\GuzzleHttp\Promise;
/**
* Get the global task queue used for promise resolution.
*
* This task queue MUST be run in an event loop in order for promises to be
* settled asynchronously. It will be automatically run when synchronously
* waiting on a promise.
*
*
* while ($eventLoop->isRunning()) {
* GuzzleHttp\Promise\queue()->run();
* }
*
*
* @param TaskQueueInterface $assign Optionally specify a new queue instance.
*
* @return TaskQueueInterface
*
* @deprecated queue will be removed in guzzlehttp/promises:2.0. Use Utils::queue instead.
*/
function queue(\Google\Site_Kit_Dependencies\GuzzleHttp\Promise\TaskQueueInterface $assign = null)
{
return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Utils::queue($assign);
}
/**
* Adds a function to run in the task queue when it is next `run()` and returns
* a promise that is fulfilled or rejected with the result.
*
* @param callable $task Task function to run.
*
* @return PromiseInterface
*
* @deprecated task will be removed in guzzlehttp/promises:2.0. Use Utils::task instead.
*/
function task(callable $task)
{
return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Utils::task($task);
}
/**
* Creates a promise for a value if the value is not a promise.
*
* @param mixed $value Promise or value.
*
* @return PromiseInterface
*
* @deprecated promise_for will be removed in guzzlehttp/promises:2.0. Use Create::promiseFor instead.
*/
function promise_for($value)
{
return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Create::promiseFor($value);
}
/**
* Creates a rejected promise for a reason if the reason is not a promise. If
* the provided reason is a promise, then it is returned as-is.
*
* @param mixed $reason Promise or reason.
*
* @return PromiseInterface
*
* @deprecated rejection_for will be removed in guzzlehttp/promises:2.0. Use Create::rejectionFor instead.
*/
function rejection_for($reason)
{
return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Create::rejectionFor($reason);
}
/**
* Create an exception for a rejected promise value.
*
* @param mixed $reason
*
* @return \Exception|\Throwable
*
* @deprecated exception_for will be removed in guzzlehttp/promises:2.0. Use Create::exceptionFor instead.
*/
function exception_for($reason)
{
return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Create::exceptionFor($reason);
}
/**
* Returns an iterator for the given value.
*
* @param mixed $value
*
* @return \Iterator
*
* @deprecated iter_for will be removed in guzzlehttp/promises:2.0. Use Create::iterFor instead.
*/
function iter_for($value)
{
return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Create::iterFor($value);
}
/**
* Synchronously waits on a promise to resolve and returns an inspection state
* array.
*
* Returns a state associative array containing a "state" key mapping to a
* valid promise state. If the state of the promise is "fulfilled", the array
* will contain a "value" key mapping to the fulfilled value of the promise. If
* the promise is rejected, the array will contain a "reason" key mapping to
* the rejection reason of the promise.
*
* @param PromiseInterface $promise Promise or value.
*
* @return array
*
* @deprecated inspect will be removed in guzzlehttp/promises:2.0. Use Utils::inspect instead.
*/
function inspect(\Google\Site_Kit_Dependencies\GuzzleHttp\Promise\PromiseInterface $promise)
{
return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Utils::inspect($promise);
}
/**
* Waits on all of the provided promises, but does not unwrap rejected promises
* as thrown exception.
*
* Returns an array of inspection state arrays.
*
* @see inspect for the inspection state array format.
*
* @param PromiseInterface[] $promises Traversable of promises to wait upon.
*
* @return array
*
* @deprecated inspect will be removed in guzzlehttp/promises:2.0. Use Utils::inspectAll instead.
*/
function inspect_all($promises)
{
return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Utils::inspectAll($promises);
}
/**
* Waits on all of the provided promises and returns the fulfilled values.
*
* Returns an array that contains the value of each promise (in the same order
* the promises were provided). An exception is thrown if any of the promises
* are rejected.
*
* @param iterable $promises Iterable of PromiseInterface objects to wait on.
*
* @return array
*
* @throws \Exception on error
* @throws \Throwable on error in PHP >=7
*
* @deprecated unwrap will be removed in guzzlehttp/promises:2.0. Use Utils::unwrap instead.
*/
function unwrap($promises)
{
return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Utils::unwrap($promises);
}
/**
* Given an array of promises, return a promise that is fulfilled when all the
* items in the array are fulfilled.
*
* The promise's fulfillment value is an array with fulfillment values at
* respective positions to the original array. If any promise in the array
* rejects, the returned promise is rejected with the rejection reason.
*
* @param mixed $promises Promises or values.
* @param bool $recursive If true, resolves new promises that might have been added to the stack during its own resolution.
*
* @return PromiseInterface
*
* @deprecated all will be removed in guzzlehttp/promises:2.0. Use Utils::all instead.
*/
function all($promises, $recursive = \false)
{
return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Utils::all($promises, $recursive);
}
/**
* Initiate a competitive race between multiple promises or values (values will
* become immediately fulfilled promises).
*
* When count amount of promises have been fulfilled, the returned promise is
* fulfilled with an array that contains the fulfillment values of the winners
* in order of resolution.
*
* This promise is rejected with a {@see AggregateException} if the number of
* fulfilled promises is less than the desired $count.
*
* @param int $count Total number of promises.
* @param mixed $promises Promises or values.
*
* @return PromiseInterface
*
* @deprecated some will be removed in guzzlehttp/promises:2.0. Use Utils::some instead.
*/
function some($count, $promises)
{
return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Utils::some($count, $promises);
}
/**
* Like some(), with 1 as count. However, if the promise fulfills, the
* fulfillment value is not an array of 1 but the value directly.
*
* @param mixed $promises Promises or values.
*
* @return PromiseInterface
*
* @deprecated any will be removed in guzzlehttp/promises:2.0. Use Utils::any instead.
*/
function any($promises)
{
return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Utils::any($promises);
}
/**
* Returns a promise that is fulfilled when all of the provided promises have
* been fulfilled or rejected.
*
* The returned promise is fulfilled with an array of inspection state arrays.
*
* @see inspect for the inspection state array format.
*
* @param mixed $promises Promises or values.
*
* @return PromiseInterface
*
* @deprecated settle will be removed in guzzlehttp/promises:2.0. Use Utils::settle instead.
*/
function settle($promises)
{
return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Utils::settle($promises);
}
/**
* Given an iterator that yields promises or values, returns a promise that is
* fulfilled with a null value when the iterator has been consumed or the
* aggregate promise has been fulfilled or rejected.
*
* $onFulfilled is a function that accepts the fulfilled value, iterator index,
* and the aggregate promise. The callback can invoke any necessary side
* effects and choose to resolve or reject the aggregate if needed.
*
* $onRejected is a function that accepts the rejection reason, iterator index,
* and the aggregate promise. The callback can invoke any necessary side
* effects and choose to resolve or reject the aggregate if needed.
*
* @param mixed $iterable Iterator or array to iterate over.
* @param callable $onFulfilled
* @param callable $onRejected
*
* @return PromiseInterface
*
* @deprecated each will be removed in guzzlehttp/promises:2.0. Use Each::of instead.
*/
function each($iterable, callable $onFulfilled = null, callable $onRejected = null)
{
return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Each::of($iterable, $onFulfilled, $onRejected);
}
/**
* Like each, but only allows a certain number of outstanding promises at any
* given time.
*
* $concurrency may be an integer or a function that accepts the number of
* pending promises and returns a numeric concurrency limit value to allow for
* dynamic a concurrency size.
*
* @param mixed $iterable
* @param int|callable $concurrency
* @param callable $onFulfilled
* @param callable $onRejected
*
* @return PromiseInterface
*
* @deprecated each_limit will be removed in guzzlehttp/promises:2.0. Use Each::ofLimit instead.
*/
function each_limit($iterable, $concurrency, callable $onFulfilled = null, callable $onRejected = null)
{
return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Each::ofLimit($iterable, $concurrency, $onFulfilled, $onRejected);
}
/**
* Like each_limit, but ensures that no promise in the given $iterable argument
* is rejected. If any promise is rejected, then the aggregate promise is
* rejected with the encountered rejection.
*
* @param mixed $iterable
* @param int|callable $concurrency
* @param callable $onFulfilled
*
* @return PromiseInterface
*
* @deprecated each_limit_all will be removed in guzzlehttp/promises:2.0. Use Each::ofLimitAll instead.
*/
function each_limit_all($iterable, $concurrency, callable $onFulfilled = null)
{
return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Each::ofLimitAll($iterable, $concurrency, $onFulfilled);
}
/**
* Returns true if a promise is fulfilled.
*
* @return bool
*
* @deprecated is_fulfilled will be removed in guzzlehttp/promises:2.0. Use Is::fulfilled instead.
*/
function is_fulfilled(\Google\Site_Kit_Dependencies\GuzzleHttp\Promise\PromiseInterface $promise)
{
return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Is::fulfilled($promise);
}
/**
* Returns true if a promise is rejected.
*
* @return bool
*
* @deprecated is_rejected will be removed in guzzlehttp/promises:2.0. Use Is::rejected instead.
*/
function is_rejected(\Google\Site_Kit_Dependencies\GuzzleHttp\Promise\PromiseInterface $promise)
{
return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Is::rejected($promise);
}
/**
* Returns true if a promise is fulfilled or rejected.
*
* @return bool
*
* @deprecated is_settled will be removed in guzzlehttp/promises:2.0. Use Is::settled instead.
*/
function is_settled(\Google\Site_Kit_Dependencies\GuzzleHttp\Promise\PromiseInterface $promise)
{
return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Is::settled($promise);
}
/**
* Create a new coroutine.
*
* @see Coroutine
*
* @return PromiseInterface
*
* @deprecated coroutine will be removed in guzzlehttp/promises:2.0. Use Coroutine::of instead.
*/
function coroutine(callable $generatorFn)
{
return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Coroutine::of($generatorFn);
}namespace Google\Site_Kit_Dependencies\GuzzleHttp;
use Google\Site_Kit_Dependencies\GuzzleHttp\Handler\CurlHandler;
use Google\Site_Kit_Dependencies\GuzzleHttp\Handler\CurlMultiHandler;
use Google\Site_Kit_Dependencies\GuzzleHttp\Handler\Proxy;
use Google\Site_Kit_Dependencies\GuzzleHttp\Handler\StreamHandler;
/**
* Expands a URI template
*
* @param string $template URI template
* @param array $variables Template variables
*
* @return string
*/
function uri_template($template, array $variables)
{
if (\extension_loaded('uri_template')) {
// @codeCoverageIgnoreStart
return \Google\Site_Kit_Dependencies\uri_template($template, $variables);
// @codeCoverageIgnoreEnd
}
static $uriTemplate;
if (!$uriTemplate) {
$uriTemplate = new \Google\Site_Kit_Dependencies\GuzzleHttp\UriTemplate();
}
return $uriTemplate->expand($template, $variables);
}
/**
* Debug function used to describe the provided value type and class.
*
* @param mixed $input
*
* @return string Returns a string containing the type of the variable and
* if a class is provided, the class name.
*/
function describe_type($input)
{
switch (\gettype($input)) {
case 'object':
return 'object(' . \get_class($input) . ')';
case 'array':
return 'array(' . \count($input) . ')';
default:
\ob_start();
\var_dump($input);
// normalize float vs double
return \str_replace('double(', 'float(', \rtrim(\ob_get_clean()));
}
}
/**
* Parses an array of header lines into an associative array of headers.
*
* @param iterable $lines Header lines array of strings in the following
* format: "Name: Value"
* @return array
*/
function headers_from_lines($lines)
{
$headers = [];
foreach ($lines as $line) {
$parts = \explode(':', $line, 2);
$headers[\trim($parts[0])][] = isset($parts[1]) ? \trim($parts[1]) : null;
}
return $headers;
}
/**
* Returns a debug stream based on the provided variable.
*
* @param mixed $value Optional value
*
* @return resource
*/
function debug_resource($value = null)
{
if (\is_resource($value)) {
return $value;
} elseif (\defined('STDOUT')) {
return \STDOUT;
}
return \fopen('php://output', 'w');
}
/**
* Chooses and creates a default handler to use based on the environment.
*
* The returned handler is not wrapped by any default middlewares.
*
* @return callable Returns the best handler for the given system.
* @throws \RuntimeException if no viable Handler is available.
*/
function choose_handler()
{
$handler = null;
if (\function_exists('curl_multi_exec') && \function_exists('curl_exec')) {
$handler = \Google\Site_Kit_Dependencies\GuzzleHttp\Handler\Proxy::wrapSync(new \Google\Site_Kit_Dependencies\GuzzleHttp\Handler\CurlMultiHandler(), new \Google\Site_Kit_Dependencies\GuzzleHttp\Handler\CurlHandler());
} elseif (\function_exists('curl_exec')) {
$handler = new \Google\Site_Kit_Dependencies\GuzzleHttp\Handler\CurlHandler();
} elseif (\function_exists('curl_multi_exec')) {
$handler = new \Google\Site_Kit_Dependencies\GuzzleHttp\Handler\CurlMultiHandler();
}
if (\ini_get('allow_url_fopen')) {
$handler = $handler ? \Google\Site_Kit_Dependencies\GuzzleHttp\Handler\Proxy::wrapStreaming($handler, new \Google\Site_Kit_Dependencies\GuzzleHttp\Handler\StreamHandler()) : new \Google\Site_Kit_Dependencies\GuzzleHttp\Handler\StreamHandler();
} elseif (!$handler) {
throw new \RuntimeException('GuzzleHttp requires cURL, the ' . 'allow_url_fopen ini setting, or a custom HTTP handler.');
}
return $handler;
}
/**
* Get the default User-Agent string to use with Guzzle
*
* @return string
*/
function default_user_agent()
{
static $defaultAgent = '';
if (!$defaultAgent) {
$defaultAgent = 'GuzzleHttp/' . \Google\Site_Kit_Dependencies\GuzzleHttp\Client::VERSION;
if (\extension_loaded('curl') && \function_exists('curl_version')) {
$defaultAgent .= ' curl/' . \curl_version()['version'];
}
$defaultAgent .= ' PHP/' . \PHP_VERSION;
}
return $defaultAgent;
}
/**
* Returns the default cacert bundle for the current system.
*
* First, the openssl.cafile and curl.cainfo php.ini settings are checked.
* If those settings are not configured, then the common locations for
* bundles found on Red Hat, CentOS, Fedora, Ubuntu, Debian, FreeBSD, OS X
* and Windows are checked. If any of these file locations are found on
* disk, they will be utilized.
*
* Note: the result of this function is cached for subsequent calls.
*
* @return string
* @throws \RuntimeException if no bundle can be found.
*/
function default_ca_bundle()
{
static $cached = null;
static $cafiles = [
// Red Hat, CentOS, Fedora (provided by the ca-certificates package)
'/etc/pki/tls/certs/ca-bundle.crt',
// Ubuntu, Debian (provided by the ca-certificates package)
'/etc/ssl/certs/ca-certificates.crt',
// FreeBSD (provided by the ca_root_nss package)
'/usr/local/share/certs/ca-root-nss.crt',
// SLES 12 (provided by the ca-certificates package)
'/var/lib/ca-certificates/ca-bundle.pem',
// OS X provided by homebrew (using the default path)
'/usr/local/etc/openssl/cert.pem',
// Google app engine
'/etc/ca-certificates.crt',
// Windows?
'C:\\windows\\system32\\curl-ca-bundle.crt',
'C:\\windows\\curl-ca-bundle.crt',
];
if ($cached) {
return $cached;
}
if ($ca = \ini_get('openssl.cafile')) {
return $cached = $ca;
}
if ($ca = \ini_get('curl.cainfo')) {
return $cached = $ca;
}
foreach ($cafiles as $filename) {
if (\file_exists($filename)) {
return $cached = $filename;
}
}
throw new \RuntimeException(<< '',
'order_item_type' => 'line_item',
);
$item_array = wp_parse_args( $item_array, $defaults );
$data_store = WC_Data_Store::load( 'order-item' );
$item_id = $data_store->add_order_item( $order_id, $item_array );
$item = WC_Order_Factory::get_order_item( $item_id );
do_action( 'woocommerce_new_order_item', $item_id, $item, $order_id );
return $item_id;
}
/**
* Update an item for an order.
*
* @since 2.2
* @param int $item_id Item ID.
* @param array $args Either `order_item_type` or `order_item_name`.
*
* @throws Exception When `WC_Data_Store::load` validation fails.
* @return bool True if successfully updated, false otherwise.
*/
function wc_update_order_item( $item_id, $args ) {
$data_store = WC_Data_Store::load( 'order-item' );
$update = $data_store->update_order_item( $item_id, $args );
if ( false === $update ) {
return false;
}
do_action( 'woocommerce_update_order_item', $item_id, $args );
return true;
}
/**
* Delete an item from the order it belongs to based on item id.
*
* @param int $item_id Item ID.
*
* @throws Exception When `WC_Data_Store::load` validation fails.
* @return bool
*/
function wc_delete_order_item( $item_id ) {
$item_id = absint( $item_id );
if ( ! $item_id ) {
return false;
}
$data_store = WC_Data_Store::load( 'order-item' );
do_action( 'woocommerce_before_delete_order_item', $item_id );
$data_store->delete_order_item( $item_id );
do_action( 'woocommerce_delete_order_item', $item_id );
return true;
}
/**
* WooCommerce Order Item Meta API - Update term meta.
*
* @param int $item_id Item ID.
* @param string $meta_key Meta key.
* @param mixed $meta_value Meta value.
* @param string $prev_value Previous value (default: '').
*
* @throws Exception When `WC_Data_Store::load` validation fails.
* @return bool
*/
function wc_update_order_item_meta( $item_id, $meta_key, $meta_value, $prev_value = '' ) {
$data_store = WC_Data_Store::load( 'order-item' );
if ( $data_store->update_metadata( $item_id, $meta_key, $meta_value, $prev_value ) ) {
WC_Cache_Helper::invalidate_cache_group( 'object_' . $item_id ); // Invalidate cache.
return true;
}
return false;
}
/**
* WooCommerce Order Item Meta API - Add term meta.
*
* @param int $item_id Item ID.
* @param string $meta_key Meta key.
* @param mixed $meta_value Meta value.
* @param bool $unique If meta data should be unique (default: false).
*
* @throws Exception When `WC_Data_Store::load` validation fails.
* @return int New row ID or 0.
*/
function wc_add_order_item_meta( $item_id, $meta_key, $meta_value, $unique = false ) {
$data_store = WC_Data_Store::load( 'order-item' );
$meta_id = $data_store->add_metadata( $item_id, $meta_key, $meta_value, $unique );
if ( $meta_id ) {
WC_Cache_Helper::invalidate_cache_group( 'object_' . $item_id ); // Invalidate cache.
return $meta_id;
}
return 0;
}
/**
* WooCommerce Order Item Meta API - Delete term meta.
*
* @param int $item_id Item ID.
* @param string $meta_key Meta key.
* @param mixed $meta_value Meta value (default: '').
* @param bool $delete_all Delete all meta data, defaults to `false`.
*
* @throws Exception When `WC_Data_Store::load` validation fails.
* @return bool
*/
function wc_delete_order_item_meta( $item_id, $meta_key, $meta_value = '', $delete_all = false ) {
$data_store = WC_Data_Store::load( 'order-item' );
if ( $data_store->delete_metadata( $item_id, $meta_key, $meta_value, $delete_all ) ) {
WC_Cache_Helper::invalidate_cache_group( 'object_' . $item_id ); // Invalidate cache.
return true;
}
return false;
}
/**
* WooCommerce Order Item Meta API - Get term meta.
*
* @param int $item_id Item ID.
* @param string $key Meta key.
* @param bool $single Whether to return a single value. (default: true).
*
* @throws Exception When `WC_Data_Store::load` validation fails.
* @return mixed
*/
function wc_get_order_item_meta( $item_id, $key, $single = true ) {
$data_store = WC_Data_Store::load( 'order-item' );
return $data_store->get_metadata( $item_id, $key, $single );
}
/**
* Get order ID by order item ID.
*
* @param int $item_id Item ID.
*
* @throws Exception When `WC_Data_Store::load` validation fails.
* @return int
*/
function wc_get_order_id_by_order_item_id( $item_id ) {
$data_store = WC_Data_Store::load( 'order-item' );
return $data_store->get_order_id_by_order_item_id( $item_id );
}/**
* WooCommerce Account Functions
*
* Functions for account specific things.
*
* @package WooCommerce\Functions
* @version 2.6.0
*/
use Automattic\WooCommerce\Enums\OrderStatus;
defined( 'ABSPATH' ) || exit;
/**
* Returns the url to the lost password endpoint url.
*
* @param string $default_url Default lost password URL.
* @return string
*/
function wc_lostpassword_url( $default_url = '' ) {
// Avoid loading too early.
if ( ! did_action( 'init' ) ) {
return $default_url;
}
// Don't change the admin form.
if ( did_action( 'login_form_login' ) ) {
return $default_url;
}
// Don't redirect to the woocommerce endpoint on global network admin lost passwords.
if ( is_multisite() && isset( $_GET['redirect_to'] ) && false !== strpos( wp_unslash( $_GET['redirect_to'] ), network_admin_url() ) ) { // WPCS: input var ok, sanitization ok, CSRF ok.
return $default_url;
}
$wc_account_page_url = wc_get_page_permalink( 'myaccount' );
$wc_account_page_exists = wc_get_page_id( 'myaccount' ) > 0;
$lost_password_endpoint = get_option( 'woocommerce_myaccount_lost_password_endpoint' );
if ( $wc_account_page_exists && ! empty( $lost_password_endpoint ) ) {
return wc_get_endpoint_url( $lost_password_endpoint, '', $wc_account_page_url );
} else {
return $default_url;
}
}
add_filter( 'lostpassword_url', 'wc_lostpassword_url', 10, 1 );
/**
* Get the link to the edit account details page.
*
* @return string
*/
function wc_customer_edit_account_url() {
$edit_account_url = wc_get_endpoint_url( 'edit-account', '', wc_get_page_permalink( 'myaccount' ) );
return apply_filters( 'woocommerce_customer_edit_account_url', $edit_account_url );
}
/**
* Get the edit address slug translation.
*
* @param string $id Address ID.
* @param bool $flip Flip the array to make it possible to retrieve the values from both sides.
*
* @return string Address slug i18n.
*/
function wc_edit_address_i18n( $id, $flip = false ) {
$slugs = apply_filters(
'woocommerce_edit_address_slugs',
array(
'billing' => sanitize_title( _x( 'billing', 'edit-address-slug', 'woocommerce' ) ),
'shipping' => sanitize_title( _x( 'shipping', 'edit-address-slug', 'woocommerce' ) ),
)
);
if ( $flip ) {
$slugs = array_flip( $slugs );
}
if ( ! isset( $slugs[ $id ] ) ) {
return $id;
}
return $slugs[ $id ];
}
/**
* Get My Account menu items.
*
* @since 2.6.0
* @return array
*/
function wc_get_account_menu_items() {
$endpoints = array(
'orders' => get_option( 'woocommerce_myaccount_orders_endpoint', 'orders' ),
'downloads' => get_option( 'woocommerce_myaccount_downloads_endpoint', 'downloads' ),
'edit-address' => get_option( 'woocommerce_myaccount_edit_address_endpoint', 'edit-address' ),
'payment-methods' => get_option( 'woocommerce_myaccount_payment_methods_endpoint', 'payment-methods' ),
'edit-account' => get_option( 'woocommerce_myaccount_edit_account_endpoint', 'edit-account' ),
'customer-logout' => get_option( 'woocommerce_logout_endpoint', 'customer-logout' ),
);
$items = array(
'dashboard' => __( 'Dashboard', 'woocommerce' ),
'orders' => __( 'Orders', 'woocommerce' ),
'downloads' => __( 'Downloads', 'woocommerce' ),
'edit-address' => _n( 'Address', 'Addresses', ( 1 + (int) wc_shipping_enabled() ), 'woocommerce' ),
'payment-methods' => __( 'Payment methods', 'woocommerce' ),
'edit-account' => __( 'Account details', 'woocommerce' ),
'customer-logout' => __( 'Log out', 'woocommerce' ),
);
// Remove missing endpoints.
foreach ( $endpoints as $endpoint_id => $endpoint ) {
if ( empty( $endpoint ) ) {
unset( $items[ $endpoint_id ] );
}
}
// Check if payment gateways support add new payment methods.
if ( isset( $items['payment-methods'] ) ) {
$support_payment_methods = false;
foreach ( WC()->payment_gateways->get_available_payment_gateways() as $gateway ) {
if ( $gateway->supports( 'add_payment_method' ) || $gateway->supports( 'tokenization' ) ) {
$support_payment_methods = true;
break;
}
}
if ( ! $support_payment_methods ) {
unset( $items['payment-methods'] );
}
}
return apply_filters( 'woocommerce_account_menu_items', $items, $endpoints );
}
/**
* Find current item in account menu.
*
* @since 9.3.0
* @param string $endpoint Endpoint.
* @return bool
*/
function wc_is_current_account_menu_item( $endpoint ) {
global $wp;
$current = isset( $wp->query_vars[ $endpoint ] );
if ( 'dashboard' === $endpoint && ( isset( $wp->query_vars['page'] ) || empty( $wp->query_vars ) ) ) {
$current = true; // Dashboard is not an endpoint, so needs a custom check.
} elseif ( 'orders' === $endpoint && isset( $wp->query_vars['view-order'] ) ) {
$current = true; // When looking at individual order, highlight Orders list item (to signify where in the menu the user currently is).
} elseif ( 'payment-methods' === $endpoint && isset( $wp->query_vars['add-payment-method'] ) ) {
$current = true;
}
return $current;
}
/**
* Get account menu item classes.
*
* @since 2.6.0
* @param string $endpoint Endpoint.
* @return string
*/
function wc_get_account_menu_item_classes( $endpoint ) {
$classes = array(
'woocommerce-MyAccount-navigation-link',
'woocommerce-MyAccount-navigation-link--' . $endpoint,
);
if ( wc_is_current_account_menu_item( $endpoint ) ) {
$classes[] = 'is-active';
}
$classes = apply_filters( 'woocommerce_account_menu_item_classes', $classes, $endpoint );
return implode( ' ', array_map( 'sanitize_html_class', $classes ) );
}
/**
* Get account endpoint URL.
*
* @since 2.6.0
* @param string $endpoint Endpoint.
* @return string
*/
function wc_get_account_endpoint_url( $endpoint ) {
if ( 'dashboard' === $endpoint ) {
return wc_get_page_permalink( 'myaccount' );
}
$url = wc_get_endpoint_url( $endpoint, '', wc_get_page_permalink( 'myaccount' ) );
if ( 'customer-logout' === $endpoint ) {
return wp_nonce_url( $url, 'customer-logout' );
}
return $url;
}
/**
* Get My Account > Orders columns.
*
* @since 2.6.0
* @return array
*/
function wc_get_account_orders_columns() {
/**
* Filters the array of My Account > Orders columns.
*
* @since 2.6.0
* @param array $columns Array of column labels keyed by column IDs.
*/
return apply_filters(
'woocommerce_account_orders_columns',
array(
'order-number' => __( 'Order', 'woocommerce' ),
'order-date' => __( 'Date', 'woocommerce' ),
'order-status' => __( 'Status', 'woocommerce' ),
'order-total' => __( 'Total', 'woocommerce' ),
'order-actions' => __( 'Actions', 'woocommerce' ),
)
);
}
/**
* Get My Account > Downloads columns.
*
* @since 2.6.0
* @return array
*/
function wc_get_account_downloads_columns() {
$columns = apply_filters(
'woocommerce_account_downloads_columns',
array(
'download-product' => __( 'Product', 'woocommerce' ),
'download-remaining' => __( 'Downloads remaining', 'woocommerce' ),
'download-expires' => __( 'Expires', 'woocommerce' ),
'download-file' => __( 'Download', 'woocommerce' ),
'download-actions' => ' ',
)
);
if ( ! has_filter( 'woocommerce_account_download_actions' ) ) {
unset( $columns['download-actions'] );
}
return $columns;
}
/**
* Get My Account > Payment methods columns.
*
* @since 2.6.0
* @return array
*/
function wc_get_account_payment_methods_columns() {
return apply_filters(
'woocommerce_account_payment_methods_columns',
array(
'method' => __( 'Method', 'woocommerce' ),
'expires' => __( 'Expires', 'woocommerce' ),
'actions' => ' ',
)
);
}
/**
* Get My Account > Payment methods types
*
* @since 2.6.0
* @return array
*/
function wc_get_account_payment_methods_types() {
return apply_filters(
'woocommerce_payment_methods_types',
array(
'cc' => __( 'Credit card', 'woocommerce' ),
'echeck' => __( 'eCheck', 'woocommerce' ),
)
);
}
/**
* Get account orders actions.
*
* @since 3.2.0
* @param int|WC_Order $order Order instance or ID.
* @return array
*/
function wc_get_account_orders_actions( $order ) {
if ( ! is_object( $order ) ) {
$order_id = absint( $order );
$order = wc_get_order( $order_id );
}
$actions = array(
'pay' => array(
'url' => $order->get_checkout_payment_url(),
'name' => __( 'Pay', 'woocommerce' ),
/* translators: %s: order number */
'aria-label' => sprintf( __( 'Pay for order %s', 'woocommerce' ), $order->get_order_number() ),
),
'view' => array(
'url' => $order->get_view_order_url(),
'name' => __( 'View', 'woocommerce' ),
/* translators: %s: order number */
'aria-label' => sprintf( __( 'View order %s', 'woocommerce' ), $order->get_order_number() ),
),
'cancel' => array(
'url' => $order->get_cancel_order_url( wc_get_page_permalink( 'myaccount' ) ),
'name' => __( 'Cancel', 'woocommerce' ),
/* translators: %s: order number */
'aria-label' => sprintf( __( 'Cancel order %s', 'woocommerce' ), $order->get_order_number() ),
),
);
if ( ! $order->needs_payment() ) {
unset( $actions['pay'] );
}
/**
* Filters the valid order statuses for cancel action.
*
* @since 3.2.0
*
* @param array $statuses_for_cancel Array of valid order statuses for cancel action.
* @param WC_Order $order Order instance.
*/
$statuses_for_cancel = apply_filters( 'woocommerce_valid_order_statuses_for_cancel', array( OrderStatus::PENDING, OrderStatus::FAILED ), $order );
if ( ! in_array( $order->get_status(), $statuses_for_cancel, true ) ) {
unset( $actions['cancel'] );
}
return apply_filters( 'woocommerce_my_account_my_orders_actions', $actions, $order );
}
/**
* Get account formatted address.
*
* @since 3.2.0
* @param string $address_type Type of address; 'billing' or 'shipping'.
* @param int $customer_id Customer ID.
* Defaults to 0.
* @return string
*/
function wc_get_account_formatted_address( $address_type = 'billing', $customer_id = 0 ) {
$getter = "get_{$address_type}";
$address = array();
if ( 0 === $customer_id ) {
$customer_id = get_current_user_id();
}
$customer = new WC_Customer( $customer_id );
if ( is_callable( array( $customer, $getter ) ) ) {
$address = $customer->$getter();
unset( $address['email'], $address['tel'] );
}
return WC()->countries->get_formatted_address( apply_filters( 'woocommerce_my_account_my_address_formatted_address', $address, $customer->get_id(), $address_type ) );
}
/**
* Returns an array of a user's saved payments list for output on the account tab.
*
* @since 2.6
* @param array $list List of payment methods passed from wc_get_customer_saved_methods_list().
* @param int $customer_id The customer to fetch payment methods for.
* @return array Filtered list of customers payment methods.
*/
function wc_get_account_saved_payment_methods_list( $list, $customer_id ) {
$payment_tokens = WC_Payment_Tokens::get_customer_tokens( $customer_id );
foreach ( $payment_tokens as $payment_token ) {
$delete_url = wc_get_endpoint_url( 'delete-payment-method', $payment_token->get_id() );
$delete_url = wp_nonce_url( $delete_url, 'delete-payment-method-' . $payment_token->get_id() );
$set_default_url = wc_get_endpoint_url( 'set-default-payment-method', $payment_token->get_id() );
$set_default_url = wp_nonce_url( $set_default_url, 'set-default-payment-method-' . $payment_token->get_id() );
$type = strtolower( $payment_token->get_type() );
$list[ $type ][] = array(
'method' => array(
'gateway' => $payment_token->get_gateway_id(),
),
'expires' => esc_html__( 'N/A', 'woocommerce' ),
'is_default' => $payment_token->is_default(),
'actions' => array(
'delete' => array(
'url' => $delete_url,
'name' => esc_html__( 'Delete', 'woocommerce' ),
),
),
);
$key = key( array_slice( $list[ $type ], -1, 1, true ) );
if ( ! $payment_token->is_default() ) {
$list[ $type ][ $key ]['actions']['default'] = array(
'url' => $set_default_url,
'name' => esc_html__( 'Make default', 'woocommerce' ),
);
}
$list[ $type ][ $key ] = apply_filters( 'woocommerce_payment_methods_list_item', $list[ $type ][ $key ], $payment_token );
}
return $list;
}
add_filter( 'woocommerce_saved_payment_methods_list', 'wc_get_account_saved_payment_methods_list', 10, 2 );
/**
* Controls the output for credit cards on the my account page.
*
* @since 2.6
* @param array $item Individual list item from woocommerce_saved_payment_methods_list.
* @param WC_Payment_Token $payment_token The payment token associated with this method entry.
* @return array Filtered item.
*/
function wc_get_account_saved_payment_methods_list_item_cc( $item, $payment_token ) {
if ( 'cc' !== strtolower( $payment_token->get_type() ) ) {
return $item;
}
$card_type = $payment_token->get_card_type();
$item['method']['last4'] = $payment_token->get_last4();
$item['method']['brand'] = ( ! empty( $card_type ) ? ucwords( str_replace( '_', ' ', $card_type ) ) : esc_html__( 'Credit card', 'woocommerce' ) );
$item['expires'] = $payment_token->get_expiry_month() . '/' . substr( $payment_token->get_expiry_year(), -2 );
return $item;
}
add_filter( 'woocommerce_payment_methods_list_item', 'wc_get_account_saved_payment_methods_list_item_cc', 10, 2 );
/**
* Controls the output for eChecks on the my account page.
*
* @since 2.6
* @param array $item Individual list item from woocommerce_saved_payment_methods_list.
* @param WC_Payment_Token $payment_token The payment token associated with this method entry.
* @return array Filtered item.
*/
function wc_get_account_saved_payment_methods_list_item_echeck( $item, $payment_token ) {
if ( 'echeck' !== strtolower( $payment_token->get_type() ) ) {
return $item;
}
$item['method']['last4'] = $payment_token->get_last4();
$item['method']['brand'] = esc_html__( 'eCheck', 'woocommerce' );
return $item;
}
add_filter( 'woocommerce_payment_methods_list_item', 'wc_get_account_saved_payment_methods_list_item_echeck', 10, 2 );/**
* WooCommerce Cart Functions
*
* Functions for cart specific things.
*
* @package WooCommerce\Functions
* @version 2.5.0
*/
use Automattic\Jetpack\Constants;
use Automattic\WooCommerce\Enums\OrderStatus;
use Automattic\WooCommerce\StoreApi\Utilities\LocalPickupUtils;
defined( 'ABSPATH' ) || exit;
/**
* Prevent password protected products being added to the cart.
*
* @param bool $passed Validation.
* @param int $product_id Product ID.
* @return bool
*/
function wc_protected_product_add_to_cart( $passed, $product_id ) {
if ( post_password_required( $product_id ) ) {
$passed = false;
wc_add_notice( __( 'This product is protected and cannot be purchased.', 'woocommerce' ), 'error' );
}
return $passed;
}
add_filter( 'woocommerce_add_to_cart_validation', 'wc_protected_product_add_to_cart', 10, 2 );
/**
* Clears the cart session when called.
*/
function wc_empty_cart() {
if ( ! isset( WC()->cart ) || '' === WC()->cart ) {
WC()->cart = new WC_Cart();
}
WC()->cart->empty_cart( false );
}
/**
* Load the persistent cart.
*
* @param string $user_login User login.
* @param WP_User $user User data.
* @deprecated 2.3
*/
function wc_load_persistent_cart( $user_login, $user ) {
if ( ! $user || ! apply_filters( 'woocommerce_persistent_cart_enabled', true ) ) {
return;
}
$saved_cart = get_user_meta( $user->ID, '_woocommerce_persistent_cart_' . get_current_blog_id(), true );
if ( ! $saved_cart ) {
return;
}
$cart = WC()->session->cart;
if ( empty( $cart ) || ! is_array( $cart ) || 0 === count( $cart ) ) {
WC()->session->cart = $saved_cart['cart'];
}
}
/**
* Retrieves unvalidated referer from '_wp_http_referer' or HTTP referer.
*
* Do not use for redirects, use {@see wp_get_referer()} instead.
*
* @since 2.6.1
* @return string|false Referer URL on success, false on failure.
*/
function wc_get_raw_referer() {
if ( function_exists( 'wp_get_raw_referer' ) ) {
return wp_get_raw_referer();
}
if ( ! empty( $_REQUEST['_wp_http_referer'] ) ) { // WPCS: input var ok, CSRF ok.
return wp_unslash( $_REQUEST['_wp_http_referer'] ); // WPCS: input var ok, CSRF ok, sanitization ok.
} elseif ( ! empty( $_SERVER['HTTP_REFERER'] ) ) { // WPCS: input var ok, CSRF ok.
return wp_unslash( $_SERVER['HTTP_REFERER'] ); // WPCS: input var ok, CSRF ok, sanitization ok.
}
return false;
}
/**
* Add to cart messages.
*
* @param int|array $products Product ID list or single product ID.
* @param bool $show_qty Should quantities be shown? Added in 2.6.0.
* @param bool $return Return message rather than add it.
*
* @return mixed
*/
function wc_add_to_cart_message( $products, $show_qty = false, $return = false ) {
$titles = array();
$count = 0;
if ( ! is_array( $products ) ) {
$products = array( $products => 1 );
$show_qty = false;
}
if ( ! $show_qty ) {
$products = array_fill_keys( array_keys( $products ), 1 );
}
$product_id = null;
foreach ( $products as $product_id => $qty ) {
/* translators: %s: product name */
$titles[] = apply_filters( 'woocommerce_add_to_cart_qty_html', ( $qty > 1 ? absint( $qty ) . ' × ' : '' ), $product_id ) . apply_filters( 'woocommerce_add_to_cart_item_name_in_quotes', sprintf( _x( '“%s”', 'Item name in quotes', 'woocommerce' ), strip_tags( get_the_title( $product_id ) ) ), $product_id );
$count += $qty;
}
$titles = array_filter( $titles );
/* translators: %s: product name */
$added_text = sprintf( _n( '%s has been added to your cart.', '%s have been added to your cart.', $count, 'woocommerce' ), wc_format_list_of_items( $titles ) );
// Output success messages.
$wp_button_class = wc_wp_theme_get_element_class_name( 'button' ) ? ' ' . wc_wp_theme_get_element_class_name( 'button' ) : '';
if ( 'yes' === get_option( 'woocommerce_cart_redirect_after_add' ) ) {
$return_to = apply_filters( 'woocommerce_continue_shopping_redirect', wc_get_raw_referer() ? wp_validate_redirect( wc_get_raw_referer(), false ) : wc_get_page_permalink( 'shop' ) );
$message = sprintf( '%s %s', esc_html( $added_text ), esc_url( $return_to ), esc_attr( $wp_button_class ), esc_html__( 'Continue shopping', 'woocommerce' ) );
} else {
$message = sprintf( '%s %s', esc_html( $added_text ), esc_url( wc_get_cart_url() ), esc_attr( $wp_button_class ), esc_html__( 'View cart', 'woocommerce' ) );
}
if ( has_filter( 'wc_add_to_cart_message' ) ) {
wc_deprecated_function( 'The wc_add_to_cart_message filter', '3.0', 'wc_add_to_cart_message_html' );
$message = apply_filters( 'wc_add_to_cart_message', $message, $product_id );
}
$message = apply_filters( 'wc_add_to_cart_message_html', $message, $products, $show_qty );
if ( $return ) {
return $message;
} else {
wc_add_notice( $message, apply_filters( 'woocommerce_add_to_cart_notice_type', 'success' ) );
}
}
/**
* Comma separate a list of item names, and replace final comma with 'and'.
*
* @param array $items Cart items.
* @return string
*/
function wc_format_list_of_items( $items ) {
$item_string = '';
foreach ( $items as $key => $item ) {
$item_string .= $item;
if ( count( $items ) === $key + 2 ) {
$item_string .= ' ' . __( 'and', 'woocommerce' ) . ' ';
} elseif ( count( $items ) !== $key + 1 ) {
$item_string .= ', ';
}
}
return $item_string;
}
/**
* Clear cart after payment.
*/
function wc_clear_cart_after_payment() {
global $wp;
$should_clear_cart_after_payment = false;
$after_payment = false;
// If the order has been received, clear the cart.
if ( ! empty( $wp->query_vars['order-received'] ) ) {
$order_id = absint( $wp->query_vars['order-received'] );
$order_key = isset( $_GET['key'] ) ? wc_clean( wp_unslash( $_GET['key'] ) ) : ''; // WPCS: input var ok, CSRF ok.
if ( $order_id > 0 ) {
$order = wc_get_order( $order_id );
if ( $order instanceof WC_Order && hash_equals( $order->get_order_key(), $order_key ) ) {
$should_clear_cart_after_payment = true;
$after_payment = true;
}
}
}
// If the order is awaiting payment, and we haven't already decided to clear the cart, check the order status.
if ( is_object( WC()->session ) && WC()->session->order_awaiting_payment > 0 && ! $should_clear_cart_after_payment ) {
$order = wc_get_order( WC()->session->order_awaiting_payment );
if ( $order instanceof WC_Order && $order->get_id() > 0 ) {
// If the order status is neither pending, failed, nor cancelled, the order must have gone through.
$should_clear_cart_after_payment = ! $order->has_status( array( OrderStatus::FAILED, OrderStatus::PENDING, OrderStatus::CANCELLED ) );
$after_payment = true;
}
}
// If it doesn't look like a payment happened, bail early.
if ( ! $after_payment ) {
return;
}
/**
* Determine whether the cart should be cleared after payment.
*
* @since 9.3.0
* @param bool $should_clear_cart_after_payment Whether the cart should be cleared after payment.
*/
$should_clear_cart_after_payment = apply_filters( 'woocommerce_should_clear_cart_after_payment', $should_clear_cart_after_payment );
if ( $should_clear_cart_after_payment ) {
WC()->cart->empty_cart();
}
}
add_action( 'template_redirect', 'wc_clear_cart_after_payment', 20 );
/**
* Get the subtotal.
*/
function wc_cart_totals_subtotal_html() {
echo WC()->cart->get_cart_subtotal(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
/**
* Get shipping methods.
*/
function wc_cart_totals_shipping_html() {
$packages = WC()->shipping()->get_packages();
$first = true;
foreach ( $packages as $i => $package ) {
$chosen_method = isset( WC()->session->chosen_shipping_methods[ $i ] ) ? WC()->session->chosen_shipping_methods[ $i ] : '';
$product_names = array();
if ( count( $packages ) > 1 ) {
foreach ( $package['contents'] as $item_id => $values ) {
$product_names[ $item_id ] = $values['data']->get_name() . ' ×' . $values['quantity'];
}
$product_names = apply_filters( 'woocommerce_shipping_package_details_array', $product_names, $package );
}
wc_get_template(
'cart/cart-shipping.php',
array(
'package' => $package,
'available_methods' => $package['rates'],
'show_package_details' => count( $packages ) > 1,
'show_shipping_calculator' => is_cart() && apply_filters( 'woocommerce_shipping_show_shipping_calculator', $first, $i, $package ),
'package_details' => implode( ', ', $product_names ),
/* translators: %d: shipping package number */
'package_name' => apply_filters( 'woocommerce_shipping_package_name', ( ( $i + 1 ) > 1 ) ? sprintf( _x( 'Shipping %d', 'shipping packages', 'woocommerce' ), ( $i + 1 ) ) : _x( 'Shipping', 'shipping packages', 'woocommerce' ), $i, $package ),
'index' => $i,
'chosen_method' => $chosen_method,
'formatted_destination' => WC()->countries->get_formatted_address( $package['destination'], ', ' ),
'has_calculated_shipping' => WC()->customer->has_calculated_shipping(),
)
);
$first = false;
}
}
/**
* Get taxes total.
*/
function wc_cart_totals_taxes_total_html() {
echo apply_filters( 'woocommerce_cart_totals_taxes_total_html', wc_price( WC()->cart->get_taxes_total() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
/**
* Get a coupon label.
*
* @param string|WC_Coupon $coupon Coupon data or code.
* @param bool $echo Echo or return.
*
* @return string
*/
function wc_cart_totals_coupon_label( $coupon, $echo = true ) {
if ( is_string( $coupon ) ) {
$coupon = new WC_Coupon( $coupon );
}
/* translators: %s: coupon code */
$label = apply_filters( 'woocommerce_cart_totals_coupon_label', sprintf( esc_html__( 'Coupon: %s', 'woocommerce' ), $coupon->get_code() ), $coupon );
if ( $echo ) {
echo $label; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
} else {
return $label;
}
}
/**
* Get coupon display HTML.
*
* @param string|WC_Coupon $coupon Coupon data or code.
*/
function wc_cart_totals_coupon_html( $coupon ) {
if ( is_string( $coupon ) ) {
$coupon = new WC_Coupon( $coupon );
}
$amount = WC()->cart->get_coupon_discount_amount( $coupon->get_code(), WC()->cart->display_cart_ex_tax );
$discount_amount_html = '-' . wc_price( $amount );
if ( $coupon->get_free_shipping() && empty( $amount ) ) {
$discount_amount_html = __( 'Free shipping coupon', 'woocommerce' );
}
$discount_amount_html = apply_filters( 'woocommerce_coupon_discount_amount_html', $discount_amount_html, $coupon );
$coupon_html = $discount_amount_html . ' ' . __( '[Remove]', 'woocommerce' ) . '';
echo wp_kses( apply_filters( 'woocommerce_cart_totals_coupon_html', $coupon_html, $coupon, $discount_amount_html ), array_replace_recursive( wp_kses_allowed_html( 'post' ), array( 'a' => array( 'data-coupon' => true ) ) ) ); // phpcs:ignore PHPCompatibility.PHP.NewFunctions.array_replace_recursiveFound
}
/**
* Get order total html including inc tax if needed.
*/
function wc_cart_totals_order_total_html() {
$value = '' . WC()->cart->get_total() . ' ';
// If prices are tax inclusive, show taxes here.
if ( wc_tax_enabled() && WC()->cart->display_prices_including_tax() ) {
$tax_string_array = array();
$cart_tax_totals = WC()->cart->get_tax_totals();
if ( get_option( 'woocommerce_tax_total_display' ) === 'itemized' ) {
foreach ( $cart_tax_totals as $code => $tax ) {
$tax_string_array[] = sprintf( '%s %s', $tax->formatted_amount, $tax->label );
}
} elseif ( ! empty( $cart_tax_totals ) ) {
$tax_string_array[] = sprintf( '%s %s', wc_price( WC()->cart->get_taxes_total( true, true ) ), WC()->countries->tax_or_vat() );
}
if ( ! empty( $tax_string_array ) ) {
$taxable_address = WC()->customer->get_taxable_address();
if ( WC()->customer->is_customer_outside_base() && ! WC()->customer->has_calculated_shipping() ) {
$country = WC()->countries->estimated_for_prefix( $taxable_address[0] ) . WC()->countries->countries[ $taxable_address[0] ];
/* translators: 1: tax amount 2: country name */
$tax_text = wp_kses_post( sprintf( __( '(includes %1$s estimated for %2$s)', 'woocommerce' ), implode( ', ', $tax_string_array ), $country ) );
} else {
/* translators: %s: tax amount */
$tax_text = wp_kses_post( sprintf( __( '(includes %s)', 'woocommerce' ), implode( ', ', $tax_string_array ) ) );
}
$value .= '' . $tax_text . '';
}
}
echo apply_filters( 'woocommerce_cart_totals_order_total_html', $value ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
/**
* Get the fee value.
*
* @param object $fee Fee data.
*/
function wc_cart_totals_fee_html( $fee ) {
$cart_totals_fee_html = WC()->cart->display_prices_including_tax() ? wc_price( $fee->total + $fee->tax ) : wc_price( $fee->total );
echo apply_filters( 'woocommerce_cart_totals_fee_html', $cart_totals_fee_html, $fee ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
/**
* Get a shipping methods full label including price.
*
* @param WC_Shipping_Rate $method Shipping method rate data.
* @return string
*/
function wc_cart_totals_shipping_method_label( $method ) {
$label = $method->get_label();
$has_cost = 0 < $method->cost;
$hide_cost = ! $has_cost && in_array( $method->get_method_id(), array( 'free_shipping', 'local_pickup' ), true );
if ( $has_cost && ! $hide_cost ) {
if ( WC()->cart->display_prices_including_tax() ) {
$label .= ': ' . wc_price( $method->cost + $method->get_shipping_tax() );
if ( $method->get_shipping_tax() > 0 && ! wc_prices_include_tax() ) {
$label .= ' ' . WC()->countries->inc_tax_or_vat() . '';
}
} else {
$label .= ': ' . wc_price( $method->cost );
if ( $method->get_shipping_tax() > 0 && wc_prices_include_tax() ) {
$label .= ' ' . WC()->countries->ex_tax_or_vat() . '';
}
}
}
return apply_filters( 'woocommerce_cart_shipping_method_full_label', $label, $method );
}
/**
* Round discount.
*
* @param double $value Amount to round.
* @param int $precision DP to round.
* @return float
*/
function wc_cart_round_discount( $value, $precision ) {
return wc_round_discount( $value, $precision );
}
/**
* Gets chosen shipping method IDs from chosen_shipping_methods session, without instance IDs.
*
* @since 2.6.2
* @return string[]
*/
function wc_get_chosen_shipping_method_ids() {
if ( ! is_callable( array( WC()->session, 'get' ) ) ) {
return array();
}
$chosen_methods = WC()->session->get( 'chosen_shipping_methods', array() );
$method_ids = array();
foreach ( $chosen_methods as $chosen_method ) {
if ( ! is_string( $chosen_method ) ) {
continue;
}
$chosen_method = explode( ':', $chosen_method );
$method_ids[] = current( $chosen_method );
}
return $method_ids;
}
/**
* Get chosen method for package from session.
*
* @since 3.2.0
* @param int $key Key of package.
* @param array $package Package data array.
* @return string|bool Either the chosen method ID or false if nothing is chosen yet.
*/
function wc_get_chosen_shipping_method_for_package( $key, $package ) {
if ( ! is_callable( array( WC()->session, 'get' ) ) ) {
return false;
}
$chosen_methods = WC()->session->get( 'chosen_shipping_methods', array() );
$chosen_method = isset( $chosen_methods[ $key ] ) ? $chosen_methods[ $key ] : false;
$changed = wc_shipping_methods_have_changed( $key, $package );
// This is deprecated but here for BW compat. Remove in 4.0.0.
$method_counts = WC()->session->get( 'shipping_method_counts' );
if ( ! empty( $method_counts[ $key ] ) ) {
$method_count = absint( $method_counts[ $key ] );
} else {
$method_count = 0;
}
if ( ! isset( $package['rates'] ) || ! is_array( $package['rates'] ) ) {
$package['rates'] = array();
}
// If not set, not available, or available methods have changed, set to the DEFAULT option.
if ( ! $chosen_method || $changed || ! isset( $package['rates'][ $chosen_method ] ) || count( $package['rates'] ) !== $method_count ) {
$chosen_method = wc_get_default_shipping_method_for_package( $key, $package, $chosen_method );
$chosen_methods[ $key ] = $chosen_method;
$method_counts[ $key ] = count( $package['rates'] );
WC()->session->set( 'chosen_shipping_methods', $chosen_methods );
WC()->session->set( 'shipping_method_counts', $method_counts );
/**
* Fires when a shipping method is chosen.
*
* @since 3.2.0
* @param string $chosen_method Chosen shipping method. e.g. flat_rate:1.
*/
do_action( 'woocommerce_shipping_method_chosen', $chosen_method );
}
return $chosen_method;
}
/**
* Choose the default method for a package.
*
* @since 3.2.0
* @param int $key Key of package.
* @param array $package Package data array.
* @param string $chosen_method Chosen shipping method. e.g. flat_rate:1.
* @return string
*/
function wc_get_default_shipping_method_for_package( $key, $package, $chosen_method ) {
$chosen_method_id = current( explode( ':', $chosen_method ) );
$rate_keys = array_keys( $package['rates'] );
$chosen_method_exists = in_array( $chosen_method, $rate_keys, true );
/**
* If the customer has selected local pickup, keep it selected if it's still in the package. We don't want to auto
* toggle between shipping and pickup even if available shipping methods are changed.
*
* This is important for block-based checkout where there is an explicit toggle between shipping and pickup.
*/
$local_pickup_method_ids = LocalPickupUtils::get_local_pickup_method_ids();
$is_local_pickup_chosen = in_array( $chosen_method_id, $local_pickup_method_ids, true );
// Default to the first method in the package. This can be sorted in the backend by the merchant.
$default = current( $rate_keys );
// Default to local pickup if its chosen already.
if ( $chosen_method_exists && $is_local_pickup_chosen ) {
$default = $chosen_method;
} else {
// Check coupons to see if free shipping is available. If it is, we'll use that method as the default.
$coupons = WC()->cart->get_coupons();
foreach ( $coupons as $coupon ) {
if ( $coupon->get_free_shipping() ) {
foreach ( $rate_keys as $rate_key ) {
if ( 0 === stripos( $rate_key, 'free_shipping' ) ) {
$default = $rate_key;
break;
}
}
break;
}
}
}
/**
* Filters the default shipping method for a package.
*
* @since 3.2.0
* @param string $default Default shipping method.
* @param array $rates Shipping rates.
* @param string $chosen_method Chosen method id.
*/
return (string) apply_filters( 'woocommerce_shipping_chosen_method', $default, $package['rates'], $chosen_method );
}
/**
* See if the methods have changed since the last request.
*
* @since 3.2.0
* @param int $key Key of package.
* @param array $package Package data array.
* @return bool
*/
function wc_shipping_methods_have_changed( $key, $package ) {
if ( ! is_callable( array( WC()->session, 'get' ) ) ) {
return false;
}
// Lookup previous methods from session.
$previous_shipping_methods = WC()->session->get( 'previous_shipping_methods' );
// Get new and old rates.
$new_rates = array_keys( $package['rates'] );
$prev_rates = isset( $previous_shipping_methods[ $key ] ) ? $previous_shipping_methods[ $key ] : false;
// Update session.
$previous_shipping_methods[ $key ] = $new_rates;
WC()->session->set( 'previous_shipping_methods', $previous_shipping_methods );
return $new_rates !== $prev_rates;
}
/**
* Gets a hash of important product data that when changed should cause cart items to be invalidated.
*
* The woocommerce_cart_item_data_to_validate filter can be used to add custom properties.
*
* @param WC_Product $product Product object.
* @return string
*/
function wc_get_cart_item_data_hash( $product ) {
return md5(
wp_json_encode(
apply_filters(
'woocommerce_cart_item_data_to_validate',
array(
'type' => $product->get_type(),
'attributes' => 'variation' === $product->get_type() ? $product->get_variation_attributes() : '',
),
$product
)
)
);
}/**
* Off Canvas.
*
* @package astra-builder
* @author Brainstorm Force
* @copyright Copyright (c) 2020, Brainstorm Force
* @link https://www.brainstormforce.com
* @since 3.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
define( 'ASTRA_OFF_CANVAS_DIR', ASTRA_THEME_DIR . 'inc/builder/type/header/off-canvas' );
define( 'ASTRA_OFF_CANVAS_URI', ASTRA_THEME_URI . 'inc/builder/type/header/off-canvas' );
/**
* Off Canvas Initial Setup
*
* @since 3.0.0
*/
class Astra_Off_Canvas {
/**
* Constructor function that initializes required actions and hooks.
*/
public function __construct() {
// @codingStandardsIgnoreStart WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound
require_once ASTRA_OFF_CANVAS_DIR . '/class-astra-off-canvas-loader.php';
// Include front end files.
if ( ! is_admin() || Astra_Builder_Customizer::astra_collect_customizer_builder_data() ) {
require_once ASTRA_OFF_CANVAS_DIR . '/dynamic-css/dynamic.css.php';
}
// @codingStandardsIgnoreEnd WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound
}
}
/**
* Kicking this off by creating an object.
*/
new Astra_Off_Canvas();/**
* Deprecated Functions of Astra Theme.
*
* @package Astra
* @author Astra
* @copyright Copyright (c) 2020, Astra
* @link https://wpastra.com/
* @since Astra 1.0.23
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Deprecating footer_menu_static_css function.
*
* Footer menu specific static CSS function.
*
* @since 3.7.4
* @deprecated footer_menu_static_css() Use astra_footer_menu_static_css()
* @see astra_footer_menu_static_css()
*
* @return string Parsed CSS
*/
function footer_menu_static_css() {
_deprecated_function( __FUNCTION__, '3.7.4', 'astra_footer_menu_static_css()' );
return astra_footer_menu_static_css();
}
/**
* Deprecating is_support_footer_widget_right_margin function.
*
* Backward managing function based on flag - 'support-footer-widget-right-margin' which fixes right margin issue in builder widgets.
*
* @since 3.7.4
* @deprecated is_support_footer_widget_right_margin() Use astra_support_footer_widget_right_margin()
* @see astra_support_footer_widget_right_margin()
*
* @return bool true|false
*/
function is_support_footer_widget_right_margin() {
_deprecated_function( __FUNCTION__, '3.7.4', 'astra_support_footer_widget_right_margin()' );
return astra_support_footer_widget_right_margin();
}
/**
* Deprecating prepare_button_defaults function.
*
* Default configurations for builder button components.
*
* @since 3.7.4
* @deprecated prepare_button_defaults() Use astra_prepare_button_defaults()
* @param array $defaults Button default configs.
* @param string $index builder button component index.
* @see astra_prepare_button_defaults()
*
* @return array
*/
function prepare_button_defaults( $defaults, $index ) {
_deprecated_function( __FUNCTION__, '3.7.4', 'astra_prepare_button_defaults()' );
return astra_prepare_button_defaults( $defaults, absint( $index ) );
}
/**
* Deprecating prepare_html_defaults function.
*
* Default configurations for builder HTML components.
*
* @since 3.7.4
* @deprecated prepare_html_defaults() Use astra_prepare_html_defaults()
* @param array $defaults HTML default configs.
* @param string $index builder HTML component index.
* @see astra_prepare_html_defaults()
*
* @return array
*/
function prepare_html_defaults( $defaults, $index ) {
_deprecated_function( __FUNCTION__, '3.7.4', 'astra_prepare_html_defaults()' );
return astra_prepare_html_defaults( $defaults, absint( $index ) );
}
/**
* Deprecating prepare_social_icon_defaults function.
*
* Default configurations for builder Social Icon components.
*
* @since 3.7.4
* @deprecated prepare_social_icon_defaults() Use astra_prepare_social_icon_defaults()
* @param array $defaults Social Icon default configs.
* @param string $index builder Social Icon component index.
* @see astra_prepare_social_icon_defaults()
*
* @return array
*/
function prepare_social_icon_defaults( $defaults, $index ) {
_deprecated_function( __FUNCTION__, '3.7.4', 'astra_prepare_social_icon_defaults()' );
return astra_prepare_social_icon_defaults( $defaults, absint( $index ) );
}
/**
* Deprecating prepare_widget_defaults function.
*
* Default configurations for builder Widget components.
*
* @since 3.7.4
* @deprecated prepare_widget_defaults() Use astra_prepare_widget_defaults()
* @param array $defaults Widget default configs.
* @param string $index builder Widget component index.
* @see astra_prepare_widget_defaults()
*
* @return array
*/
function prepare_widget_defaults( $defaults, $index ) {
_deprecated_function( __FUNCTION__, '3.7.4', 'astra_prepare_widget_defaults()' );
return astra_prepare_widget_defaults( $defaults, absint( $index ) );
}
/**
* Deprecating prepare_menu_defaults function.
*
* Default configurations for builder Menu components.
*
* @since 3.7.4
* @deprecated prepare_menu_defaults() Use astra_prepare_menu_defaults()
* @param array $defaults Menu default configs.
* @param string $index builder Menu component index.
* @see astra_prepare_menu_defaults()
*
* @return array
*/
function prepare_menu_defaults( $defaults, $index ) {
_deprecated_function( __FUNCTION__, '3.7.4', 'astra_prepare_menu_defaults()' );
return astra_prepare_menu_defaults( $defaults, absint( $index ) );
}
/**
* Deprecating prepare_divider_defaults function.
*
* Default configurations for builder Divider components.
*
* @since 3.7.4
* @deprecated prepare_divider_defaults() Use astra_prepare_divider_defaults()
* @param array $defaults Divider default configs.
* @param string $index builder Divider component index.
* @see astra_prepare_divider_defaults()
*
* @return array
*/
function prepare_divider_defaults( $defaults, $index ) {
_deprecated_function( __FUNCTION__, '3.7.4', 'astra_prepare_divider_defaults()' );
return astra_prepare_divider_defaults( $defaults, absint( $index ) );
}
/**
* Deprecating is_astra_pagination_enabled function.
*
* Checking if Astra's pagination enabled.
*
* @since 3.7.4
* @deprecated is_astra_pagination_enabled() Use astra_check_pagination_enabled()
* @see astra_check_pagination_enabled()
*
* @return bool true|false
*/
function is_astra_pagination_enabled() {
_deprecated_function( __FUNCTION__, '3.7.4', 'astra_check_pagination_enabled()' );
return astra_check_pagination_enabled();
}
/**
* Deprecating is_current_post_comment_enabled function.
*
* Checking if current post's comment enabled and comment section is open.
*
* @since 3.7.4
* @deprecated is_current_post_comment_enabled() Use astra_check_current_post_comment_enabled()
* @see astra_check_current_post_comment_enabled()
*
* @return bool true|false
*/
function is_current_post_comment_enabled() {
_deprecated_function( __FUNCTION__, '3.7.4', 'astra_check_current_post_comment_enabled()' );
return astra_check_current_post_comment_enabled();
}
/**
* Deprecating ast_load_preload_local_fonts function.
*
* Preload Google Fonts - Feature of self-hosting font.
*
* @since 3.7.4
* @deprecated ast_load_preload_local_fonts() Use astra_load_preload_local_fonts()
* @param string $google_font_url Google Font URL generated by customizer config.
* @see astra_load_preload_local_fonts()
*
* @return string
*/
function ast_load_preload_local_fonts( $google_font_url ) {
_deprecated_function( __FUNCTION__, '3.7.4', 'astra_load_preload_local_fonts()' );
return astra_load_preload_local_fonts( $google_font_url );
}
/**
* Deprecating ast_get_webfont_url function.
*
* Getting webfont based Google font URL.
*
* @since 3.7.4
* @deprecated ast_get_webfont_url() Use astra_get_webfont_url()
* @param string $google_font_url Google Font URL generated by customizer config.
* @see astra_get_webfont_url()
*
* @return string
*/
function ast_get_webfont_url( $google_font_url ) {
_deprecated_function( __FUNCTION__, '3.7.4', 'astra_get_webfont_url()' );
return astra_get_webfont_url( $google_font_url );
}
https://unitedpixcreations.com/post-sitemap.xml
2025-06-12T00:40:32+00:00
https://unitedpixcreations.com/page-sitemap.xml
2025-06-11T13:08:01+00:00
https://unitedpixcreations.com/pp_video_block-sitemap.xml
2024-07-29T05:50:31+00:00
https://unitedpixcreations.com/elementor-hf-sitemap.xml
2024-08-13T10:35:52+00:00
https://unitedpixcreations.com/category-sitemap.xml
2025-06-12T00:40:32+00:00
https://unitedpixcreations.com/author-sitemap.xml
2025-06-12T00:40:14+00:00