171 lines
5.7 KiB
PHP
171 lines
5.7 KiB
PHP
|
<?php
|
||
|
/**
|
||
|
* WooCommerce Core Functions
|
||
|
*
|
||
|
* Genral core functions available on both the front-end and admin.
|
||
|
*
|
||
|
* @author WooThemes
|
||
|
* @category Core
|
||
|
* @package WooCommerce/Functions
|
||
|
* @version 2.1.0
|
||
|
*/
|
||
|
|
||
|
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||
|
|
||
|
// Include core functions
|
||
|
include( 'wc-cart-functions.php' );
|
||
|
include( 'wc-conditional-functions.php' );
|
||
|
include( 'wc-coupon-functions.php' );
|
||
|
include( 'wc-customer-functions.php' );
|
||
|
include( 'wc-deprecated-functions.php' );
|
||
|
include( 'wc-formatting-functions.php' );
|
||
|
include( 'wc-message-functions.php' );
|
||
|
include( 'wc-order-functions.php' );
|
||
|
include( 'wc-page-functions.php' );
|
||
|
include( 'wc-product-functions.php' );
|
||
|
include( 'wc-term-functions.php' );
|
||
|
|
||
|
/**
|
||
|
* Filters on data used in admin and frontend
|
||
|
*/
|
||
|
add_filter( 'woocommerce_coupon_code', 'sanitize_text_field' );
|
||
|
add_filter( 'woocommerce_coupon_code', 'strtolower' ); // Coupons case-insensitive by default
|
||
|
add_filter( 'woocommerce_stock_amount', 'intval' ); // Stock amounts are integers by default
|
||
|
|
||
|
/**
|
||
|
* Short Description (excerpt)
|
||
|
*/
|
||
|
add_filter( 'woocommerce_short_description', 'wptexturize' );
|
||
|
add_filter( 'woocommerce_short_description', 'convert_smilies' );
|
||
|
add_filter( 'woocommerce_short_description', 'convert_chars' );
|
||
|
add_filter( 'woocommerce_short_description', 'wpautop' );
|
||
|
add_filter( 'woocommerce_short_description', 'shortcode_unautop' );
|
||
|
add_filter( 'woocommerce_short_description', 'prepend_attachment' );
|
||
|
add_filter( 'woocommerce_short_description', 'do_shortcode', 11 ); // AFTER wpautop()
|
||
|
|
||
|
/**
|
||
|
* Get Base Currency Code.
|
||
|
* @return string
|
||
|
*/
|
||
|
function get_woocommerce_currency() {
|
||
|
return apply_filters( 'woocommerce_currency', get_option('woocommerce_currency') );
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Get full list of currency codes.
|
||
|
* @return array
|
||
|
*/
|
||
|
function get_woocommerce_currencies() {
|
||
|
return array_unique(
|
||
|
apply_filters( 'woocommerce_currencies',
|
||
|
array(
|
||
|
'AUD' => __( 'Australian Dollars', 'woocommerce' ),
|
||
|
'BRL' => __( 'Brazilian Real', 'woocommerce' ),
|
||
|
'CAD' => __( 'Canadian Dollars', 'woocommerce' ),
|
||
|
'CNY' => __( 'Chinese Yuan', 'woocommerce' ),
|
||
|
'CZK' => __( 'Czech Koruna', 'woocommerce' ),
|
||
|
'DKK' => __( 'Danish Krone', 'woocommerce' ),
|
||
|
'EUR' => __( 'Euros', 'woocommerce' ),
|
||
|
'HKD' => __( 'Hong Kong Dollar', 'woocommerce' ),
|
||
|
'HUF' => __( 'Hungarian Forint', 'woocommerce' ),
|
||
|
'IDR' => __( 'Indonesia Rupiah', 'woocommerce' ),
|
||
|
'INR' => __( 'Indian Rupee', 'woocommerce' ),
|
||
|
'ILS' => __( 'Israeli Shekel', 'woocommerce' ),
|
||
|
'JPY' => __( 'Japanese Yen', 'woocommerce' ),
|
||
|
'KRW' => __( 'South Korean Won', 'woocommerce' ),
|
||
|
'MYR' => __( 'Malaysian Ringgits', 'woocommerce' ),
|
||
|
'MXN' => __( 'Mexican Peso', 'woocommerce' ),
|
||
|
'NOK' => __( 'Norwegian Krone', 'woocommerce' ),
|
||
|
'NZD' => __( 'New Zealand Dollar', 'woocommerce' ),
|
||
|
'PHP' => __( 'Philippine Pesos', 'woocommerce' ),
|
||
|
'PLN' => __( 'Polish Zloty', 'woocommerce' ),
|
||
|
'GBP' => __( 'Pounds Sterling', 'woocommerce' ),
|
||
|
'RON' => __( 'Romanian Leu', 'woocommerce' ),
|
||
|
'RUB' => __( 'Russian Ruble', 'woocommerce' ),
|
||
|
'SGD' => __( 'Singapore Dollar', 'woocommerce' ),
|
||
|
'ZAR' => __( 'South African rand', 'woocommerce' ),
|
||
|
'SEK' => __( 'Swedish Krona', 'woocommerce' ),
|
||
|
'CHF' => __( 'Swiss Franc', 'woocommerce' ),
|
||
|
'TWD' => __( 'Taiwan New Dollars', 'woocommerce' ),
|
||
|
'THB' => __( 'Thai Baht', 'woocommerce' ),
|
||
|
'TRY' => __( 'Turkish Lira', 'woocommerce' ),
|
||
|
'USD' => __( 'US Dollars', 'woocommerce' ),
|
||
|
)
|
||
|
)
|
||
|
);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Get Currency symbol.
|
||
|
* @param string $currency (default: '')
|
||
|
* @return string
|
||
|
*/
|
||
|
function get_woocommerce_currency_symbol( $currency = '' ) {
|
||
|
if ( ! $currency )
|
||
|
$currency = get_woocommerce_currency();
|
||
|
|
||
|
switch ( $currency ) {
|
||
|
case 'BRL' :
|
||
|
$currency_symbol = 'R$';
|
||
|
break;
|
||
|
case 'AUD' :
|
||
|
case 'CAD' :
|
||
|
case 'MXN' :
|
||
|
case 'NZD' :
|
||
|
case 'HKD' :
|
||
|
case 'SGD' :
|
||
|
case 'USD' :
|
||
|
$currency_symbol = '$';
|
||
|
break;
|
||
|
case 'EUR' :
|
||
|
$currency_symbol = '€';
|
||
|
break;
|
||
|
case 'CNY' :
|
||
|
case 'RMB' :
|
||
|
case 'JPY' :
|
||
|
$currency_symbol = '¥';
|
||
|
break;
|
||
|
case 'RUB' :
|
||
|
$currency_symbol = 'руб.';
|
||
|
break;
|
||
|
case 'KRW' : $currency_symbol = '₩'; break;
|
||
|
case 'TRY' : $currency_symbol = 'TL'; break;
|
||
|
case 'NOK' : $currency_symbol = 'kr'; break;
|
||
|
case 'ZAR' : $currency_symbol = 'R'; break;
|
||
|
case 'CZK' : $currency_symbol = 'Kč'; break;
|
||
|
case 'MYR' : $currency_symbol = 'RM'; break;
|
||
|
case 'DKK' : $currency_symbol = 'kr'; break;
|
||
|
case 'HUF' : $currency_symbol = 'Ft'; break;
|
||
|
case 'IDR' : $currency_symbol = 'Rp'; break;
|
||
|
case 'INR' : $currency_symbol = 'Rs.'; break;
|
||
|
case 'ILS' : $currency_symbol = '₪'; break;
|
||
|
case 'PHP' : $currency_symbol = '₱'; break;
|
||
|
case 'PLN' : $currency_symbol = 'zł'; break;
|
||
|
case 'SEK' : $currency_symbol = 'kr'; break;
|
||
|
case 'CHF' : $currency_symbol = 'CHF'; break;
|
||
|
case 'TWD' : $currency_symbol = 'NT$'; break;
|
||
|
case 'THB' : $currency_symbol = '฿'; break;
|
||
|
case 'GBP' : $currency_symbol = '£'; break;
|
||
|
case 'RON' : $currency_symbol = 'lei'; break;
|
||
|
default : $currency_symbol = ''; break;
|
||
|
}
|
||
|
|
||
|
return apply_filters( 'woocommerce_currency_symbol', $currency_symbol, $currency );
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Send HTML emails from WooCommerce
|
||
|
*
|
||
|
* @param mixed $to
|
||
|
* @param mixed $subject
|
||
|
* @param mixed $message
|
||
|
* @param string $headers (default: "Content-Type: text/html\r\n")
|
||
|
* @param string $attachments (default: "")
|
||
|
*/
|
||
|
function woocommerce_mail( $to, $subject, $message, $headers = "Content-Type: text/html\r\n", $attachments = "" ) {
|
||
|
global $woocommerce;
|
||
|
|
||
|
$mailer = $woocommerce->mailer();
|
||
|
|
||
|
$mailer->send( $to, $subject, $message, $headers, $attachments );
|
||
|
}
|