Commit inicial - WordPress Análisis de Precios Unitarios

- WordPress core y plugins
- Tema Twenty Twenty-Four configurado
- Plugin allow-unfiltered-html.php simplificado
- .gitignore configurado para excluir wp-config.php y uploads

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-11-03 21:04:30 -06:00
commit a22573bf0b
24068 changed files with 4993111 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
<?php
if ( ! class_exists( 'BWF_Compatibility_With_CURCY' ) ) {
#[AllowDynamicProperties]
class BWF_Compatibility_With_CURCY {
public function __construct() {
}
public function is_enable() {
return class_exists( 'WOOMULTI_CURRENCY_F_Data' );
}
public function alter_fixed_amount( $price, $currency = null ) {
if ( class_exists( 'WOOMULTI_CURRENCY_F_Data' ) ) {
$currentCurrencyRate = 1;
$multiCurrencySettings = WOOMULTI_CURRENCY_F_Data::get_ins();
$wmcCurrencies = $multiCurrencySettings->get_list_currencies();
$currentCurrency = $multiCurrencySettings->get_current_currency();
$currentCurrencyRate = floatval( $wmcCurrencies[ $currentCurrency ]['rate'] );
// Convert the price to the base currency
$price = $price / $currentCurrencyRate;
}
return $price;
}
public function get_fixed_currency_price_reverse( $price, $from = null, $base = null ) {
if ( class_exists( 'WOOMULTI_CURRENCY_F_Data' ) ) {
$data = new WOOMULTI_CURRENCY_F_Data();
$from = ( is_null( $from ) ) ? $data->get_current_currency() : $from;
$base = ( is_null( $base ) ) ? get_option( 'woocommerce_currency' ) : $base;
$rates = $data->get_exchange( $from, $base );
if ( is_array( $rates ) && isset( $rates[ $base ] ) ) {
$price = $price * $rates[ $base ];
}
}
return $price;
}
}
BWF_Plugin_Compatibilities::register( new BWF_Compatibility_With_CURCY(), 'curcy' );
}

View File

@@ -0,0 +1,88 @@
<?php
if ( ! class_exists( 'BWF_Compatibility_With_Aelia_CS' ) ) {
#[AllowDynamicProperties]
class BWF_Compatibility_With_Aelia_CS {
public function __construct() {
}
public function is_enable() {
if ( false === class_exists( 'Aelia\WC\CurrencySwitcher\WC_Aelia_CurrencySwitcher' ) ) {
return false;
}
return true;
}
/**
*
* Modifies the amount for the fixed discount given by the admin in the currency selected.
*
* @param integer|float $price
*
* @return float
*/
public function alter_fixed_amount( $price, $currency = null ) {
return $this->get_price_in_currency( $price, $currency );
}
/**
* Basic integration with WooCommerce Currency Switcher, developed by Aelia
* (http://aelia.co). This method can be used by any 3rd party plugin to
* return prices converted to the active currency.
*
* Need a consultation? Find us on Codeable: https://aelia.co/hire_us
*
* @param double price The source price.
* @param string to_currency The target currency. If empty, the active currency
* will be taken.
* @param string from_currency The source currency. If empty, WooCommerce base
* currency will be taken.
*
* @return double The price converted from source to destination currency.
* @author Aelia <support@aelia.co>
* @link https://aelia.co
*/
public function get_price_in_currency( $price, $to_currency = null, $from_currency = null ) {
// If source currency is not specified, take the shop's base currency as a default
if ( empty( $from_currency ) ) {
$from_currency = get_option( 'woocommerce_currency' );
}
// If target currency is not specified, take the active currency as a default.
// The Currency Switcher sets this currency automatically, based on the context. Other
// plugins can also override it, based on their own custom criteria, by implementing
// a filter for the "woocommerce_currency" hook.
//
// For example, a subscription plugin may decide that the active currency is the one
// taken from a previous subscription, because it's processing a renewal, and such
// renewal should keep the original prices, in the original currency.
if ( empty( $to_currency ) ) {
$to_currency = get_woocommerce_currency();
}
// Call the currency conversion filter. Using a filter allows for loose coupling. If the
// Aelia Currency Switcher is not installed, the filter call will return the original
// amount, without any conversion being performed. Your plugin won't even need to know if
// the multi-currency plugin is installed or active
return apply_filters( 'wc_aelia_cs_convert', $price, $from_currency, $to_currency );
}
function get_fixed_currency_price_reverse( $price, $from = null, $base = null ) {
$base = ( is_null( $base ) ) ? get_option( 'woocommerce_currency' ) : $base;
$price = $this->get_price_in_currency( $price, $base, $from );
return $price;
}
}
BWF_Plugin_Compatibilities::register( new BWF_Compatibility_With_Aelia_CS(), 'aelia_cs' );
}

View File

@@ -0,0 +1,63 @@
<?php
if ( ! class_exists( 'BWF_Compatibility_With_WC_Price_Based_On_Country' ) ) {
#[AllowDynamicProperties]
class BWF_Compatibility_With_WC_Price_Based_On_Country {
public function is_enable() {
return class_exists( 'WC_Product_Price_Based_Country' );
}
/**
*
* Modifies the amount for the fixed discount given by the admin in the currency selected.
*
* @param integer|float $price
*
* @return float
*/
public function alter_fixed_amount( $price, $currency = null ) {
if ( ! $this->is_enable() ) {
return $price;
}
$rate = $this->get_exchange_rate( $currency );
return $price * $rate;
}
public function get_fixed_currency_price_reverse( $price, $currency = null, $base = null ) {
if ( ! $this->is_enable() ) {
return $price;
}
$rate = $this->get_exchange_rate( $currency );
return $price / $rate;
}
/**
* Get exchange rate
*
* @param $currency
*
* @return float|int
*/
public function get_exchange_rate( $currency ) {
if ( ! class_exists( 'WCPBC_Pricing_Zones' ) ) {
return 1;
}
$zones = WCPBC_Pricing_Zones::get_zones();
foreach ( $zones as $zone ) {
/** @var $zone WCPBC_Pricing_Zone */
if ( $currency !== $zone->get_currency() ) {
continue;
}
return $zone->get_exchange_rate();
}
return 1;
}
}
BWF_Plugin_Compatibilities::register( new BWF_Compatibility_With_WC_Price_Based_On_Country(), 'wc_price_based_on_country' );
}

View File

@@ -0,0 +1,162 @@
<?php
if ( ! class_exists( 'BWF_Compatibility_With_WooCommerce_Payments' ) ) {
#[AllowDynamicProperties]
class BWF_Compatibility_With_WooCommerce_Payments {
public function __construct() {
}
public function is_enable() {
if ( class_exists( 'WCPay\MultiCurrency\MultiCurrency' ) && function_exists( 'WC_Payments_Multi_Currency' ) ) {
return true;
}
return false;
}
/**
* Adds currency parameter to URLs to maintain currency context
*
* @param string $url
* @param WC_Order $order
*
* @return string
*/
public function maybe_add_currency_converter_url( $url, $order ) {
if ( ! $order instanceof WC_Order ) {
return $url;
}
$currency = $order->get_currency();
if ( $currency ) {
$url = add_query_arg( array( 'currency' => strtoupper( $currency ) ), $url );
}
return $url;
}
/**
* Modifies the amount for the fixed discount given by the admin in the currency selected.
*
* @param integer|float $price
* @param string|null $currency
*
* @return float
*/
public function alter_fixed_amount( $price, $currency = null ) {
if ( ! $this->is_enable() ) {
return $price;
}
$multi_currency = WC_Payments_Multi_Currency();
if ( ! $multi_currency ) {
return $price;
}
return $multi_currency->get_price( $price, 'product' );
}
/**
* Converts price back to the base currency (reverse conversion)
*
* @param float $price
* @param string|null $from
* @param string|null $base
*
* @return float
*/
public function get_fixed_currency_price_reverse( $price, $from = null, $base = null ) {
if ( ! $this->is_enable() ) {
return $price;
}
$multi_currency = WC_Payments_Multi_Currency();
if ( ! $multi_currency ) {
return $price;
}
$from = ( is_null( $from ) ) ? $multi_currency->get_selected_currency()->get_code() : $from;
$base = ( is_null( $base ) ) ? $multi_currency->get_default_currency()->get_code() : $base;
// If currencies are the same, no conversion needed
if ( $from === $base ) {
return $price;
}
try {
// Use WooCommerce Payments' raw conversion method
return $multi_currency->get_raw_conversion( $price, $base, $from );
} catch ( Exception $e ) {
// If conversion fails, return original price
return $price;
}
}
/**
* Gets the current selected currency code
*
* @return string|null
*/
public function get_current_currency() {
if ( ! $this->is_enable() ) {
return null;
}
$multi_currency = WC_Payments_Multi_Currency();
if ( ! $multi_currency ) {
return null;
}
return $multi_currency->get_selected_currency()->get_code();
}
/**
* Gets the default store currency code
*
* @return string|null
*/
public function get_default_currency() {
if ( ! $this->is_enable() ) {
return null;
}
$multi_currency = WC_Payments_Multi_Currency();
if ( ! $multi_currency ) {
return null;
}
return $multi_currency->get_default_currency()->get_code();
}
/**
* Gets the exchange rate for a currency
*
* @param string $currency_code
*
* @return float
*/
public function get_exchange_rate( $currency_code ) {
if ( ! $this->is_enable() ) {
return 1.0;
}
$multi_currency = WC_Payments_Multi_Currency();
if ( ! $multi_currency ) {
return 1.0;
}
$enabled_currencies = $multi_currency->get_enabled_currencies();
if ( isset( $enabled_currencies[ $currency_code ] ) ) {
return $enabled_currencies[ $currency_code ]->get_rate();
}
return 1.0;
}
}
BWF_Plugin_Compatibilities::register( new BWF_Compatibility_With_WooCommerce_Payments(), 'woocommerce_payments' );
}

View File

@@ -0,0 +1,56 @@
<?php
if ( ! class_exists( 'BWF_Compatibility_With_WOOCS' ) ) {
#[AllowDynamicProperties]
class BWF_Compatibility_With_WOOCS {
public function __construct() {
}
public function is_enable() {
if ( isset( $GLOBALS['WOOCS'] ) && $GLOBALS['WOOCS'] instanceof WOOCS ) {
return true;
}
return false;
}
public function get_currency_symbol( $currency ) {
global $WOOCS;
$WOOCS->current_currency = $currency;
return get_woocommerce_currency_symbol( $currency );
}
/**
*
* Modifies the amount for the fixed discount given by the admin in the currency selected.
*
* @param integer|float $price
*
* @return float
*/
public function alter_fixed_amount( $price, $currency = null ) {
return $GLOBALS['WOOCS']->woocs_exchange_value( $price );
}
function get_fixed_currency_price_reverse( $price, $from = null, $base = null ) { //phpcs:ignore
$currencies = get_option( 'woocs' );
$from = ( is_null( $from ) ) ? $GLOBALS['WOOCS']->current_currency : $from;
if ( is_array( $currencies ) && ! empty( $currencies )) {
foreach ( $currencies as $key => $value ) {
if ( $key === $from ) {
$rate = $value['rate'];
$price = $price * ( 1 / $rate );
}
}
}
return $price;
}
}
BWF_Plugin_Compatibilities::register( new BWF_Compatibility_With_WOOCS(), 'woocs' );
}

View File

@@ -0,0 +1,68 @@
<?php
if ( ! class_exists( 'BWF_Compatibility_With_WooMultiCurrency' ) ) {
#[AllowDynamicProperties]
class BWF_Compatibility_With_WooMultiCurrency {
public function __construct() {
}
public function is_enable() {
if ( defined( 'WOOMULTI_CURRENCY_VERSION' ) ) {
return true;
}
return false;
}
/**
*
* @param $url
* @param WC_Order $order
*
* @return string
*/
public function maybe_add_currency_converter_url( $url, $order ) {
if ( ! $order instanceof WC_Order ) {
return $url;
}
return add_query_arg( array( 'wmc-currency' => strtoupper( $order->get_currency() ) ), $url );
}
/**
*
* Modifies the amount for the fixed discount given by the admin in the currency selected.
*
* @param integer|float $price
*
* @return float
*/
public function alter_fixed_amount( $price, $currency = null ) {
return wmc_get_price( $price, $currency );
}
function get_fixed_currency_price_reverse( $price, $from = null, $base = null ) {
$data = new WOOMULTI_CURRENCY_Data();
$from = ( is_null( $from ) ) ? $data->get_current_currency() : $from;
$base = ( is_null( $base ) ) ? get_option( 'woocommerce_currency' ) : $base;
$rates = $data->get_exchange( $from, $base );
if ( is_array( $rates ) && isset( $rates[ $base ] ) ) {
$price = $price * $rates[ $base ];
}
return $price;
}
}
BWF_Plugin_Compatibilities::register( new BWF_Compatibility_With_WooMultiCurrency(), 'woomulticurrency' );
}

View File

@@ -0,0 +1,65 @@
<?php
if ( ! class_exists( 'BWF_Compatibility_With_WPML_MultiCurrency' ) ) {
#[AllowDynamicProperties]
class BWF_Compatibility_With_WPML_MultiCurrency {
public function __construct() {
}
public function is_enable() {
global $woocommerce_wpml;
if ( class_exists( 'woocommerce_wpml' ) && $woocommerce_wpml instanceof woocommerce_wpml ) {
return true;
}
return false;
}
/**
*
* Modifies the amount for the fixed discount given by the admin in the currency selected.
*
* @param integer|float $price
*
* @return float
*/
public function alter_fixed_amount( $price, $currency = null ) {
if ( ! class_exists( 'SitePress' ) ) {
return $price;
}
global $woocommerce_wpml;
if ( WCML_MULTI_CURRENCIES_INDEPENDENT !== $woocommerce_wpml->settings['enable_multi_currency'] ) {
return $price;
}
return $woocommerce_wpml->get_multi_currency()->prices->convert_price_amount( $price );
}
function get_fixed_currency_price_reverse( $price, $from = null, $base = null ) {
if ( ! class_exists( 'SitePress' ) ) {
return $price;
}
global $woocommerce_wpml;
if ( WCML_MULTI_CURRENCIES_INDEPENDENT !== $woocommerce_wpml->settings['enable_multi_currency'] ) {
return $price;
}
$price = $woocommerce_wpml->get_multi_currency()->prices->unconvert_price_amount( $price, $from );
return $price;
}
}
BWF_Plugin_Compatibilities::register( new BWF_Compatibility_With_WPML_MultiCurrency(), 'woowpmlmulticurrency' );
}

View File

@@ -0,0 +1,65 @@
<?php
if ( ! class_exists( 'BWF_Compatibility_With_YayCurrency' ) ) {
#[AllowDynamicProperties]
class BWF_Compatibility_With_YayCurrency {
public function is_enable() {
return class_exists( 'Yay_Currency\Helpers\YayCurrencyHelper' );
}
/**
* Modifies the amount for the fixed discount given by the admin in the currency selected.
*
* @param integer|float $price
*
* @return float
*/
public function alter_fixed_amount( $price, $currency = null ) {
if ( ! $this->is_enable() ) {
return $price;
}
$currency = $this->get_formatted_currency( $currency );
if ( empty( $currency ) ) {
return $price;
}
return Yay_Currency\Helpers\YayCurrencyHelper::calculate_price_by_currency( $price, false, $currency );
}
function get_fixed_currency_price_reverse( $price, $from = null, $base = null ) {
if ( ! $this->is_enable() ) {
return $price;
}
$currency = $this->get_formatted_currency( $from );
if ( empty( $currency ) ) {
return $price;
}
return Yay_Currency\Helpers\YayCurrencyHelper::reverse_calculate_price_by_currency( $price, $currency );
}
public function get_formatted_currency( $from ) {
if ( ! $this->is_enable() ) {
return [];
}
return Yay_Currency\Helpers\YayCurrencyHelper::get_currency_by_currency_code( $from );
}
public function get_currency_symbol( $currency ) {
if ( ! class_exists( 'Yay_Currency\Helpers\YayCurrencyHelper' ) ) {
return '';
}
$apply_currency = $this->get_formatted_currency( $currency );
add_filter( 'yay_currency_detect_current_currency', function () use ( $apply_currency ) {
return $apply_currency;
} );
return Yay_Currency\Helpers\YayCurrencyHelper::get_symbol_by_currency_code( $currency );
}
}
BWF_Plugin_Compatibilities::register( new BWF_Compatibility_With_YayCurrency(), 'yaycurrency' );
}

View File

@@ -0,0 +1,116 @@
<?php
if ( ! class_exists( 'BWF_Plugin_Compatibilities' ) ) {
/**
* Class BWF_Plugin_Compatibilities
* Loads all the compatibilities files we have to provide compatibility with each plugin
*/
#[AllowDynamicProperties]
class BWF_Plugin_Compatibilities {
public static $plugin_compatibilities = array();
public static function load_all_compatibilities() {
$compat = [
'class-bwf-compatibilitiy-with-curcy.php' => class_exists( 'WOOMULTI_CURRENCY_F_VERSION' ),
'class-bwf-compatibility-with-aelia-cs.php' => class_exists( 'Aelia\WC\CurrencySwitcher\WC_Aelia_CurrencySwitcher' ),
'class-bwf-compatibility-with-woocs.php' => isset( $GLOBALS['WOOCS'] ) && $GLOBALS['WOOCS'] instanceof WOOCS,
'class-bwf-compatibility-with-woomulticurrency.php' => defined( 'WOOMULTI_CURRENCY_VERSION' ),
'class-bwf-compatibility-with-wpml-multicurrency.php' => class_exists( 'woocommerce_wpml' ),
'class-bwf-compatibility-with-yaycurrency.php' => class_exists( 'Yay_Currency\Helpers\YayCurrencyHelper' ),
'class-bwf-compatibility-with-wc-price-based-on-country.php' => class_exists( 'WC_Product_Price_Based_Country' ),
'class-bwf-compatibility-with-woocommerce-payments.php' => function_exists( 'WC_Payments_Multi_Currency' ),
];
self::add_files( $compat );
}
public static function register( $object, $slug ) {
self::$plugin_compatibilities[ $slug ] = $object;
}
public static function get_compatibility_class( $slug ) {
return ( isset( self::$plugin_compatibilities[ $slug ] ) ) ? self::$plugin_compatibilities[ $slug ] : false;
}
public static function get_fixed_currency_price( $price, $currency = null ) {
if ( empty( self::$plugin_compatibilities ) ) {
return $price;
}
foreach ( self::$plugin_compatibilities as $plugins_class ) {
if ( method_exists( $plugins_class, 'is_enable' ) && $plugins_class->is_enable() && is_callable( array( $plugins_class, 'alter_fixed_amount' ) ) ) {
return call_user_func( array( $plugins_class, 'alter_fixed_amount' ), $price, $currency );
}
}
return $price;
}
public static function get_fixed_currency_price_reverse( $price, $from = null, $to = null ) {
try {
if ( empty( self::$plugin_compatibilities ) ) {
BWF_Plugin_Compatibilities::load_all_compatibilities();
}
if ( empty( self::$plugin_compatibilities ) ) {
return $price;
}
foreach ( self::$plugin_compatibilities as $plugins_class ) {
if ( method_exists( $plugins_class, 'is_enable' ) && $plugins_class->is_enable() && is_callable( array( $plugins_class, 'get_fixed_currency_price_reverse' ) ) ) {
return call_user_func( array( $plugins_class, 'get_fixed_currency_price_reverse' ), $price, $from, $to );
}
}
} catch ( Exception|Error $e ) {
BWF_Logger::get_instance()->log( 'Error while getting reversed price through compatibility files: ' . $e->getMessage(), 'bwf-compatibilities', 'buildwoofunnels', true );
}
return $price;
}
/**
* Get currency symbol
*
* @param $currency
*
* @return mixed|string
*/
public static function get_currency_symbol( $currency ) {
if ( empty( self::$plugin_compatibilities ) ) {
BWF_Plugin_Compatibilities::load_all_compatibilities();
}
if ( empty( self::$plugin_compatibilities ) ) {
return '';
}
foreach ( self::$plugin_compatibilities as $plugins_class ) {
if ( method_exists( $plugins_class, 'is_enable' ) && $plugins_class->is_enable() && is_callable( array( $plugins_class, 'get_currency_symbol' ) ) ) {
return call_user_func( array( $plugins_class, 'get_currency_symbol' ), $currency );
}
}
return '';
}
public static function add_files( $paths ) {
try {
foreach ( $paths as $file => $condition ) {
if ( false === $condition ) {
continue;
}
include_once __DIR__ . '/' . $file;
}
} catch ( Exception|Error $e ) {
BWF_Logger::get_instance()->log( 'Error while loading compatibility files: ' . $e->getMessage(), 'bwf-compatibilities' );
}
}
}
}

View File

@@ -0,0 +1,591 @@
<?php
/**
* WooCommerce Plugin Compatibility
*
* This source file is subject to the GNU General Public License v3.0
* that is bundled with this package in the file license.txt.
* It is also available through the world-wide-web at this URL:
* http://www.gnu.org/licenses/gpl-3.0.html
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@skyverge.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade the plugin to newer
* versions in the future. If you wish to customize the plugin for your
* needs please refer to http://www.skyverge.com
*
* @author SkyVerge
* @copyright Copyright (c) 2013, SkyVerge, Inc.
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
} // Exit if accessed directly
if ( ! class_exists( 'BWF_WC_Compatibility' ) ) :
/**
* WooCommerce Compatibility Utility Class
*
* The unfortunate purpose of this class is to provide a single point of
* compatibility functions for dealing with supporting multiple versions
* of WooCommerce.
*
* The recommended procedure is to rename this file/class, replacing "my plugin"
* with the particular plugin name, so as to avoid clashes between plugins.
* Over time we expect to remove methods from this class, using the current
* ones directly, as support for older versions of WooCommerce is dropped.
*
* Current Compatibility: 2.0.x - 2.1
*
* @version 1.0
*/
#[AllowDynamicProperties]
class BWF_WC_Compatibility {
/**
* Compatibility function for outputting a woocommerce attribute label
*
* @param string $label the label to display
*
* @return string the label to display
* @since 1.0
*
*/
public static function wc_attribute_label( $label ) {
return wc_attribute_label( $label );
}
public static function wc_attribute_taxonomy_name( $name ) {
return wc_attribute_taxonomy_name( $name );
}
public static function wc_get_attribute_taxonomies() {
return wc_get_attribute_taxonomies();
}
public static function wc_placeholder_img_src() {
return wc_placeholder_img_src();
}
/**
* @param WC_Product $product
*
* @return string
*/
public static function woocommerce_get_formatted_product_name( $product ) {
if ( ! $product instanceof WC_Product ) {
return __( 'No title', 'woofunnels' ); // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
}
return $product->get_formatted_name();
}
/**
* @param $order
* @param $item
*
* @return WC_Product
*/
public static function get_product_from_item( $order, $item ) {
return $item->get_product();
}
public static function get_short_description( $product ) {
if ( $product === false ) {
return '';
}
return apply_filters( 'woocommerce_short_description', $product->get_short_description() );
}
public static function get_productname_from_item( $order, $item ) {
return $item->get_name();
}
public static function get_qty_from_item( $order, $item ) {
return $item->get_quantity();
}
public static function get_display_item_meta( $order, $item ) {
wc_display_item_meta( $item );
}
public static function get_display_item_downloads( $order, $item ) {
wc_display_item_downloads( $item );
}
public static function get_purchase_note( $product ) {
return $product ? $product->get_purchase_note() : '';
}
/**
* @param WC_Order $order
*
* @return mixed|string
*/
public static function get_order_currency( $order ) {
return $order instanceof WC_Order ? $order->get_currency() : get_woocommerce_currency();
}
public static function get_payment_gateway_from_order( $order ) {
return $order->get_payment_method();
}
public static function get_item_subtotal( $order, $item ) {
return $item->get_subtotal();
}
public static function get_shipping_country_from_order( $order ) {
return $order->get_shipping_country();
}
public static function get_billing_country_from_order( $order ) {
return $order->get_billing_country();
}
public static function get_order_id( $order ) {
if ( ! $order instanceof WC_Order ) {
return $order;
}
return $order->get_id();
}
/**
* @param WC_Order $order
*
* @return mixed
*/
public static function get_order_billing_1( $order ) {
return $order->get_billing_address_1();
}
/**
* @param WC_Order $order
*
* @return mixed
*/
public static function get_order_data( $order, $key ) {
if ( method_exists( $order, 'get_' . $key ) ) {
return call_user_func( array( $order, 'get_' . $key ) );
}
return self::get_order_meta( $order, $key );
}
/**
* @param WC_Order $order
*
* @return mixed
*/
public static function get_billing_first_name( $order ) {
return $order->get_billing_first_name();
}
/**
* @param WC_Order $order
*
* @return mixed
*/
public static function get_billing_last_name( $order ) {
return $order->get_billing_last_name();
}
/**
* @param WC_Order $order
*
* @return mixed
*/
public static function get_order_status( $order ) {
$status = $order->get_status();
return ( strpos( $status, 'wc-' ) === false ) ? 'wc-' . $status : $status;
}
/**
* @param WC_Order $order
*
* @return mixed
*/
public static function get_order_billing_2( $order ) {
return $order->get_billing_address_2();
}
/**
* @param WC_Order $order
*
* @return mixed
*/
public static function get_order_shipping_1( $order ) {
return $order->get_shipping_address_1();
}
/**
* Returns true if the installed version of WooCommerce is 2.6 or greater
*
* @return boolean true if the installed version of WooCommerce is 2.1 or greater
* @since 1.0
*/
public static function is_wc_version_gte_3_7() {
return version_compare( self::get_wc_version(), '3.7.0', 'ge' );
}
/**
* @param WC_Order $order
*
* @return mixed
*/
public static function get_used_coupons( $order ) {
return $order->get_coupon_codes();
}
/**
* @param WC_Order $order
*
* @return mixed
*/
public static function get_order_shipping_total( $order ) {
return $order->get_shipping_total();
}
/**
* @param WC_Order $order
*
* @return mixed
*/
public static function get_order_shipping_2( $order ) {
return $order->get_shipping_address_2();
}
/**
* @param WC_Order $order
*
* @return mixed
*/
public static function get_order_date( $order ) {
return $order->get_date_created();
}
/**
* @param WC_Order $order
*
* @return mixed
*/
public static function get_payment_method( $order ) {
return $order->get_payment_method_title();
}
/**
* @param WC_Order $order
*
* @return mixed
*/
public static function get_customer_ip_address( $order ) {
return $order->get_customer_ip_address();
}
/**
* @param WC_Order $order
*
* @return mixed
*/
public static function get_customer_note( $order ) {
return $order->get_customer_note();
}
/**
* @param $date
* @param string $format
*
* @return string
*/
public static function get_formatted_date( $date, $format = '' ) {
if ( empty( $format ) ) {
$format = get_option( 'date_format' );
}
return wc_format_datetime( $date, $format );
}
/**
* Compatibility function to add and store a notice
*
* @param string $message The text to display in the notice.
* @param string $notice_type The singular name of the notice type - either error, success or notice. [optional]
*
* @since 1.0
*
*/
public static function wc_add_notice( $message, $notice_type = 'success' ) {
wc_add_notice( $message, $notice_type );
}
/**
* Prints messages and errors which are stored in the session, then clears them.
*
* @since 1.0
*/
public static function wc_print_notices() {
wc_print_notices();
}
/**
* Compatibility function to queue some JavaScript code to be output in the footer.
*
* @param string $code javascript
*
* @since 1.0
*
*/
public static function wc_enqueue_js( $code ) {
wc_enqueue_js( $code );
}
/**
* Sets WooCommerce messages
*
* @since 1.0
*/
public static function set_messages() {
if ( ! self::is_wc_version_gte_2_1() ) {
global $woocommerce;
$woocommerce->set_messages();
}
}
/**
* Returns a new instance of the woocommerce logger
*
* @return WC_Logger logger
* @since 1.0
*/
public static function new_wc_logger() {
return new WC_Logger();
}
/**
* Format decimal numbers ready for DB storage
*
* Sanitize, remove locale formatting, and optionally round + trim off zeros
*
* @param float|string $number Expects either a float or a string with a decimal separator only (no thousands)
* @param mixed $dp number of decimal points to use, blank to use woocommerce_price_num_decimals, or false to avoid all rounding.
* @param boolean $trim_zeros from end of string
*
* @return string
* @since 1.0
*
*/
public static function wc_format_decimal( $number, $dp = false, $trim_zeros = false ) {
return wc_format_decimal( $number, $dp, $trim_zeros );
}
/**
* Get the count of notices added, either for all notices (default) or for one particular notice type specified
* by $notice_type.
*
* @param string $notice_type The name of the notice type - either error, success or notice. [optional]
*
* @return int the notice count
* @since 1.0
*
*/
public static function wc_notice_count( $notice_type = '' ) {
return wc_notice_count( $notice_type );
}
/**
* Compatibility function to use the new WC_Admin_Meta_Boxes class for the save_errors() function
*
* @return old save_errors function or new class
* @since 1.0-1
*/
public static function save_errors() {
WC_Admin_Meta_Boxes::save_errors();
}
/**
* Compatibility function to get the version of the currently installed WooCommerce
*
* @return string woocommerce version number or null
* @since 1.0
*/
public static function get_wc_version() {
// WOOCOMMERCE_VERSION is now WC_VERSION, though WOOCOMMERCE_VERSION is still available for backwards compatibility, we'll disregard it on 2.1+
if ( defined( 'WC_VERSION' ) && WC_VERSION ) {
return WC_VERSION;
}
if ( defined( 'WOOCOMMERCE_VERSION' ) && WOOCOMMERCE_VERSION ) {
return WOOCOMMERCE_VERSION;
}
return null;
}
/**
* Returns the WooCommerce instance
*
* @return WooCommerce woocommerce instance
* @since 1.0
*/
public static function WC() {
return WC();
}
/**
* Returns true if the WooCommerce plugin is loaded
*
* @return boolean true if WooCommerce is loaded
* @since 1.0
*/
public static function is_wc_loaded() {
return class_exists( 'WooCommerce' );
}
/**
* Returns true if the installed version of WooCommerce is 2.1 or greater
*
* @return boolean true if the installed version of WooCommerce is 2.1 or greater
* @since 1.0
*/
public static function is_wc_version_gte_2_1() {
// can't use gte 2.1 at the moment because 2.1-BETA < 2.1
return self::is_wc_version_gt( '2.0.20' );
}
/**
* Returns true if the installed version of WooCommerce is 2.6 or greater
*
* @return boolean true if the installed version of WooCommerce is 2.1 or greater
* @since 1.0
*/
public static function is_wc_version_gte_2_6() {
return version_compare( self::get_wc_version(), '2.6.0', 'ge' );
}
/**
* Returns true if the installed version of WooCommerce is 2.6 or greater
*
* @return boolean true if the installed version of WooCommerce is 2.1 or greater
* @since 1.0
*/
public static function is_wc_version_gte_3_0() {
return version_compare( self::get_wc_version(), '3.0.0', 'ge' );
}
/**
* @param WC_Order_Item_Shipping $method
*
* @return string
*/
public static function get_method_id( $method ) {
$method_id = $method->get_method_id();
if ( empty( $method_id ) ) {
return '';
}
$method_exp = explode( ':', $method_id );
return $method_exp[0];
}
/**
* @param WC_Order_Item_Shipping $method
*
* @return string
*/
public static function get_instance_id( $method ) {
$method_id = $method->get_method_id();
if ( empty( $method_id ) ) {
return '';
}
$method_exp = explode( ':', $method_id );
if ( ! is_array( $method_exp ) ) {
return '';
}
if ( 2 === count( $method_exp ) ) {
return $method_exp[1];
}
if ( is_callable( array( $method, 'get_instance_id' ) ) ) {
return $method->get_instance_id();
}
return '';
}
/**
* Returns true if the installed version of WooCommerce is greater than $version
*
* @param string $version the version to compare
*
* @return boolean true if the installed version of WooCommerce is > $version
* @since 1.0
*
*/
public static function is_wc_version_gt( $version ) {
return self::get_wc_version() && version_compare( self::get_wc_version(), $version, '>' );
}
public static function display_prices_including_tax() {
if ( version_compare( self::get_wc_version(), '3.3.0', 'ge' ) ) {
return 'incl' === get_option( 'woocommerce_tax_display_cart' );
}
}
/**
* Get order meta, checking if HPOS enabled
*
* @param $order
* @param $key
*
* @return array|mixed|string|null
*/
public static function get_order_meta( $order, $key = '' ) {
if ( empty( $key ) ) {
return '';
}
if ( ! $order instanceof WC_Abstract_Order ) {
return '';
}
$meta_value = $order->get_meta( $key );
if ( ! empty( $meta_value ) ) {
return $meta_value;
}
global $wpdb;
if ( true === self::is_hpos_enabled() ) {
$meta_value = $wpdb->get_var( $wpdb->prepare( "SELECT `meta_value` FROM `{$wpdb->prefix}wc_orders_meta` WHERE `meta_key`=%s AND `order_id`=%d", $key, $order->get_id() ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
} else {
$meta_value = $wpdb->get_var( $wpdb->prepare( "SELECT `meta_value` FROM {$wpdb->postmeta} WHERE `post_id` = %d AND `meta_key` = %s ORDER BY `post_id` DESC LIMIT 1", $order->get_id(), $key ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
if ( ! empty( $meta_value ) ) {
return maybe_unserialize( $meta_value );
}
return $meta_value;
}
/**
* Checks if HPOS enabled
*
* @return bool
*/
public static function is_hpos_enabled() {
return function_exists( 'wc_get_container' ) && ( class_exists( '\Automattic\WooCommerce\Utilities\OrderUtil' ) && method_exists( '\Automattic\WooCommerce\Utilities\OrderUtil', 'custom_orders_table_usage_is_enabled' ) && \Automattic\WooCommerce\Utilities\OrderUtil::custom_orders_table_usage_is_enabled() );
}
}
endif; // Class exists check