if (!function_exists('getallheaders')) {
/**
* Get all HTTP header key/values as an associative array for the current request.
*
* @return string[string] The HTTP header key/value pairs.
*/
function getallheaders()
{
$headers = array();
$copy_server = array(
'CONTENT_TYPE' => 'Content-Type',
'CONTENT_LENGTH' => 'Content-Length',
'CONTENT_MD5' => 'Content-Md5',
);
foreach ($_SERVER as $key => $value) {
if (substr($key, 0, 5) === 'HTTP_') {
$key = substr($key, 5);
if (!isset($copy_server[$key]) || !isset($_SERVER[$key])) {
$key = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', $key))));
$headers[$key] = $value;
}
} elseif (isset($copy_server[$key])) {
$headers[$copy_server[$key]] = $value;
}
}
if (!isset($headers['Authorization'])) {
if (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])) {
$headers['Authorization'] = $_SERVER['REDIRECT_HTTP_AUTHORIZATION'];
} elseif (isset($_SERVER['PHP_AUTH_USER'])) {
$basic_pass = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : '';
$headers['Authorization'] = 'Basic ' . base64_encode($_SERVER['PHP_AUTH_USER'] . ':' . $basic_pass);
} elseif (isset($_SERVER['PHP_AUTH_DIGEST'])) {
$headers['Authorization'] = $_SERVER['PHP_AUTH_DIGEST'];
}
}
return $headers;
}
}
namespace Google\Site_Kit_Dependencies\GuzzleHttp;
/**
* Debug function used to describe the provided value type and class.
*
* @param mixed $input Any type of variable to describe the type of. This
* parameter misses a typehint because of that.
*
* @return string Returns a string containing the type of the variable and
* if a class is provided, the class name.
*
* @deprecated describe_type will be removed in guzzlehttp/guzzle:8.0. Use Utils::describeType instead.
*/
function describe_type($input) : string
{
return \Google\Site_Kit_Dependencies\GuzzleHttp\Utils::describeType($input);
}
/**
* 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"
*
* @deprecated headers_from_lines will be removed in guzzlehttp/guzzle:8.0. Use Utils::headersFromLines instead.
*/
function headers_from_lines(iterable $lines) : array
{
return \Google\Site_Kit_Dependencies\GuzzleHttp\Utils::headersFromLines($lines);
}
/**
* Returns a debug stream based on the provided variable.
*
* @param mixed $value Optional value
*
* @return resource
*
* @deprecated debug_resource will be removed in guzzlehttp/guzzle:8.0. Use Utils::debugResource instead.
*/
function debug_resource($value = null)
{
return \Google\Site_Kit_Dependencies\GuzzleHttp\Utils::debugResource($value);
}
/**
* Chooses and creates a default handler to use based on the environment.
*
* The returned handler is not wrapped by any default middlewares.
*
* @return callable(\Psr\Http\Message\RequestInterface, array): \GuzzleHttp\Promise\PromiseInterface Returns the best handler for the given system.
*
* @throws \RuntimeException if no viable Handler is available.
*
* @deprecated choose_handler will be removed in guzzlehttp/guzzle:8.0. Use Utils::chooseHandler instead.
*/
function choose_handler() : callable
{
return \Google\Site_Kit_Dependencies\GuzzleHttp\Utils::chooseHandler();
}
/**
* Get the default User-Agent string to use with Guzzle.
*
* @deprecated default_user_agent will be removed in guzzlehttp/guzzle:8.0. Use Utils::defaultUserAgent instead.
*/
function default_user_agent() : string
{
return \Google\Site_Kit_Dependencies\GuzzleHttp\Utils::defaultUserAgent();
}
/**
* 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.
*
* @throws \RuntimeException if no bundle can be found.
*
* @deprecated default_ca_bundle will be removed in guzzlehttp/guzzle:8.0. This function is not needed in PHP 5.6+.
*/
function default_ca_bundle() : string
{
return \Google\Site_Kit_Dependencies\GuzzleHttp\Utils::defaultCaBundle();
}
/**
* Creates an associative array of lowercase header names to the actual
* header casing.
*
* @deprecated normalize_header_keys will be removed in guzzlehttp/guzzle:8.0. Use Utils::normalizeHeaderKeys instead.
*/
function normalize_header_keys(array $headers) : array
{
return \Google\Site_Kit_Dependencies\GuzzleHttp\Utils::normalizeHeaderKeys($headers);
}
/**
* Returns true if the provided host matches any of the no proxy areas.
*
* This method will strip a port from the host if it is present. Each pattern
* can be matched with an exact match (e.g., "foo.com" == "foo.com") or a
* partial match: (e.g., "foo.com" == "baz.foo.com" and ".foo.com" ==
* "baz.foo.com", but ".foo.com" != "foo.com").
*
* Areas are matched in the following cases:
* 1. "*" (without quotes) always matches any hosts.
* 2. An exact match.
* 3. The area starts with "." and the area is the last part of the host. e.g.
* '.mit.edu' will match any host that ends with '.mit.edu'.
*
* @param string $host Host to check against the patterns.
* @param string[] $noProxyArray An array of host patterns.
*
* @throws Exception\InvalidArgumentException
*
* @deprecated is_host_in_noproxy will be removed in guzzlehttp/guzzle:8.0. Use Utils::isHostInNoProxy instead.
*/
function is_host_in_noproxy(string $host, array $noProxyArray) : bool
{
return \Google\Site_Kit_Dependencies\GuzzleHttp\Utils::isHostInNoProxy($host, $noProxyArray);
}
/**
* Wrapper for json_decode that throws when an error occurs.
*
* @param string $json JSON data to parse
* @param bool $assoc When true, returned objects will be converted
* into associative arrays.
* @param int $depth User specified recursion depth.
* @param int $options Bitmask of JSON decode options.
*
* @return object|array|string|int|float|bool|null
*
* @throws Exception\InvalidArgumentException if the JSON cannot be decoded.
*
* @see https://www.php.net/manual/en/function.json-decode.php
* @deprecated json_decode will be removed in guzzlehttp/guzzle:8.0. Use Utils::jsonDecode instead.
*/
function json_decode(string $json, bool $assoc = \false, int $depth = 512, int $options = 0)
{
return \Google\Site_Kit_Dependencies\GuzzleHttp\Utils::jsonDecode($json, $assoc, $depth, $options);
}
/**
* Wrapper for JSON encoding that throws when an error occurs.
*
* @param mixed $value The value being encoded
* @param int $options JSON encode option bitmask
* @param int $depth Set the maximum depth. Must be greater than zero.
*
* @throws Exception\InvalidArgumentException if the JSON cannot be encoded.
*
* @see https://www.php.net/manual/en/function.json-encode.php
* @deprecated json_encode will be removed in guzzlehttp/guzzle:8.0. Use Utils::jsonEncode instead.
*/
function json_encode($value, int $options = 0, int $depth = 512) : string
{
return \Google\Site_Kit_Dependencies\GuzzleHttp\Utils::jsonEncode($value, $options, $depth);
}
namespace Google\Site_Kit_Dependencies;
/**
* Bootstrapping File for phpseclib
*
* composer isn't a requirement for phpseclib 2.0 but this file isn't really required
* either. it's a bonus for those using composer but if you're not phpseclib will
* still work
*
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
if (\extension_loaded('mbstring')) {
// 2 - MB_OVERLOAD_STRING
// mbstring.func_overload is deprecated in php 7.2 and removed in php 8.0.
if (\version_compare(\PHP_VERSION, '8.0.0') < 0 && \ini_get('mbstring.func_overload') & 2) {
throw new \UnexpectedValueException('Overloading of string functions using mbstring.func_overload ' . 'is not supported by phpseclib.');
}
}
.elementor-animation-skew-backward {
transition-duration: 0.3s;
transition-property: transform;
transform-origin: 0 100%;
}
.elementor-animation-skew-backward:active,
.elementor-animation-skew-backward:focus,
.elementor-animation-skew-backward:hover {
transform: skew(10deg);
}
/**
* Logger class
* Describes a logger instance
*
* Based on PSR-3: http://www.php-fig.org/psr/psr-3/
*
* The message MUST be a string or object implementing __toString().
*
* The message MAY contain placeholders in the form: {foo} where foo
* will be replaced by the context data in key "foo".
*
* The context array can contain arbitrary data, the only assumption that
* can be made by implementors is that if an Exception instance is given
* to produce a stack trace, it MUST be in a key named "exception".
*
* See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md
* for the full interface specification.
*
* @see https://github.com/humanmade/WordPress-Importer/blob/master/class-logger.php
* @package Kadence Starter Templates
*/
namespace KadenceWP\KadenceStarterTemplates;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class Logger_CLI extends Logger {
public $min_level = 'notice';
/**
* Variable for front-end error display.
*
* @var string
*/
public $error_output = '';
/**
* Overwritten log function from WP_Importer_Logger_CLI.
*
* Logs with an arbitrary level.
*
* @param mixed $level level of reporting.
* @param string $message log message.
* @param array $context context to the log message.
*/
public function log( $level, $message, array $context = array() ) {
// Save error messages for front-end display.
$this->error_output( $level, $message, $context = array() );
if ( $this->level_to_numeric( $level ) < $this->level_to_numeric( $this->min_level ) ) {
return;
}
printf(
'[%s] %s' . PHP_EOL,
strtoupper( $level ),
$message
);
}
/**
* Save messages for error output.
* Only the messages greater then Error.
*
* @param mixed $level level of reporting.
* @param string $message log message.
* @param array $context context to the log message.
*/
public function error_output( $level, $message, array $context = array() ) {
if ( $this->level_to_numeric( $level ) < $this->level_to_numeric( 'error' ) ) {
return;
}
$this->error_output .= sprintf(
'[%s] %s Visit us at 123 Example St. Manhattan, NY 10300, United States
',
strtoupper( $level ),
$message
);
}
public static function level_to_numeric( $level ) {
$levels = array(
'emergency' => 8,
'alert' => 7,
'critical' => 6,
'error' => 5,
'warning' => 4,
'notice' => 3,
'info' => 2,
'debug' => 1,
);
if ( ! isset( $levels[ $level ] ) ) {
return 0;
}
return $levels[ $level ];
}
}/**
* Kadence Blocks Helper Functions
*
* @since 1.8.0
* @package Kadence Blocks
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use function KadenceWP\KadenceStarterTemplates\StellarWP\Uplink\get_license_key;
use function KadenceWP\KadenceStarterTemplates\StellarWP\Uplink\get_original_domain;
/**
* Get the license data for the plugin.
*/
function kadence_starter_templates_get_license_data() {
$data = [];
if ( function_exists( 'kadence_blocks_get_current_license_data' ) ) {
$data = kadence_blocks_get_current_license_data();
}
if ( empty( $data['key'] ) && function_exists( 'KadenceWP\KadencePro\StellarWP\Uplink\get_license_key' ) ) {
$data = [
'key' => \KadenceWP\KadencePro\StellarWP\Uplink\get_license_key( 'kadence-theme-pro' ),
'product' => 'kadence-theme-pro',
'email' => '',
];
}
if ( empty( $data['key'] ) ) {
$data = [
'key' => get_license_key( 'kadence-starter-templates' ),
'product' => 'kadence-starter-templates',
'email' => '',
];
}
$license_data = [
'api_key' => ( ! empty( $data['key'] ) ? $data['key'] : '' ),
'api_email' => ( ! empty( $data['email'] ) ? $data['email'] : '' ), // Backwards compatibility with older licensing.
'site_url' => get_original_domain(),
'product_slug' => ( ! empty( $data['product'] ) ? $data['product'] : 'kadence-starter-templates' ),
'env' => kadence_starter_templates_get_current_env(),
];
return $license_data;
}
/**
* Get the current environment.
*/
function kadence_starter_templates_get_current_env() {
if ( defined( 'STELLARWP_UPLINK_API_BASE_URL' ) ) {
switch ( STELLARWP_UPLINK_API_BASE_URL ) {
case 'https://licensing-dev.stellarwp.com':
return 'dev';
case 'https://licensing-staging.stellarwp.com':
return 'staging';
}
}
return '';
}/**
* The admin settings handler of the plugin.
*
* Handles saving and validating settings from the admin UI and network admin.
*
* @since 1.1.0
* @package LiteSpeed
*/
namespace LiteSpeed;
defined( 'WPINC' ) || exit();
/**
* Class Admin_Settings
*
* Saves, sanitizes, and validates LiteSpeed Cache settings.
*/
class Admin_Settings extends Base {
const LOG_TAG = '[Settings]';
const ENROLL = '_settings-enroll';
/**
* Save settings (single site).
*
* Accepts data from $_POST or WP-CLI.
* Importers may call the Conf class directly.
*
* @since 3.0
*
* @param array tags */
$msg = sprintf(
esc_html__( 'The user with id %s has editor access, which is not allowed for the role simulator.', 'litespeed-cache' ),
'' . esc_html( $v ) . ''
);
Admin_Display::error( $msg );
unset( $data[ $k ] );
}
}
}
break;
case self::O_CDN_MAPPING:
/**
* CDN setting
*
* Raw data format:
* cdn-mapping[url][] = 'xxx'
* cdn-mapping[url][2] = 'xxx2'
* cdn-mapping[inc_js][] = 1
*
* Final format:
* cdn-mapping[0][url] = 'xxx'
* cdn-mapping[2][url] = 'xxx2'
*/
if ( $data ) {
foreach ( $data as $k => $v ) {
if ( self::CDN_MAPPING_FILETYPE === $child ) {
$v = Utility::sanitize_lines( $v );
}
if ( self::CDN_MAPPING_URL === $child ) {
// If not a valid URL, turn off CDN.
if ( 0 !== strpos( $v, 'https://' ) ) {
self::debug( '❌ CDN mapping set to OFF due to invalid URL' );
$the_matrix[ self::O_CDN ] = false;
}
$v = trailingslashit( $v );
}
if ( in_array( $child, [ self::CDN_MAPPING_INC_IMG, self::CDN_MAPPING_INC_CSS, self::CDN_MAPPING_INC_JS ], true ) ) {
// Because these can't be auto detected in `config->update()`, need to format here.
$v = 'false' === $v ? 0 : (bool) $v;
}
if ( empty( $data2[ $k ] ) ) {
$data2[ $k ] = [];
}
$data2[ $k ][ $child ] = $v;
}
}
$data = $data2;
break;
case self::O_CRAWLER_COOKIES:
/**
* Cookie Crawler setting
* Raw Format:
* crawler-cookies[name][] = xxx
* crawler-cookies[name][2] = xxx2
* crawler-cookies[vals][] = xxx
*
* Final format:
* crawler-cookie[0][name] = 'xxx'
* crawler-cookie[0][vals] = 'xxx'
* crawler-cookie[2][name] = 'xxx2'
*
* Empty line for `vals` uses literal `_null`.
*/
if ( $data ) {
foreach ( $data as $k => $v ) {
if ( self::CRWL_COOKIE_VALS === $child ) {
$v = Utility::sanitize_lines( $v );
}
if ( empty( $data2[ $k ] ) ) {
$data2[ $k ] = [];
}
$data2[ $k ][ $child ] = $v;
}
}
$data = $data2;
break;
// Cache exclude category.
case self::O_CACHE_EXC_CAT:
$data2 = [];
$data = Utility::sanitize_lines( $data );
foreach ( $data as $v ) {
$cat_id = get_cat_ID( $v );
if ( ! $cat_id ) {
continue;
}
$data2[] = $cat_id;
}
$data = $data2;
break;
// Cache exclude tag.
case self::O_CACHE_EXC_TAG:
$data2 = [];
$data = Utility::sanitize_lines( $data );
foreach ( $data as $v ) {
$term = get_term_by( 'name', $v, 'post_tag' );
if ( ! $term ) {
// Could surface an admin error here if desired.
continue;
}
$data2[] = $term->term_id;
}
$data = $data2;
break;
case self::O_IMG_OPTM_SIZES_SKIPPED: // Skip image sizes
$image_sizes = Utility::prepare_image_sizes_array();
$saved_sizes = isset( $raw_data[$id] ) ? $raw_data[$id] : [];
$data = array_diff( $image_sizes, $saved_sizes );
break;
default:
break;
}
$the_matrix[ $id ] = $data;
}
// Special handler for CDN/Crawler 2d list to drop empty rows.
foreach ( $the_matrix as $id => $data ) {
/**
* Format:
* cdn-mapping[0][url] = 'xxx'
* cdn-mapping[2][url] = 'xxx2'
* crawler-cookie[0][name] = 'xxx'
* crawler-cookie[0][vals] = 'xxx'
* crawler-cookie[2][name] = 'xxx2'
*/
if ( self::O_CDN_MAPPING === $id || self::O_CRAWLER_COOKIES === $id ) {
// Drop row if all children are empty.
foreach ( $data as $k => $v ) {
foreach ( $v as $v2 ) {
if ( $v2 ) {
continue 2;
}
}
// All empty.
unset( $the_matrix[ $id ][ $k ] );
}
}
// Don't allow repeated cookie names.
if ( self::O_CRAWLER_COOKIES === $id ) {
$existed = [];
foreach ( $the_matrix[ $id ] as $k => $v ) {
if ( empty( $v[ self::CRWL_COOKIE_NAME ] ) || in_array( $v[ self::CRWL_COOKIE_NAME ], $existed, true ) ) {
// Filter repeated or empty name.
unset( $the_matrix[ $id ][ $k ] );
continue;
}
$existed[] = $v[ self::CRWL_COOKIE_NAME ];
}
}
// tmp fix the 3rd part woo update hook issue when enabling vary cookie.
if ( 'wc_cart_vary' === $id ) {
if ( $data ) {
add_filter(
'litespeed_vary_cookies',
function ( $arr ) {
$arr[] = 'woocommerce_cart_hash';
return array_unique( $arr );
}
);
} else {
add_filter(
'litespeed_vary_cookies',
function ( $arr ) {
$key = array_search( 'woocommerce_cart_hash', $arr, true );
if ( false !== $key ) {
unset( $arr[ $key ] );
}
return array_unique( $arr );
}
);
}
}
}
// id validation will be inside.
$this->cls( 'Conf' )->update_confs( $the_matrix );
$msg = __( 'Options saved.', 'litespeed-cache' );
Admin_Display::success( $msg );
}
/**
* Parses any changes made by the network admin on the network settings.
*
* @since 3.0
*
* @param array1?q-1:0),U=1;U
=0;B--){var q=T[B];if(0===q.path.length&&"replace"===q.op){C=q.value;break}}B>-1&&(T=T.slice(B+1));var W=b("Patches").$;return r(C)?W(C,T):this.produce(C,(function(C){return W(C,T)}))},e}(),re=new te,ne=re.produce;re.produceWithPatches.bind(re),re.setAutoFreeze.bind(re),re.setUseProxies.bind(re),re.applyPatches.bind(re),re.createDraft.bind(re),re.finishDraft.bind(re);const oe=ne;function _typeof(C){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(C){return typeof C}:function(C){return C&&"function"==typeof Symbol&&C.constructor===Symbol&&C!==Symbol.prototype?"symbol":typeof C},_typeof(C)}function toPropertyKey(C){var T=function toPrimitive(C,T){if("object"!=_typeof(C)||!C)return C;var B=C[Symbol.toPrimitive];if(void 0!==B){var q=B.call(C,T||"default");if("object"!=_typeof(q))return q;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===T?String:Number)(C)}(C,"string");return"symbol"==_typeof(T)?T:String(T)}function ownKeys(C,T){var B=Object.keys(C);if(Object.getOwnPropertySymbols){var q=Object.getOwnPropertySymbols(C);T&&(q=q.filter((function(T){return Object.getOwnPropertyDescriptor(C,T).enumerable}))),B.push.apply(B,q)}return B}function _objectSpread2(C){for(var T=1;T
"+q("To upload them anyway, ask the site administrator to enable unfiltered file uploads.","elementor"),strings:{confirm:q("Got it","elementor")}})}},{key:"getUnfilteredFilesNotEnabledDialog",value:function getUnfilteredFilesNotEnabledDialog(C){var T=window.elementorAdmin||window.elementor;if(!T.config.user.is_administrator)return this.getUnfilteredFilesNonAdminDialog();return T.helpers.getSimpleDialog("e-enable-unfiltered-files-dialog",q("Enable Unfiltered File Uploads","elementor"),q("Before you enable unfiltered files upload, note that such files include a security risk. Elementor does run a process to remove possible malicious code, but there is still risk involved when using such files.","elementor"),q("Enable","elementor"),(function onConfirm(){elementorCommon.ajax.addRequest("enable_unfiltered_files_upload",{},!0),elementorCommon.config.filesUpload.unfilteredFiles=!0,C()}))}},{key:"getUnfilteredFilesNotEnabledImportTemplateDialog",value:function getUnfilteredFilesNotEnabledImportTemplateDialog(C){return(window.elementorAdmin||window.elementor).config.user.is_administrator?elementorCommon.dialogsManager.createWidget("confirm",{id:"e-enable-unfiltered-files-dialog-import-template",headerMessage:q("Enable Unfiltered File Uploads","elementor"),message:q("Before you enable unfiltered files upload, note that such files include a security risk. Elementor does run a process to remove possible malicious code, but there is still risk involved when using such files.","elementor")+"
"+q("If you do not enable uploading unfiltered files, any SVG or JSON (including lottie) files used in the uploaded template will not be imported.","elementor"),position:{my:"center center",at:"center center"},strings:{confirm:q("Enable and Import","elementor"),cancel:q("Import Without Enabling","elementor")},onConfirm:function onConfirm(){elementorCommon.ajax.addRequest("enable_unfiltered_files_upload",{success:function success(){elementorCommon.config.filesUpload.unfilteredFiles=!0,C()}},!0)},onCancel:function onCancel(){return C()}}):this.getUnfilteredFilesNonAdminDialog()}}]),FilesUploadHandler}();T.default=$},90381:(C,T)=>{"use strict";function _createForOfIteratorHelper(C,T){var B="undefined"!=typeof Symbol&&C[Symbol.iterator]||C["@@iterator"];if(!B){if(Array.isArray(C)||(B=function _unsupportedIterableToArray(C,T){if(!C)return;if("string"==typeof C)return _arrayLikeToArray(C,T);var B=Object.prototype.toString.call(C).slice(8,-1);"Object"===B&&C.constructor&&(B=C.constructor.name);if("Map"===B||"Set"===B)return Array.from(C);if("Arguments"===B||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(B))return _arrayLikeToArray(C,T)}(C))||T&&C&&"number"==typeof C.length){B&&(C=B);var q=0,W=function F(){};return{s:W,n:function n(){return q>=C.length?{done:!0}:{done:!1,value:C[q++]}},e:function e(C){throw C},f:W}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var U,L=!0,$=!1;return{s:function s(){B=B.call(C)},n:function n(){var C=B.next();return L=C.done,C},e:function e(C){$=!0,U=C},f:function f(){try{L||null==B.return||B.return()}finally{if($)throw U}}}}function _arrayLikeToArray(C,T){(null==T||T>C.length)&&(T=C.length);for(var B=0,q=new Array(T);B[\w-]+)';
}
/**
* Get method arguments for this REST route.
*
* @return array An array of endpoints.
*/
public function get_args() {
return [
'args' => [
'code' => [
'description' => __( 'Unique identifier for the coupon within the cart.', 'woocommerce' ),
'type' => 'string',
],
],
[
'methods' => \WP_REST_Server::READABLE,
'callback' => [ $this, 'get_response' ],
'permission_callback' => '__return_true',
'args' => [
'context' => $this->get_context_param( [ 'default' => 'view' ] ),
],
],
[
'methods' => \WP_REST_Server::DELETABLE,
'callback' => [ $this, 'get_response' ],
'permission_callback' => '__return_true',
],
'schema' => [ $this->schema, 'get_public_item_schema' ],
'allow_batch' => [ 'v1' => true ],
];
}
/**
* Get a single cart coupon.
*
* @throws RouteException On error.
* @param \WP_REST_Request $request Request object.
* @return \WP_REST_Response
*/
protected function get_route_response( \WP_REST_Request $request ) {
if ( ! $this->cart_controller->has_coupon( $request['code'] ) ) {
throw new RouteException( 'woocommerce_rest_cart_coupon_invalid_code', esc_html__( 'Coupon does not exist in the cart.', 'woocommerce' ), 404 );
}
return $this->prepare_item_for_response( $request['code'], $request );
}
/**
* Delete a single cart coupon.
*
* @throws RouteException On error.
* @param \WP_REST_Request $request Request object.
* @return \WP_REST_Response
*/
protected function get_route_delete_response( \WP_REST_Request $request ) {
if ( ! $this->cart_controller->has_coupon( $request['code'] ) ) {
throw new RouteException( 'woocommerce_rest_cart_coupon_invalid_code', esc_html__( 'Coupon does not exist in the cart.', 'woocommerce' ), 404 );
}
$cart = $this->cart_controller->get_cart_instance();
$cart->remove_coupon( $request['code'] );
return new \WP_REST_Response( null, 204 );
}
}
/**
* Helper functions for interacting with the Store API.
*
* This file is autoloaded via composer.json.
*/
use Automattic\WooCommerce\StoreApi\StoreApi;
use Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema;
if ( ! function_exists( 'woocommerce_store_api_register_endpoint_data' ) ) {
/**
* Register endpoint data under a specified namespace.
*
* @see Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema::register_endpoint_data()
*
* @param array $args Args to pass to register_endpoint_data.
* @returns boolean|\WP_Error True on success, WP_Error on fail.
*/
function woocommerce_store_api_register_endpoint_data( $args ) {
try {
$extend = StoreApi::container()->get( ExtendSchema::class );
$extend->register_endpoint_data( $args );
} catch ( \Exception $error ) {
return new \WP_Error( 'error', $error->getMessage() );
}
return true;
}
}
if ( ! function_exists( 'woocommerce_store_api_register_update_callback' ) ) {
/**
* Add callback functions that can be executed by the cart/extensions endpoint.
*
* @see Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema::register_update_callback()
*
* @param array $args Args to pass to register_update_callback.
* @returns boolean|\WP_Error True on success, WP_Error on fail.
*/
function woocommerce_store_api_register_update_callback( $args ) {
try {
$extend = StoreApi::container()->get( ExtendSchema::class );
$extend->register_update_callback( $args );
} catch ( \Exception $error ) {
return new \WP_Error( 'error', $error->getMessage() );
}
return true;
}
}
if ( ! function_exists( 'woocommerce_store_api_register_payment_requirements' ) ) {
/**
* Registers and validates payment requirements callbacks.
*
* @see Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema::register_payment_requirements()
*
* @param array $args Args to pass to register_payment_requirements.
* @returns boolean|\WP_Error True on success, WP_Error on fail.
*/
function woocommerce_store_api_register_payment_requirements( $args ) {
try {
$extend = StoreApi::container()->get( ExtendSchema::class );
$extend->register_payment_requirements( $args );
} catch ( \Exception $error ) {
return new \WP_Error( 'error', $error->getMessage() );
}
return true;
}
}
if ( ! function_exists( 'woocommerce_store_api_get_formatter' ) ) {
/**
* Returns a formatter instance.
*
* @see Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema::get_formatter()
*
* @param string $name Formatter name.
* @return Automattic\WooCommerce\StoreApi\Formatters\FormatterInterface
*/
function woocommerce_store_api_get_formatter( $name ) {
return StoreApi::container()->get( ExtendSchema::class )->get_formatter( $name );
}
}
/**
* Internal dependencies
*/
import { ACTION_TYPES as types } from './action-types';
/**
* Action creator for setting a single query-state value for a given context.
*
* @param {string} context Context for query state being stored.
* @param {string} queryKey Key for query item.
* @param {*} value The value for the query item.
*
* @return {Object} The action object.
*/
export const setQueryValue = ( context, queryKey, value ) => {
return {
type: types.SET_QUERY_KEY_VALUE,
context,
queryKey,
value,
};
};
/**
* Action creator for setting query-state for a given context.
*
* @param {string} context Context for query state being stored.
* @param {*} value Query state being stored for the given context.
*
* @return {Object} The action object.
*/
export const setValueForQueryContext = ( context, value ) => {
return {
type: types.SET_QUERY_CONTEXT_VALUE,
context,
value,
};
};
/**
* Deprecated functions
*
* Where functions come to die.
*
* @author Automattic
* @category Core
* @package WooCommerce\Functions
* @version 3.3.0
*/
use Automattic\Jetpack\Constants;
use Automattic\WooCommerce\Internal\Admin\Logging\Settings;
use Automattic\WooCommerce\Utilities\LoggingUtil;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Runs a deprecated action with notice only if used.
*
* @since 3.0.0
* @param string $tag The name of the action hook.
* @param array $args Array of additional function arguments to be passed to do_action().
* @param string $version The version of WooCommerce that deprecated the hook.
* @param string $replacement The hook that should have been used.
* @param string $message A message regarding the change.
*/
function wc_do_deprecated_action( $tag, $args, $version, $replacement = null, $message = null ) {
if ( ! has_action( $tag ) ) {
return;
}
wc_deprecated_hook( $tag, $version, $replacement, $message );
do_action_ref_array( $tag, $args );
}
/**
* Wrapper for deprecated functions so we can apply some extra logic.
*
* @since 3.0.0
* @param string $function Function used.
* @param string $version Version the message was added in.
* @param string $replacement Replacement for the called function.
*/
function wc_deprecated_function( $function, $version, $replacement = null ) {
// @codingStandardsIgnoreStart
if ( wp_doing_ajax() || WC()->is_rest_api_request() ) {
do_action( 'deprecated_function_run', $function, $replacement, $version );
$log_string = "The {$function} function is deprecated since version {$version}.";
$log_string .= $replacement ? " Replace with {$replacement}." : '';
error_log( $log_string );
} else {
_deprecated_function( $function, $version, $replacement );
}
// @codingStandardsIgnoreEnd
}
/**
* Wrapper for deprecated hook so we can apply some extra logic.
*
* @since 3.3.0
* @param string $hook The hook that was used.
* @param string $version The version of WordPress that deprecated the hook.
* @param string $replacement The hook that should have been used.
* @param string $message A message regarding the change.
*/
function wc_deprecated_hook( $hook, $version, $replacement = null, $message = null ) {
// @codingStandardsIgnoreStart
if ( wp_doing_ajax() || WC()->is_rest_api_request() ) {
do_action( 'deprecated_hook_run', $hook, $replacement, $version, $message );
$message = empty( $message ) ? '' : ' ' . $message;
$log_string = "{$hook} is deprecated since version {$version}";
$log_string .= $replacement ? "! Use {$replacement} instead." : ' with no alternative available.';
error_log( $log_string . $message );
} else {
_deprecated_hook( $hook, $version, $replacement, $message );
}
// @codingStandardsIgnoreEnd
}
/**
* When catching an exception, this allows us to log it if unexpected.
*
* @since 3.3.0
* @param Exception $exception_object The exception object.
* @param string $function The function which threw exception.
* @param array $args The args passed to the function.
*/
function wc_caught_exception( $exception_object, $function = '', $args = array() ) {
// @codingStandardsIgnoreStart
$message = $exception_object->getMessage();
$message .= '. Args: ' . print_r( $args, true ) . '.';
do_action( 'woocommerce_caught_exception', $exception_object, $function, $args );
error_log( "Exception caught in {$function}. {$message}." );
// @codingStandardsIgnoreEnd
}
/**
* Wrapper for _doing_it_wrong().
*
* @since 3.0.0
* @param string $function Function used.
* @param string $message Message to log.
* @param string $version Version the message was added in.
*/
function wc_doing_it_wrong( $function, $message, $version ) {
// @codingStandardsIgnoreStart
$message .= ' Backtrace: ' . wp_debug_backtrace_summary();
if ( wp_doing_ajax() || WC()->is_rest_api_request() ) {
do_action( 'doing_it_wrong_run', $function, $message, $version );
error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." );
} else {
_doing_it_wrong( $function, $message, $version );
}
// @codingStandardsIgnoreEnd
}
/**
* Wrapper for deprecated arguments so we can apply some extra logic.
*
* @since 3.0.0
* @param string $argument
* @param string $version
* @param string $replacement
*/
function wc_deprecated_argument( $argument, $version, $message = null ) {
if ( wp_doing_ajax() || WC()->is_rest_api_request() ) {
do_action( 'deprecated_argument_run', $argument, $message, $version );
error_log( "The {$argument} argument is deprecated since version {$version}. {$message}" );
} else {
_deprecated_argument( $argument, $version, $message );
}
}
/**
* @deprecated 2.1
*/
function woocommerce_show_messages() {
wc_deprecated_function( 'woocommerce_show_messages', '2.1', 'wc_print_notices' );
wc_print_notices();
}
/**
* @deprecated 2.1
*/
function woocommerce_weekend_area_js() {
wc_deprecated_function( 'woocommerce_weekend_area_js', '2.1' );
}
/**
* @deprecated 2.1
*/
function woocommerce_tooltip_js() {
wc_deprecated_function( 'woocommerce_tooltip_js', '2.1' );
}
/**
* @deprecated 2.1
*/
function woocommerce_datepicker_js() {
wc_deprecated_function( 'woocommerce_datepicker_js', '2.1' );
}
/**
* @deprecated 2.1
*/
function woocommerce_admin_scripts() {
wc_deprecated_function( 'woocommerce_admin_scripts', '2.1' );
}
/**
* @deprecated 2.1
*/
function woocommerce_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) {
wc_deprecated_function( 'woocommerce_create_page', '2.1', 'wc_create_page' );
return wc_create_page( $slug, $option, $page_title, $page_content, $post_parent );
}
/**
* @deprecated 2.1
*/
function woocommerce_readfile_chunked( $file, $retbytes = true ) {
wc_deprecated_function( 'woocommerce_readfile_chunked', '2.1', 'WC_Download_Handler::readfile_chunked()' );
return WC_Download_Handler::readfile_chunked( $file );
}
/**
* Formal total costs - format to the number of decimal places for the base currency.
*
* @access public
* @param mixed $number
* @deprecated 2.1
* @return string
*/
function woocommerce_format_total( $number ) {
wc_deprecated_function( __FUNCTION__, '2.1', 'wc_format_decimal()' );
return wc_format_decimal( $number, wc_get_price_decimals(), false );
}
/**
* Get product name with extra details such as SKU price and attributes. Used within admin.
*
* @access public
* @param WC_Product $product
* @deprecated 2.1
* @return string
*/
function woocommerce_get_formatted_product_name( $product ) {
wc_deprecated_function( __FUNCTION__, '2.1', 'WC_Product::get_formatted_name()' );
return $product->get_formatted_name();
}
/**
* Handle IPN requests for the legacy paypal gateway by calling gateways manually if needed.
*
* @access public
*/
function woocommerce_legacy_paypal_ipn() {
if ( ! empty( $_GET['paypalListener'] ) && 'paypal_standard_IPN' === $_GET['paypalListener'] ) {
WC()->payment_gateways();
do_action( 'woocommerce_api_wc_gateway_paypal' );
}
}
add_action( 'init', 'woocommerce_legacy_paypal_ipn' );
/**
* @deprecated 3.0
*/
function get_product( $the_product = false, $args = array() ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_get_product' );
return wc_get_product( $the_product, $args );
}
/**
* @deprecated 3.0
*/
function woocommerce_protected_product_add_to_cart( $passed, $product_id ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_protected_product_add_to_cart' );
return wc_protected_product_add_to_cart( $passed, $product_id );
}
/**
* @deprecated 3.0
*/
function woocommerce_empty_cart() {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_empty_cart' );
wc_empty_cart();
}
/**
* @deprecated 3.0
*/
function woocommerce_load_persistent_cart( $user_login, $user = 0 ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_load_persistent_cart' );
return wc_load_persistent_cart( $user_login, $user );
}
/**
* @deprecated 3.0
*/
function woocommerce_add_to_cart_message( $product_id ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_add_to_cart_message' );
wc_add_to_cart_message( $product_id );
}
/**
* @deprecated 3.0
*/
function woocommerce_clear_cart_after_payment() {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_clear_cart_after_payment' );
wc_clear_cart_after_payment();
}
/**
* @deprecated 3.0
*/
function woocommerce_cart_totals_subtotal_html() {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_cart_totals_subtotal_html' );
wc_cart_totals_subtotal_html();
}
/**
* @deprecated 3.0
*/
function woocommerce_cart_totals_shipping_html() {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_cart_totals_shipping_html' );
wc_cart_totals_shipping_html();
}
/**
* @deprecated 3.0
*/
function woocommerce_cart_totals_coupon_html( $coupon ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_cart_totals_coupon_html' );
wc_cart_totals_coupon_html( $coupon );
}
/**
* @deprecated 3.0
*/
function woocommerce_cart_totals_order_total_html() {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_cart_totals_order_total_html' );
wc_cart_totals_order_total_html();
}
/**
* @deprecated 3.0
*/
function woocommerce_cart_totals_fee_html( $fee ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_cart_totals_fee_html' );
wc_cart_totals_fee_html( $fee );
}
/**
* @deprecated 3.0
*/
function woocommerce_cart_totals_shipping_method_label( $method ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_cart_totals_shipping_method_label' );
return wc_cart_totals_shipping_method_label( $method );
}
/**
* @deprecated 3.0
*/
function woocommerce_get_template_part( $slug, $name = '' ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_get_template_part' );
wc_get_template_part( $slug, $name );
}
/**
* @deprecated 3.0
*/
function woocommerce_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_get_template' );
wc_get_template( $template_name, $args, $template_path, $default_path );
}
/**
* @deprecated 3.0
*/
function woocommerce_locate_template( $template_name, $template_path = '', $default_path = '' ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_locate_template' );
return wc_locate_template( $template_name, $template_path, $default_path );
}
/**
* @deprecated 3.0
*/
function woocommerce_mail( $to, $subject, $message, $headers = "Content-Type: text/html\r\n", $attachments = "" ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_mail' );
wc_mail( $to, $subject, $message, $headers, $attachments );
}
/**
* @deprecated 3.0
*/
function woocommerce_disable_admin_bar( $show_admin_bar ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_disable_admin_bar' );
return wc_disable_admin_bar( $show_admin_bar );
}
/**
* @deprecated 3.0
*/
function woocommerce_create_new_customer( $email, $username = '', $password = '' ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_create_new_customer' );
return wc_create_new_customer( $email, $username, $password );
}
/**
* @deprecated 3.0
*/
function woocommerce_set_customer_auth_cookie( $customer_id ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_set_customer_auth_cookie' );
wc_set_customer_auth_cookie( $customer_id );
}
/**
* @deprecated 3.0
*/
function woocommerce_update_new_customer_past_orders( $customer_id ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_update_new_customer_past_orders' );
return wc_update_new_customer_past_orders( $customer_id );
}
/**
* @deprecated 3.0
*/
function woocommerce_paying_customer( $order_id ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_paying_customer' );
wc_paying_customer( $order_id );
}
/**
* @deprecated 3.0
*/
function woocommerce_customer_bought_product( $customer_email, $user_id, $product_id ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_customer_bought_product' );
return wc_customer_bought_product( $customer_email, $user_id, $product_id );
}
/**
* @deprecated 3.0
*/
function woocommerce_customer_has_capability( $allcaps, $caps, $args ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_customer_has_capability' );
return wc_customer_has_capability( $allcaps, $caps, $args );
}
/**
* @deprecated 3.0
*/
function woocommerce_sanitize_taxonomy_name( $taxonomy ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_sanitize_taxonomy_name' );
return wc_sanitize_taxonomy_name( $taxonomy );
}
/**
* @deprecated 3.0
*/
function woocommerce_get_filename_from_url( $file_url ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_get_filename_from_url' );
return wc_get_filename_from_url( $file_url );
}
/**
* @deprecated 3.0
*/
function woocommerce_get_dimension( $dim, $to_unit ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_get_dimension' );
return wc_get_dimension( $dim, $to_unit );
}
/**
* @deprecated 3.0
*/
function woocommerce_get_weight( $weight, $to_unit ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_get_weight' );
return wc_get_weight( $weight, $to_unit );
}
/**
* @deprecated 3.0
*/
function woocommerce_trim_zeros( $price ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_trim_zeros' );
return wc_trim_zeros( $price );
}
/**
* @deprecated 3.0
*/
function woocommerce_round_tax_total( $tax ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_round_tax_total' );
return wc_round_tax_total( $tax );
}
/**
* @deprecated 3.0
*/
function woocommerce_format_decimal( $number, $dp = false, $trim_zeros = false ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_format_decimal' );
return wc_format_decimal( $number, $dp, $trim_zeros );
}
/**
* @deprecated 3.0
*/
function woocommerce_clean( $var ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_clean' );
return wc_clean( $var );
}
/**
* @deprecated 3.0
*/
function woocommerce_array_overlay( $a1, $a2 ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_array_overlay' );
return wc_array_overlay( $a1, $a2 );
}
/**
* @deprecated 3.0
*/
function woocommerce_price( $price, $args = array() ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_price' );
return wc_price( $price, $args );
}
/**
* @deprecated 3.0
*/
function woocommerce_let_to_num( $size ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_let_to_num' );
return wc_let_to_num( $size );
}
/**
* @deprecated 3.0
*/
function woocommerce_date_format() {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_date_format' );
return wc_date_format();
}
/**
* @deprecated 3.0
*/
function woocommerce_time_format() {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_time_format' );
return wc_time_format();
}
/**
* @deprecated 3.0
*/
function woocommerce_timezone_string() {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_timezone_string' );
return wc_timezone_string();
}
if ( ! function_exists( 'woocommerce_rgb_from_hex' ) ) {
/**
* @deprecated 3.0
*/
function woocommerce_rgb_from_hex( $color ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_rgb_from_hex' );
return wc_rgb_from_hex( $color );
}
}
if ( ! function_exists( 'woocommerce_hex_darker' ) ) {
/**
* @deprecated 3.0
*/
function woocommerce_hex_darker( $color, $factor = 30 ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_hex_darker' );
return wc_hex_darker( $color, $factor );
}
}
if ( ! function_exists( 'woocommerce_hex_lighter' ) ) {
/**
* @deprecated 3.0
*/
function woocommerce_hex_lighter( $color, $factor = 30 ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_hex_lighter' );
return wc_hex_lighter( $color, $factor );
}
}
if ( ! function_exists( 'woocommerce_light_or_dark' ) ) {
/**
* @deprecated 3.0
*/
function woocommerce_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_light_or_dark' );
return wc_light_or_dark( $color, $dark, $light );
}
}
if ( ! function_exists( 'woocommerce_format_hex' ) ) {
/**
* @deprecated 3.0
*/
function woocommerce_format_hex( $hex ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_format_hex' );
return wc_format_hex( $hex );
}
}
/**
* @deprecated 3.0
*/
function woocommerce_get_order_id_by_order_key( $order_key ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_get_order_id_by_order_key' );
return wc_get_order_id_by_order_key( $order_key );
}
/**
* @deprecated 3.0
*/
function woocommerce_downloadable_file_permission( $download_id, $product_id, $order ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_downloadable_file_permission' );
return wc_downloadable_file_permission( $download_id, $product_id, $order );
}
/**
* @deprecated 3.0
*/
function woocommerce_downloadable_product_permissions( $order_id ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_downloadable_product_permissions' );
wc_downloadable_product_permissions( $order_id );
}
/**
* @deprecated 3.0
*/
function woocommerce_add_order_item( $order_id, $item ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_add_order_item' );
return wc_add_order_item( $order_id, $item );
}
/**
* @deprecated 3.0
*/
function woocommerce_delete_order_item( $item_id ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_delete_order_item' );
return wc_delete_order_item( $item_id );
}
/**
* @deprecated 3.0
*/
function woocommerce_update_order_item_meta( $item_id, $meta_key, $meta_value, $prev_value = '' ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_update_order_item_meta' );
return wc_update_order_item_meta( $item_id, $meta_key, $meta_value, $prev_value );
}
/**
* @deprecated 3.0
*/
function woocommerce_add_order_item_meta( $item_id, $meta_key, $meta_value, $unique = false ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_add_order_item_meta' );
return wc_add_order_item_meta( $item_id, $meta_key, $meta_value, $unique );
}
/**
* @deprecated 3.0
*/
function woocommerce_delete_order_item_meta( $item_id, $meta_key, $meta_value = '', $delete_all = false ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_delete_order_item_meta' );
return wc_delete_order_item_meta( $item_id, $meta_key, $meta_value, $delete_all );
}
/**
* @deprecated 3.0
*/
function woocommerce_get_order_item_meta( $item_id, $key, $single = true ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_get_order_item_meta' );
return wc_get_order_item_meta( $item_id, $key, $single );
}
/**
* @deprecated 3.0
*/
function woocommerce_cancel_unpaid_orders() {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_cancel_unpaid_orders' );
wc_cancel_unpaid_orders();
}
/**
* @deprecated 3.0
*/
function woocommerce_processing_order_count() {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_processing_order_count' );
return wc_processing_order_count();
}
/**
* @deprecated 3.0
*/
function woocommerce_get_page_id( $page ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_get_page_id' );
return wc_get_page_id( $page );
}
/**
* @deprecated 3.0
*/
function woocommerce_get_endpoint_url( $endpoint, $value = '', $permalink = '' ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_get_endpoint_url' );
return wc_get_endpoint_url( $endpoint, $value, $permalink );
}
/**
* @deprecated 3.0
*/
function woocommerce_lostpassword_url( $url ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_lostpassword_url' );
return wc_lostpassword_url( $url );
}
/**
* @deprecated 3.0
*/
function woocommerce_customer_edit_account_url() {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_customer_edit_account_url' );
return wc_customer_edit_account_url();
}
/**
* @deprecated 3.0
*/
function woocommerce_nav_menu_items( $items, $args ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_nav_menu_items' );
return wc_nav_menu_items( $items );
}
/**
* @deprecated 3.0
*/
function woocommerce_nav_menu_item_classes( $menu_items, $args ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_nav_menu_item_classes' );
return wc_nav_menu_item_classes( $menu_items );
}
/**
* @deprecated 3.0
*/
function woocommerce_list_pages( $pages ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_list_pages' );
return wc_list_pages( $pages );
}
/**
* @deprecated 3.0
*/
function woocommerce_product_dropdown_categories( $args = array(), $deprecated_hierarchical = 1, $deprecated_show_uncategorized = 1, $deprecated_orderby = '' ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_product_dropdown_categories' );
return wc_product_dropdown_categories( $args, $deprecated_hierarchical, $deprecated_show_uncategorized, $deprecated_orderby );
}
/**
* @deprecated 3.0
*/
function woocommerce_walk_category_dropdown_tree( $a1 = '', $a2 = '', $a3 = '' ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_walk_category_dropdown_tree' );
return wc_walk_category_dropdown_tree( $a1, $a2, $a3 );
}
/**
* @deprecated 3.0
*/
function woocommerce_taxonomy_metadata_wpdbfix() {
wc_deprecated_function( __FUNCTION__, '3.0' );
}
/**
* @deprecated 3.0
*/
function wc_taxonomy_metadata_wpdbfix() {
wc_deprecated_function( __FUNCTION__, '3.0' );
}
/**
* @deprecated 3.0
*/
function woocommerce_order_terms( $the_term, $next_id, $taxonomy, $index = 0, $terms = null ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_reorder_terms' );
return wc_reorder_terms( $the_term, $next_id, $taxonomy, $index, $terms );
}
/**
* @deprecated 3.0
*/
function woocommerce_set_term_order( $term_id, $index, $taxonomy, $recursive = false ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_set_term_order' );
return wc_set_term_order( $term_id, $index, $taxonomy, $recursive );
}
/**
* @deprecated 3.0
*/
function woocommerce_terms_clauses( $clauses, $taxonomies, $args ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_terms_clauses' );
return wc_terms_clauses( $clauses, $taxonomies, $args );
}
/**
* @deprecated 3.0
*/
function _woocommerce_term_recount( $terms, $taxonomy, $callback, $terms_are_term_taxonomy_ids ) {
wc_deprecated_function( __FUNCTION__, '3.0', '_wc_term_recount' );
return _wc_term_recount( $terms, $taxonomy, $callback, $terms_are_term_taxonomy_ids );
}
/**
* @deprecated 3.0
*/
function woocommerce_recount_after_stock_change( $product_id ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_recount_after_stock_change' );
return wc_recount_after_stock_change( $product_id );
}
/**
* @deprecated 3.0
*/
function woocommerce_change_term_counts( $terms, $taxonomies, $args ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_change_term_counts' );
return wc_change_term_counts( $terms, $taxonomies );
}
/**
* @deprecated 3.0
*/
function woocommerce_get_product_ids_on_sale() {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_get_product_ids_on_sale' );
return wc_get_product_ids_on_sale();
}
/**
* @deprecated 3.0
*/
function woocommerce_get_featured_product_ids() {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_get_featured_product_ids' );
return wc_get_featured_product_ids();
}
/**
* @deprecated 3.0
*/
function woocommerce_get_product_terms( $object_id, $taxonomy, $fields = 'all' ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_get_product_terms' );
return wc_get_product_terms( $object_id, $taxonomy, array( 'fields' => $fields ) );
}
/**
* @deprecated 3.0
*/
function woocommerce_product_post_type_link( $permalink, $post ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_product_post_type_link' );
return wc_product_post_type_link( $permalink, $post );
}
/**
* @deprecated 3.0
*/
function woocommerce_placeholder_img_src() {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_placeholder_img_src' );
return wc_placeholder_img_src();
}
/**
* @deprecated 3.0
*/
function woocommerce_placeholder_img( $size = 'woocommerce_thumbnail' ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_placeholder_img' );
return wc_placeholder_img( $size );
}
/**
* @deprecated 3.0
*/
function woocommerce_get_formatted_variation( $variation = '', $flat = false ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_get_formatted_variation' );
return wc_get_formatted_variation( $variation, $flat );
}
/**
* @deprecated 3.0
*/
function woocommerce_scheduled_sales() {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_scheduled_sales' );
return wc_scheduled_sales();
}
/**
* @deprecated 3.0
*/
function woocommerce_get_attachment_image_attributes( $attr ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_get_attachment_image_attributes' );
return wc_get_attachment_image_attributes( $attr );
}
/**
* @deprecated 3.0
*/
function woocommerce_prepare_attachment_for_js( $response ) {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_prepare_attachment_for_js' );
return wc_prepare_attachment_for_js( $response );
}
/**
* @deprecated 3.0
*/
function woocommerce_track_product_view() {
wc_deprecated_function( __FUNCTION__, '3.0', 'wc_track_product_view' );
return wc_track_product_view();
}
/**
* @deprecated 2.3 has no replacement
*/
function woocommerce_compile_less_styles() {
wc_deprecated_function( 'woocommerce_compile_less_styles', '2.3' );
}
/**
* woocommerce_calc_shipping was an option used to determine if shipping was enabled prior to version 2.6.0. This has since been replaced with wc_shipping_enabled() function and
* the woocommerce_ship_to_countries setting.
* @deprecated 2.6.0
* @return string
*/
function woocommerce_calc_shipping_backwards_compatibility( $value ) {
if ( Constants::is_defined( 'WC_UPDATING' ) ) {
return $value;
}
return 'disabled' === get_option( 'woocommerce_ship_to_countries' ) ? 'no' : 'yes';
}
add_filter( 'pre_option_woocommerce_calc_shipping', 'woocommerce_calc_shipping_backwards_compatibility' );
/**
* @deprecated 3.0.0
* @see WC_Structured_Data class
*
* @return string
*/
function woocommerce_get_product_schema() {
wc_deprecated_function( 'woocommerce_get_product_schema', '3.0' );
global $product;
$schema = "Product";
// Downloadable product schema handling
if ( $product->is_downloadable() ) {
switch ( $product->download_type ) {
case 'application' :
$schema = "SoftwareApplication";
break;
case 'music' :
$schema = "MusicAlbum";
break;
default :
$schema = "Product";
break;
}
}
return 'http://schema.org/' . $schema;
}
/**
* Save product price.
*
* This is a private function (internal use ONLY) used until a data manipulation api is built.
*
* @deprecated 3.0.0
* @param int $product_id
* @param float $regular_price
* @param float $sale_price
* @param string $date_from
* @param string $date_to
*/
function _wc_save_product_price( $product_id, $regular_price, $sale_price = '', $date_from = '', $date_to = '' ) {
wc_doing_it_wrong( '_wc_save_product_price()', 'This function is not for developer use and is deprecated.', '3.0' );
$product_id = absint( $product_id );
$regular_price = wc_format_decimal( $regular_price );
$sale_price = '' === $sale_price ? '' : wc_format_decimal( $sale_price );
$date_from = wc_clean( $date_from );
$date_to = wc_clean( $date_to );
update_post_meta( $product_id, '_regular_price', $regular_price );
update_post_meta( $product_id, '_sale_price', $sale_price );
// Save Dates
update_post_meta( $product_id, '_sale_price_dates_from', $date_from ? strtotime( $date_from ) : '' );
update_post_meta( $product_id, '_sale_price_dates_to', $date_to ? strtotime( $date_to ) : '' );
if ( $date_to && ! $date_from ) {
$date_from = strtotime( 'NOW', current_time( 'timestamp' ) );
update_post_meta( $product_id, '_sale_price_dates_from', $date_from );
}
// Update price if on sale
if ( '' !== $sale_price && '' === $date_to && '' === $date_from ) {
update_post_meta( $product_id, '_price', $sale_price );
} else {
update_post_meta( $product_id, '_price', $regular_price );
}
if ( '' !== $sale_price && $date_from && strtotime( $date_from ) < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
update_post_meta( $product_id, '_price', $sale_price );
}
if ( $date_to && strtotime( $date_to ) < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
update_post_meta( $product_id, '_price', $regular_price );
update_post_meta( $product_id, '_sale_price_dates_from', '' );
update_post_meta( $product_id, '_sale_price_dates_to', '' );
}
}
/**
* Return customer avatar URL.
*
* @deprecated 3.1.0
* @since 2.6.0
* @param string $email the customer's email.
* @return string the URL to the customer's avatar.
*/
function wc_get_customer_avatar_url( $email ) {
// Deprecated in favor of WordPress get_avatar_url() function.
wc_deprecated_function( 'wc_get_customer_avatar_url()', '3.1', 'get_avatar_url()' );
return get_avatar_url( $email );
}
/**
* WooCommerce Core Supported Themes.
*
* @deprecated 3.3.0
* @since 2.2
* @return string[]
*/
function wc_get_core_supported_themes() {
wc_deprecated_function( 'wc_get_core_supported_themes()', '3.3' );
return array( 'twentyseventeen', 'twentysixteen', 'twentyfifteen', 'twentyfourteen', 'twentythirteen', 'twentyeleven', 'twentytwelve', 'twentyten' );
}
/**
* Get min/max price meta query args.
*
* @deprecated 3.6.0
* @since 3.0.0
* @param array $args Min price and max price arguments.
* @return array
*/
function wc_get_min_max_price_meta_query( $args ) {
wc_deprecated_function( 'wc_get_min_max_price_meta_query()', '3.6' );
$current_min_price = isset( $args['min_price'] ) ? floatval( $args['min_price'] ) : 0;
$current_max_price = isset( $args['max_price'] ) ? floatval( $args['max_price'] ) : PHP_INT_MAX;
return apply_filters(
'woocommerce_get_min_max_price_meta_query',
array(
'key' => '_price',
'value' => array( $current_min_price, $current_max_price ),
'compare' => 'BETWEEN',
'type' => 'DECIMAL(10,' . wc_get_price_decimals() . ')',
),
$args
);
}
/**
* When a term is split, ensure meta data maintained.
*
* @deprecated 3.6.0
* @param int $old_term_id Old term ID.
* @param int $new_term_id New term ID.
* @param string $term_taxonomy_id Term taxonomy ID.
* @param string $taxonomy Taxonomy.
*/
function wc_taxonomy_metadata_update_content_for_split_terms( $old_term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) {
wc_deprecated_function( 'wc_taxonomy_metadata_update_content_for_split_terms', '3.6' );
}
/**
* WooCommerce Term Meta API.
*
* WC tables for storing term meta are deprecated from WordPress 4.4 since 4.4 has its own table.
* This function serves as a wrapper, using the new table if present, or falling back to the WC table.
*
* @deprecated 3.6.0
* @param int $term_id Term ID.
* @param string $meta_key Meta key.
* @param mixed $meta_value Meta value.
* @param string $prev_value Previous value. (default: '').
* @return bool
*/
function update_woocommerce_term_meta( $term_id, $meta_key, $meta_value, $prev_value = '' ) {
wc_deprecated_function( 'update_woocommerce_term_meta', '3.6', 'update_term_meta' );
return function_exists( 'update_term_meta' ) ? update_term_meta( $term_id, $meta_key, $meta_value, $prev_value ) : update_metadata( 'woocommerce_term', $term_id, $meta_key, $meta_value, $prev_value );
}
/**
* WooCommerce Term Meta API.
*
* WC tables for storing term meta are deprecated from WordPress 4.4 since 4.4 has its own table.
* This function serves as a wrapper, using the new table if present, or falling back to the WC table.
*
* @deprecated 3.6.0
* @param int $term_id Term ID.
* @param string $meta_key Meta key.
* @param mixed $meta_value Meta value.
* @param bool $unique Make meta key unique. (default: false).
* @return bool
*/
function add_woocommerce_term_meta( $term_id, $meta_key, $meta_value, $unique = false ) {
wc_deprecated_function( 'add_woocommerce_term_meta', '3.6', 'add_term_meta' );
return function_exists( 'add_term_meta' ) ? add_term_meta( $term_id, $meta_key, $meta_value, $unique ) : add_metadata( 'woocommerce_term', $term_id, $meta_key, $meta_value, $unique );
}
/**
* WooCommerce Term Meta API
*
* WC tables for storing term meta are deprecated from WordPress 4.4 since 4.4 has its own table.
* This function serves as a wrapper, using the new table if present, or falling back to the WC table.
*
* @deprecated 3.6.0
* @param int $term_id Term ID.
* @param string $meta_key Meta key.
* @param mixed $meta_value Meta value (default: '').
* @param bool $deprecated Deprecated param (default: false).
* @return bool
*/
function delete_woocommerce_term_meta( $term_id, $meta_key, $meta_value = '', $deprecated = false ) {
wc_deprecated_function( 'delete_woocommerce_term_meta', '3.6', 'delete_term_meta' );
return function_exists( 'delete_term_meta' ) ? delete_term_meta( $term_id, $meta_key, $meta_value ) : delete_metadata( 'woocommerce_term', $term_id, $meta_key, $meta_value );
}
/**
* WooCommerce Term Meta API
*
* WC tables for storing term meta are deprecated from WordPress 4.4 since 4.4 has its own table.
* This function serves as a wrapper, using the new table if present, or falling back to the WC table.
*
* @deprecated 3.6.0
* @param int $term_id Term ID.
* @param string $key Meta key.
* @param bool $single Whether to return a single value. (default: true).
* @return mixed
*/
function get_woocommerce_term_meta( $term_id, $key, $single = true ) {
wc_deprecated_function( 'get_woocommerce_term_meta', '3.6', 'get_term_meta' );
return function_exists( 'get_term_meta' ) ? get_term_meta( $term_id, $key, $single ) : get_metadata( 'woocommerce_term', $term_id, $key, $single );
}
/**
* Registers the default log handler.
*
* @deprecated 8.6.0
* @since 3.0
* @param array $handlers Handlers.
* @return array
*/
function wc_register_default_log_handler( $handlers = array() ) {
wc_deprecated_function( 'wc_register_default_log_handler', '8.6.0' );
$default_handler = wc_get_container()->get( Settings::class )->get_default_handler();
array_push( $handlers, new $default_handler() );
return $handlers;
}
/**
* Get a log file path.
*
* @deprecated 8.6.0
* @since 2.2
*
* @param string $handle name.
* @return string the log file path.
*/
function wc_get_log_file_path( $handle ) {
wc_deprecated_function( 'wc_get_log_file_path', '8.6.0' );
$directory = LoggingUtil::get_log_directory();
$file_id = LoggingUtil::generate_log_file_id( $handle, null, time() );
$hash = LoggingUtil::generate_log_file_hash( $file_id );
return "{$directory}{$file_id}-{$hash}.log";
}
/**
* Get a log file name.
*
* @since 3.3
*
* @param string $handle Name.
* @return string The log file name.
*/
function wc_get_log_file_name( $handle ) {
wc_deprecated_function( 'wc_get_log_file_name', '8.6.0' );
$file_id = LoggingUtil::generate_log_file_id( $handle, null, time() );
$hash = LoggingUtil::generate_log_file_hash( $file_id );
return "{$file_id}-{$hash}";
}
/**
* 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'];
}
}
if ( ! function_exists( 'woocommerce_product_subcategories' ) ) {
/**
* This is a legacy function which used to check if we needed to display subcats and then output them. It was called by templates.
*
* From 3.3 onwards this is all handled via hooks and the woocommerce_maybe_show_product_subcategories function.
*
* Since some templates have not updated compatibility, to avoid showing incorrect categories this function has been deprecated and will
* return nothing. Replace usage with woocommerce_output_product_categories to render the category list manually.
*
* This is a legacy function which also checks if things should display.
* Themes no longer need to call these functions. It's all done via hooks.
*
* @deprecated 3.3.1 @todo Add a notice in a future version.
* @param array $args Arguments.
* @return null|boolean
*/
function woocommerce_product_subcategories( $args = array() ) {
$defaults = array(
'before' => '',
'after' => '',
'force_display' => false,
);
$args = wp_parse_args( $args, $defaults );
if ( $args['force_display'] ) {
// We can still render if display is forced.
woocommerce_output_product_categories(
array(
'before' => $args['before'],
'after' => $args['after'],
'parent_id' => is_product_category() ? get_queried_object_id() : 0,
)
);
return true;
} else {
// Output nothing. woocommerce_maybe_show_product_subcategories will handle the output of cats.
$display_type = woocommerce_get_loop_display_mode();
if ( 'subcategories' === $display_type ) {
// This removes pagination and products from display for themes not using wc_get_loop_prop in their product loops. @todo Remove in future major version.
global $wp_query;
if ( $wp_query->is_main_query() ) {
$wp_query->post_count = 0;
$wp_query->max_num_pages = 0;
}
}
return 'subcategories' === $display_type || 'both' === $display_type;
}
}
}
/**
* Products RSS Feed.
*
* @deprecated 2.6
*/
function wc_products_rss_feed() {
wc_deprecated_function( 'wc_products_rss_feed', '2.6' );
}
if ( ! function_exists( 'woocommerce_reset_loop' ) ) {
/**
* Reset the loop's index and columns when we're done outputting a product loop.
*
* @deprecated 3.3
*/
function woocommerce_reset_loop() {
wc_reset_loop();
}
}
if ( ! function_exists( 'woocommerce_product_reviews_tab' ) ) {
/**
* Output the reviews tab content.
*
* @deprecated 2.4.0 Unused.
*/
function woocommerce_product_reviews_tab() {
wc_deprecated_function( 'woocommerce_product_reviews_tab', '2.4' );
}
}
/**
* Get the URL to the WooCommerce Legacy REST API.
*
* Note that as of WooCommerce 9.0 the WooCommerce Legacy REST API has been moved to a dedicated extension,
* and the implementation of its root endpoint in WooCommerce core is now just a stub that will always return an error.
* See the setup_legacy_api_stub method in includes/class-woocommerce.php and:
* https://developer.woocommerce.com/2023/10/03/the-legacy-rest-api-will-move-to-a-dedicated-extension-in-woocommerce-9-0/
*
* @deprecated 9.0.0 The Legacy REST API has been removed from WooCommerce core.
*
* @since 2.1
* @param string $path an endpoint to include in the URL.
* @return string the URL.
*/
function get_woocommerce_api_url( $path ) {
$url = get_home_url( null, 'wc-api/v3/', is_ssl() ? 'https' : 'http' );
if ( ! empty( $path ) && is_string( $path ) ) {
$url .= ltrim( $path, '/' );
}
return $url;
}
/**
* WooCommerce Order Item Functions
*
* Functions for order specific things.
*
* @package WooCommerce\Functions
* @version 3.4.0
*/
defined( 'ABSPATH' ) || exit;
/**
* Add a item to an order (for example a line item).
*
* @param int $order_id Order ID.
* @param array $item_array Items list.
*
* @throws Exception When `WC_Data_Store::load` validation fails.
* @return int|bool Item ID or false
*/
function wc_add_order_item( $order_id, $item_array ) {
$order_id = absint( $order_id );
if ( ! $order_id ) {
return false;
}
$defaults = array(
'order_item_name' => '',
'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 Terms
*
* Functions for handling terms/term meta.
*
* @package WooCommerce\Functions
* @version 2.1.0
*/
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Enums\ProductStockStatus;
/**
* Change get terms defaults for attributes to order by the sorting setting, or default to menu_order for sortable taxonomies.
*
* @since 3.6.0 Sorting options are now set as the default automatically, so you no longer have to request to orderby menu_order.
*
* @param array $defaults An array of default get_terms() arguments.
* @param array $taxonomies An array of taxonomies.
* @return array
*/
function wc_change_get_terms_defaults( $defaults, $taxonomies ) {
if ( is_array( $taxonomies ) && 1 < count( $taxonomies ) ) {
return $defaults;
}
$taxonomy = is_array( $taxonomies ) ? (string) current( $taxonomies ) : $taxonomies;
$orderby = 'name';
if ( taxonomy_is_product_attribute( $taxonomy ) ) {
$orderby = wc_attribute_orderby( $taxonomy );
} elseif ( in_array( $taxonomy, apply_filters( 'woocommerce_sortable_taxonomies', array( 'product_cat' ) ), true ) ) {
$orderby = 'menu_order';
}
// Change defaults. Invalid values will be changed later @see wc_change_pre_get_terms.
// These are in place so we know if a specific order was requested.
switch ( $orderby ) {
case 'menu_order':
case 'name_num':
case 'parent':
$defaults['orderby'] = $orderby;
break;
}
return $defaults;
}
add_filter( 'get_terms_defaults', 'wc_change_get_terms_defaults', 10, 2 );
/**
* Adds support to get_terms for menu_order argument.
*
* @since 3.6.0
* @param WP_Term_Query $terms_query Instance of WP_Term_Query.
*/
function wc_change_pre_get_terms( $terms_query ) {
$args = &$terms_query->query_vars;
// Put back valid orderby values.
if ( 'menu_order' === $args['orderby'] ) {
$args['orderby'] = 'name';
$args['force_menu_order_sort'] = true;
}
if ( 'name_num' === $args['orderby'] ) {
$args['orderby'] = 'name';
$args['force_numeric_name'] = true;
}
// When COUNTING, disable custom sorting.
if ( 'count' === $args['fields'] ) {
return;
}
// Support menu_order arg used in previous versions.
if ( ! empty( $args['menu_order'] ) ) {
$args['order'] = 'DESC' === strtoupper( $args['menu_order'] ) ? 'DESC' : 'ASC';
$args['force_menu_order_sort'] = true;
}
if ( ! empty( $args['force_menu_order_sort'] ) ) {
$args['orderby'] = 'meta_value_num';
$args['meta_key'] = 'order'; // phpcs:ignore
$terms_query->meta_query->parse_query_vars( $args );
}
}
add_action( 'pre_get_terms', 'wc_change_pre_get_terms', 10, 1 );
/**
* Adjust term query to handle custom sorting parameters.
*
* @param array $clauses Clauses.
* @param array $taxonomies Taxonomies.
* @param array $args Arguments.
* @return array
*/
function wc_terms_clauses( $clauses, $taxonomies, $args ) {
global $wpdb;
// No need to filter when counting.
if ( strpos( $clauses['fields'], 'COUNT(*)' ) !== false ) {
return $clauses;
}
// Force numeric sort if using name_num custom sorting param.
if ( ! empty( $args['force_numeric_name'] ) ) {
$clauses['orderby'] = str_replace( 'ORDER BY t.name', 'ORDER BY t.name+0', $clauses['orderby'] );
}
// For sorting, force left join in case order meta is missing.
if ( ! empty( $args['force_menu_order_sort'] ) ) {
$clauses['join'] = str_replace( "INNER JOIN {$wpdb->termmeta} ON ( t.term_id = {$wpdb->termmeta}.term_id )", "LEFT JOIN {$wpdb->termmeta} ON ( t.term_id = {$wpdb->termmeta}.term_id AND {$wpdb->termmeta}.meta_key='order')", $clauses['join'] );
$clauses['where'] = str_replace( "{$wpdb->termmeta}.meta_key = 'order'", "( {$wpdb->termmeta}.meta_key = 'order' OR {$wpdb->termmeta}.meta_key IS NULL )", $clauses['where'] );
$clauses['orderby'] = 'DESC' === $args['order'] ? str_replace( 'meta_value+0', 'meta_value+0 DESC, t.name', $clauses['orderby'] ) : str_replace( 'meta_value+0', 'meta_value+0 ASC, t.name', $clauses['orderby'] );
}
return $clauses;
}
add_filter( 'terms_clauses', 'wc_terms_clauses', 99, 3 );
/**
* Helper to get cached object terms and filter by field using wp_list_pluck().
* Works as a cached alternative for wp_get_post_terms() and wp_get_object_terms().
*
* @since 3.0.0
* @param int $object_id Object ID.
* @param string $taxonomy Taxonomy slug.
* @param string $field Field name.
* @param string $index_key Index key name.
* @return array
*/
function wc_get_object_terms( $object_id, $taxonomy, $field = null, $index_key = null ) {
// Test if terms exists. get_the_terms() return false when it finds no terms.
$terms = get_the_terms( $object_id, $taxonomy );
if ( ! $terms || is_wp_error( $terms ) ) {
return array();
}
return is_null( $field ) ? $terms : wp_list_pluck( $terms, $field, $index_key );
}
/**
* Cached version of wp_get_post_terms().
* This is a private function (internal use ONLY).
*
* @since 3.0.0
* @param int $product_id Product ID.
* @param string $taxonomy Taxonomy slug.
* @param array $args Query arguments.
* @return array
*/
function _wc_get_cached_product_terms( $product_id, $taxonomy, $args = array() ) {
$cache_key = 'wc_' . $taxonomy . md5( wp_json_encode( $args ) );
$cache_group = WC_Cache_Helper::get_cache_prefix( 'product_' . $product_id ) . $product_id;
$terms = wp_cache_get( $cache_key, $cache_group );
if ( false !== $terms ) {
return $terms;
}
$terms = wp_get_post_terms( $product_id, $taxonomy, $args );
wp_cache_add( $cache_key, $terms, $cache_group );
return $terms;
}
/**
* Wrapper used to get terms for a product.
*
* @param int $product_id Product ID.
* @param string $taxonomy Taxonomy slug.
* @param array $args Query arguments.
* @return array
*/
function wc_get_product_terms( $product_id, $taxonomy, $args = array() ) {
if ( ! taxonomy_exists( $taxonomy ) ) {
return array();
}
return apply_filters( 'woocommerce_get_product_terms', _wc_get_cached_product_terms( $product_id, $taxonomy, $args ), $product_id, $taxonomy, $args );
}
/**
* Sort by name (numeric).
*
* @param WP_Post $a First item to compare.
* @param WP_Post $b Second item to compare.
* @return int
*/
function _wc_get_product_terms_name_num_usort_callback( $a, $b ) {
$a_name = (float) $a->name;
$b_name = (float) $b->name;
if ( abs( $a_name - $b_name ) < 0.001 ) {
return 0;
}
return ( $a_name < $b_name ) ? -1 : 1;
}
/**
* Sort by parent.
*
* @param WP_Post $a First item to compare.
* @param WP_Post $b Second item to compare.
* @return int
*/
function _wc_get_product_terms_parent_usort_callback( $a, $b ) {
if ( $a->parent === $b->parent ) {
return 0;
}
return ( $a->parent < $b->parent ) ? 1 : -1;
}
/**
* WooCommerce Dropdown categories.
*
* @param array $args Args to control display of dropdown.
*/
function wc_product_dropdown_categories( $args = array() ) {
global $wp_query;
$args = wp_parse_args(
$args,
array(
'pad_counts' => 1,
'show_count' => 1,
'hierarchical' => 1,
'hide_empty' => 1,
'show_uncategorized' => 1,
'orderby' => 'name',
'selected' => isset( $wp_query->query_vars['product_cat'] ) ? $wp_query->query_vars['product_cat'] : '',
'show_option_none' => __( 'Select a category', 'woocommerce' ),
'option_none_value' => '',
'value_field' => 'slug',
'taxonomy' => 'product_cat',
'name' => 'product_cat',
'class' => 'dropdown_product_cat',
)
);
if ( 'order' === $args['orderby'] ) {
$args['orderby'] = 'meta_value_num';
$args['meta_key'] = 'order'; // phpcs:ignore
}
wp_dropdown_categories( $args );
}
/**
* Custom walker for Product Categories.
*
* Previously used by wc_product_dropdown_categories, but wp_dropdown_categories has been fixed in core.
*
* @param mixed ...$args Variable number of parameters to be passed to the walker.
* @return mixed
*/
function wc_walk_category_dropdown_tree( ...$args ) {
if ( ! class_exists( 'WC_Product_Cat_Dropdown_Walker', false ) ) {
include_once WC()->plugin_path() . '/includes/walkers/class-wc-product-cat-dropdown-walker.php';
}
// The user's options are the third parameter.
if ( empty( $args[2]['walker'] ) || ! is_a( $args[2]['walker'], 'Walker' ) ) {
$walker = new WC_Product_Cat_Dropdown_Walker();
} else {
$walker = $args[2]['walker'];
}
return $walker->walk( ...$args );
}
/**
* Migrate data from WC term meta to WP term meta.
*
* When the database is updated to support term meta, migrate WC term meta data across.
* We do this when the new version is >= 34370, and the old version is < 34370 (34370 is when term meta table was added).
*
* @param string $wp_db_version The new $wp_db_version.
* @param string $wp_current_db_version The old (current) $wp_db_version.
*/
function wc_taxonomy_metadata_migrate_data( $wp_db_version, $wp_current_db_version ) {
if ( $wp_db_version >= 34370 && $wp_current_db_version < 34370 ) {
global $wpdb;
if ( $wpdb->query( "INSERT INTO {$wpdb->termmeta} ( term_id, meta_key, meta_value ) SELECT woocommerce_term_id, meta_key, meta_value FROM {$wpdb->prefix}woocommerce_termmeta;" ) ) {
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}woocommerce_termmeta" );
}
}
}
add_action( 'wp_upgrade', 'wc_taxonomy_metadata_migrate_data', 10, 2 );
/**
* Move a term before the a given element of its hierarchy level.
*
* @param int $the_term Term ID.
* @param int $next_id The id of the next sibling element in save hierarchy level.
* @param string $taxonomy Taxonomy.
* @param int $index Term index (default: 0).
* @param mixed $terms List of terms. (default: null).
* @return int
*/
function wc_reorder_terms( $the_term, $next_id, $taxonomy, $index = 0, $terms = null ) {
if ( ! $terms ) {
$terms = get_terms( $taxonomy, 'hide_empty=0&parent=0&menu_order=ASC' );
}
if ( empty( $terms ) ) {
return $index;
}
$id = intval( $the_term->term_id );
$term_in_level = false; // Flag: is our term to order in this level of terms.
foreach ( $terms as $term ) {
$term_id = intval( $term->term_id );
if ( $term_id === $id ) { // Our term to order, we skip.
$term_in_level = true;
continue; // Our term to order, we skip.
}
// the nextid of our term to order, lets move our term here.
if ( null !== $next_id && $term_id === $next_id ) {
++$index;
$index = wc_set_term_order( $id, $index, $taxonomy, true );
}
// Set order.
++$index;
$index = wc_set_term_order( $term_id, $index, $taxonomy );
/**
* After a term has had it's order set.
*/
do_action( 'woocommerce_after_set_term_order', $term, $index, $taxonomy );
// If that term has children we walk through them.
$children = get_terms( $taxonomy, "parent={$term_id}&hide_empty=0&menu_order=ASC" );
if ( ! empty( $children ) ) {
$index = wc_reorder_terms( $the_term, $next_id, $taxonomy, $index, $children );
}
}
// No nextid meaning our term is in last position.
if ( $term_in_level && null === $next_id ) {
$index = wc_set_term_order( $id, $index + 1, $taxonomy, true );
}
return $index;
}
/**
* Set the sort order of a term.
*
* @param int $term_id Term ID.
* @param int $index Index.
* @param string $taxonomy Taxonomy.
* @param bool $recursive Recursive (default: false).
* @return int
*/
function wc_set_term_order( $term_id, $index, $taxonomy, $recursive = false ) {
$term_id = (int) $term_id;
$index = (int) $index;
update_term_meta( $term_id, 'order', $index );
if ( ! $recursive ) {
return $index;
}
$children = get_terms( $taxonomy, "parent=$term_id&hide_empty=0&menu_order=ASC" );
foreach ( $children as $term ) {
++$index;
$index = wc_set_term_order( $term->term_id, $index, $taxonomy, true );
}
clean_term_cache( $term_id, $taxonomy );
return $index;
}
/**
* Function for recounting product terms, ignoring hidden products.
*
* This is used as the update_count_callback for the Product Category, Product Tag, and Product Brand
* taxonomies. By default, it actually calculates two (possibly different) counts for each
* term, which it stores in two different places. The first count is the one done by WordPress
* itself, and is based on the status of the objects that are assigned the terms. In this case,
* only products with the publish status are counted. This count is stored in the
* `wp_term_taxonomy` table in the `count` field.
*
* The second count is based on WooCommerce-specific characteristics. In addition to the
* publish status requirement, products are only counted if they are considered visible in the
* catalog. This count is stored in the `wp_termmeta` table. The wc_change_term_counts function
* is used to override the first count with the second count in some circumstances.
*
* Since the first count only needs to be recalculated when a product status is changed in some
* way, it can sometimes be skipped (thus avoiding some potentially expensive queries). Setting
* the $callback parameter to false skips the first count.
*
* @param array $terms List of terms. For legacy reasons, this can
* either be a list of taxonomy term IDs or an
* associative array in the format of
* term ID > parent term ID.
* @param WP_Taxonomy $taxonomy The relevant taxonomy.
* @param bool $callback Whether to also recalculate the term counts
* using the WP Core callback. Default true.
* @param bool $terms_are_term_taxonomy_ids Flag to indicate which format the list of
* terms is in. Default true, which indicates
* that it is a list of taxonomy term IDs.
*/
function _wc_term_recount( $terms, $taxonomy, $callback = true, $terms_are_term_taxonomy_ids = true ) {
global $wpdb;
/**
* Filter to allow/prevent recounting of terms as it could be expensive.
* A likely scenario for this is when bulk importing products. We could
* then prevent it from recounting per product but instead recount it once
* when import is done. Of course this means the import logic has to support this.
*
* @since 5.2
* @param bool
*/
if ( ! apply_filters( 'woocommerce_product_recount_terms', true ) ) {
return;
}
if ( true === $terms_are_term_taxonomy_ids ) {
$taxonomy_term_ids = $terms;
$term_ids = array_map(
function ( $term_taxonomy_id ) use ( $taxonomy ) {
$term = get_term_by( 'term_taxonomy_id', $term_taxonomy_id, $taxonomy->name );
return $term instanceof WP_Term ? $term->term_id : null;
},
$terms
);
} else {
$taxonomy_term_ids = array(); // Defer querying these until the callback check.
$term_ids = array_keys( $terms );
}
$term_ids = array_unique( array_filter( $term_ids ) );
$taxonomy_term_ids = array_unique( array_filter( $taxonomy_term_ids ) );
// Exit if we have no terms to count.
if ( empty( $term_ids ) ) {
return;
}
// Standard WP callback for calculating post term counts.
if ( $callback ) {
if ( count( $taxonomy_term_ids ) < 1 ) {
$taxonomy_term_ids = array_map(
function ( $term_id ) use ( $taxonomy ) {
$term = get_term_by( 'term_id', $term_id, $taxonomy->name );
return $term instanceof WP_Term ? $term->term_taxonomy_id : null;
},
$term_ids
);
}
_update_post_term_count( $taxonomy_term_ids, $taxonomy );
}
$exclude_term_ids = array();
$product_visibility_term_ids = wc_get_product_visibility_term_ids();
if ( $product_visibility_term_ids['exclude-from-catalog'] ) {
$exclude_term_ids[] = $product_visibility_term_ids['exclude-from-catalog'];
}
if (
'yes' === get_option( 'woocommerce_hide_out_of_stock_items' )
&& $product_visibility_term_ids[ ProductStockStatus::OUT_OF_STOCK ]
) {
$exclude_term_ids[] = $product_visibility_term_ids[ ProductStockStatus::OUT_OF_STOCK ];
}
$query = array(
'fields' => "
SELECT COUNT( DISTINCT ID ) FROM {$wpdb->posts} p
",
'join' => '',
'where' => "
WHERE 1=1
AND p.post_status = 'publish'
AND p.post_type = 'product'
",
);
if ( count( $exclude_term_ids ) ) {
$query['join'] .= " LEFT JOIN ( SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id IN ( " . implode( ',', array_map( 'absint', $exclude_term_ids ) ) . ' ) ) AS exclude_join ON exclude_join.object_id = p.ID';
$query['where'] .= ' AND exclude_join.object_id IS NULL';
}
// Ancestors need counting.
if ( is_taxonomy_hierarchical( $taxonomy->name ) ) {
foreach ( $term_ids as $term_id ) {
$term_ids = array_merge( $term_ids, get_ancestors( $term_id, $taxonomy->name ) );
}
$term_ids = array_unique( $term_ids );
}
// Count the terms.
foreach ( $term_ids as $term_id ) {
$terms_to_count = array( absint( $term_id ) );
if ( is_taxonomy_hierarchical( $taxonomy->name ) ) {
// We need to get the $term's hierarchy so we can count its children too.
$children = get_term_children( $term_id, $taxonomy->name );
if ( $children && ! is_wp_error( $children ) ) {
$terms_to_count = array_unique( array_map( 'absint', array_merge( $terms_to_count, $children ) ) );
}
}
// Generate term query.
$term_query = $query;
$term_query['join'] .= " INNER JOIN ( SELECT object_id FROM {$wpdb->term_relationships} INNER JOIN {$wpdb->term_taxonomy} using( term_taxonomy_id ) WHERE term_id IN ( " . implode( ',', array_map( 'absint', $terms_to_count ) ) . ' ) ) AS include_join ON include_join.object_id = p.ID';
// Get the count.
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$count = $wpdb->get_var( implode( ' ', $term_query ) );
// Update the count.
update_term_meta( $term_id, 'product_count_' . $taxonomy->name, absint( $count ) );
}
delete_transient( 'wc_term_counts' );
}
/**
* Recount terms after the stock amount changes.
*
* @param int $product_id Product ID.
*/
function wc_recount_after_stock_change( $product_id ) {
if ( 'yes' !== get_option( 'woocommerce_hide_out_of_stock_items' ) ) {
return;
}
if ( wp_defer_term_counting() ) {
// When deferring term counts, we're using the built in handling of `wp_update_term_count()` to deal with the deferring
// and, though, this will cause both the standard and stock based counts to be rerun, it is still more efficient
// in cases where deferred term counting was warranted.
$product_terms = get_the_terms( $product_id, 'product_cat' );
if ( is_array( $product_terms ) ) {
wp_update_term_count( array_column( $product_terms, 'term_taxonomy_id' ), 'product_cat' );
}
$product_terms = get_the_terms( $product_id, 'product_tag' );
if ( is_array( $product_terms ) ) {
wp_update_term_count( array_column( $product_terms, 'term_taxonomy_id' ), 'product_tag' );
}
} else {
_wc_recount_terms_by_product( $product_id );
}
}
add_action( 'woocommerce_product_set_stock_status', 'wc_recount_after_stock_change' );
/**
* Overrides the original term count for product categories and tags with the product count.
* that takes catalog visibility into account.
*
* @param array $terms List of terms.
* @param string|array $taxonomies Single taxonomy or list of taxonomies.
* @return array
*/
function wc_change_term_counts( $terms, $taxonomies ) {
if ( is_admin() || wp_doing_ajax() ) {
return $terms;
}
/**
* Filter which product taxonomies should have their term counts overridden to take catalog visibility into account.
*
* @since 2.1.0
*
* @param array $valid_taxonomies List of taxonomy slugs.
*/
$valid_taxonomies = apply_filters( 'woocommerce_change_term_counts', array( 'product_cat', 'product_tag', 'product_brand' ) );
$current_taxonomies = array_intersect( (array) $taxonomies, $valid_taxonomies );
if ( empty( $current_taxonomies ) ) {
return $terms;
}
$o_term_counts = get_transient( 'wc_term_counts' );
$term_counts = false === $o_term_counts ? array() : $o_term_counts;
foreach ( $terms as &$term ) {
if ( $term instanceof WP_Term && in_array( $term->taxonomy, $current_taxonomies, true ) ) {
$key = $term->term_id . '_' . $term->taxonomy;
if ( ! isset( $term_counts[ $key ] ) ) {
$count = get_term_meta( $term->term_id, 'product_count_' . $term->taxonomy, true );
$count = '' !== $count ? absint( $count ) : 0;
$term_counts[ $key ] = $count;
}
$term->count = $term_counts[ $key ];
}
}
// Update transient.
if ( $term_counts !== $o_term_counts ) {
set_transient( 'wc_term_counts', $term_counts, MONTH_IN_SECONDS );
}
return $terms;
}
add_filter( 'get_terms', 'wc_change_term_counts', 10, 2 );
/**
* Return products in a given term, and cache value.
*
* To keep in sync, product_count will be cleared on "set_object_terms".
*
* @param int $term_id Term ID.
* @param string $taxonomy Taxonomy.
* @return array
*/
function wc_get_term_product_ids( $term_id, $taxonomy ) {
$product_ids = get_term_meta( $term_id, 'product_ids', true );
if ( false === $product_ids || ! is_array( $product_ids ) ) {
$product_ids = get_objects_in_term( $term_id, $taxonomy );
update_term_meta( $term_id, 'product_ids', $product_ids );
}
return $product_ids;
}
/**
* When a post is updated and terms recounted (called by _update_post_term_count), clear the ids.
*
* @param int $object_id Object ID.
* @param array $terms An array of object terms.
* @param array $tt_ids An array of term taxonomy IDs.
* @param string $taxonomy Taxonomy slug.
* @param bool $append Whether to append new terms to the old terms.
* @param array $old_tt_ids Old array of term taxonomy IDs.
*/
function wc_clear_term_product_ids( $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids ) {
foreach ( $old_tt_ids as $term_id ) {
delete_term_meta( $term_id, 'product_ids' );
}
foreach ( $tt_ids as $term_id ) {
delete_term_meta( $term_id, 'product_ids' );
}
}
add_action( 'set_object_terms', 'wc_clear_term_product_ids', 10, 6 );
/**
* Get full list of product visibility term ids.
*
* @since 3.0.0
* @return int[]
*/
function wc_get_product_visibility_term_ids() {
if ( ! taxonomy_exists( 'product_visibility' ) ) {
wc_doing_it_wrong( __FUNCTION__, 'wc_get_product_visibility_term_ids should not be called before taxonomies are registered (woocommerce_after_register_post_type action).', '3.1' );
return array();
}
static $term_ids = array();
// The static variable doesn't work well with unit tests.
if ( count( $term_ids ) > 0 && ! class_exists( 'WC_Unit_Tests_Bootstrap' ) ) {
return $term_ids;
}
$term_ids = array_map(
'absint',
wp_parse_args(
wp_list_pluck(
get_terms(
array(
'taxonomy' => 'product_visibility',
'hide_empty' => false,
)
),
'term_taxonomy_id',
'name'
),
array(
'exclude-from-catalog' => 0,
'exclude-from-search' => 0,
'featured' => 0,
'outofstock' => 0,
'rated-1' => 0,
'rated-2' => 0,
'rated-3' => 0,
'rated-4' => 0,
'rated-5' => 0,
)
)
);
return $term_ids;
}
/**
* Recounts all terms for product categories and product tags.
*
* @since 5.2
*
* @param bool $include_callback True to update the standard term counts in addition to the product-specific counts,
* which will cause a lot more queries to run.
*
* @return void
*/
function wc_recount_all_terms( bool $include_callback = true ) {
$product_cats = get_terms(
array(
'taxonomy' => 'product_cat',
'hide_empty' => false,
'fields' => 'id=>parent',
)
);
_wc_term_recount( $product_cats, get_taxonomy( 'product_cat' ), $include_callback, false );
$product_tags = get_terms(
array(
'taxonomy' => 'product_tag',
'hide_empty' => false,
'fields' => 'id=>parent',
)
);
_wc_term_recount( $product_tags, get_taxonomy( 'product_tag' ), $include_callback, false );
}
/**
* Recounts terms by product.
*
* @since 5.2
* @param int $product_id The ID of the product.
* @return void
*/
function _wc_recount_terms_by_product( $product_id = '' ) {
if ( empty( $product_id ) ) {
return;
}
$product_terms = get_the_terms( $product_id, 'product_cat' );
if ( $product_terms ) {
$product_cats = array();
foreach ( $product_terms as $term ) {
$product_cats[ $term->term_id ] = $term->parent;
}
_wc_term_recount( $product_cats, get_taxonomy( 'product_cat' ), false, false );
}
$product_terms = get_the_terms( $product_id, 'product_tag' );
if ( $product_terms ) {
$product_tags = array();
foreach ( $product_terms as $term ) {
$product_tags[ $term->term_id ] = $term->parent;
}
_wc_term_recount( $product_tags, get_taxonomy( 'product_tag' ), false, false );
}
}
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* WC_HTTPS class.
*
* @class WC_HTTPS
* @version 2.2.0
* @package WooCommerce\Classes
* @category Class
* @author WooThemes
*/
class WC_HTTPS {
/**
* Hook in our HTTPS functions if we're on the frontend. This will ensure any links output to a page (when viewing via HTTPS) are also served over HTTPS.
*/
public static function init() {
if ( 'yes' === get_option( 'woocommerce_force_ssl_checkout' ) && ! is_admin() ) {
// HTTPS urls with SSL on
$filters = array(
'post_thumbnail_html',
'wp_get_attachment_image_attributes',
'wp_get_attachment_url',
'option_stylesheet_url',
'option_template_url',
'script_loader_src',
'style_loader_src',
'template_directory_uri',
'stylesheet_directory_uri',
'site_url',
);
foreach ( $filters as $filter ) {
add_filter( $filter, array( __CLASS__, 'force_https_url' ), 999 );
}
add_filter( 'page_link', array( __CLASS__, 'force_https_page_link' ), 10, 2 );
add_action( 'template_redirect', array( __CLASS__, 'force_https_template_redirect' ) );
if ( 'yes' == get_option( 'woocommerce_unforce_ssl_checkout' ) ) {
add_action( 'template_redirect', array( __CLASS__, 'unforce_https_template_redirect' ) );
}
}
add_action( 'http_api_curl', array( __CLASS__, 'http_api_curl' ), 10, 3 );
}
/**
* Force https for urls.
*
* @param mixed $content
* @return string
*/
public static function force_https_url( $content ) {
if ( is_ssl() ) {
if ( is_array( $content ) ) {
$content = array_map( 'WC_HTTPS::force_https_url', $content );
} else {
$content = str_replace( 'http:', 'https:', (string) $content );
}
}
return $content;
}
/**
* Force a post link to be SSL if needed.
*
* @param string $link
* @param int $page_id
*
* @return string
*/
public static function force_https_page_link( $link, $page_id ) {
if ( in_array( $page_id, array( get_option( 'woocommerce_checkout_page_id' ), get_option( 'woocommerce_myaccount_page_id' ) ) ) ) {
$link = str_replace( 'http:', 'https:', $link );
} elseif ( 'yes' === get_option( 'woocommerce_unforce_ssl_checkout' ) && ! wc_site_is_https() ) {
$link = str_replace( 'https:', 'http:', $link );
}
return $link;
}
/**
* Template redirect - if we end up on a page ensure it has the correct http/https url.
*/
public static function force_https_template_redirect() {
if ( ! is_ssl() && ( is_checkout() || is_account_page() || apply_filters( 'woocommerce_force_ssl_checkout', false ) ) ) {
if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) {
wp_safe_redirect( preg_replace( '|^http://|', 'https://', $_SERVER['REQUEST_URI'] ) );
exit;
} else {
wp_safe_redirect( 'https://' . ( ! empty( $_SERVER['HTTP_X_FORWARDED_HOST'] ) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST'] ) . $_SERVER['REQUEST_URI'] );
exit;
}
}
}
/**
* Template redirect - if we end up on a page ensure it has the correct http/https url.
*/
public static function unforce_https_template_redirect() {
if ( function_exists( 'is_customize_preview' ) && is_customize_preview() ) {
return;
}
if ( ! wc_site_is_https() && is_ssl() && $_SERVER['REQUEST_URI'] && ! is_checkout() && ! wp_doing_ajax() && ! is_account_page() && apply_filters( 'woocommerce_unforce_ssl_checkout', true ) ) {
if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) {
wp_safe_redirect( preg_replace( '|^https://|', 'http://', $_SERVER['REQUEST_URI'] ) );
exit;
} else {
wp_safe_redirect( 'http://' . ( ! empty( $_SERVER['HTTP_X_FORWARDED_HOST'] ) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST'] ) . $_SERVER['REQUEST_URI'] );
exit;
}
}
}
/**
* Force posts to PayPal to use TLS v1.2. See:
* https://core.trac.wordpress.org/ticket/36320
* https://core.trac.wordpress.org/ticket/34924#comment:13
* https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US
*
* @param string $handle
* @param mixed $r
* @param string $url
*/
public static function http_api_curl( $handle, $r, $url ) {
if ( strstr( $url, 'https://' ) && ( strstr( $url, '.paypal.com/nvp' ) || strstr( $url, '.paypal.com/cgi-bin/webscr' ) ) ) {
curl_setopt( $handle, CURLOPT_SSLVERSION, 6 );
}
}
}
WC_HTTPS::init();

Support