2013-08-09 16:11:15 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* WooCommerce Core Functions
|
|
|
|
*
|
2013-09-03 12:03:05 +00:00
|
|
|
* General core functions available on both the front-end and admin.
|
2013-08-09 16:11:15 +00:00
|
|
|
*
|
|
|
|
* @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' );
|
2013-11-12 21:05:54 +00:00
|
|
|
include( 'wc-notice-functions.php' );
|
2013-08-09 16:11:15 +00:00
|
|
|
include( 'wc-order-functions.php' );
|
|
|
|
include( 'wc-page-functions.php' );
|
|
|
|
include( 'wc-product-functions.php' );
|
|
|
|
include( 'wc-term-functions.php' );
|
2013-09-12 13:41:02 +00:00
|
|
|
include( 'wc-attribute-functions.php' );
|
2013-08-09 16:11:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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()
|
|
|
|
|
2013-09-12 13:42:57 +00:00
|
|
|
/**
|
|
|
|
* Get template part (for templates like the shop-loop).
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param mixed $slug
|
|
|
|
* @param string $name (default: '')
|
|
|
|
* @return void
|
|
|
|
*/
|
2013-11-25 12:45:04 +00:00
|
|
|
function wc_get_template_part( $slug, $name = '' ) {
|
2013-09-12 13:42:57 +00:00
|
|
|
$template = '';
|
|
|
|
|
|
|
|
// Look in yourtheme/slug-name.php and yourtheme/woocommerce/slug-name.php
|
2014-02-01 14:58:56 +00:00
|
|
|
if ( $name ) {
|
|
|
|
$template = locate_template( array( "{$slug}-{$name}.php", WC()->template_path() . "{$slug}-{$name}.php" ) );
|
|
|
|
}
|
2013-09-12 13:42:57 +00:00
|
|
|
|
|
|
|
// Get default slug-name.php
|
2014-02-01 14:58:56 +00:00
|
|
|
if ( ! $template && $name && file_exists( WC()->plugin_path() . "/templates/{$slug}-{$name}.php" ) ) {
|
2013-09-12 13:42:57 +00:00
|
|
|
$template = WC()->plugin_path() . "/templates/{$slug}-{$name}.php";
|
2014-02-01 14:58:56 +00:00
|
|
|
}
|
2013-09-12 13:42:57 +00:00
|
|
|
|
|
|
|
// If template file doesn't exist, look in yourtheme/slug.php and yourtheme/woocommerce/slug.php
|
2014-02-01 14:58:56 +00:00
|
|
|
if ( ! $template ) {
|
|
|
|
$template = locate_template( array( "{$slug}.php", WC()->template_path() . "{$slug}.php" ) );
|
|
|
|
}
|
2013-09-12 13:42:57 +00:00
|
|
|
|
2014-01-16 07:46:48 +00:00
|
|
|
// Allow 3rd party plugin filter template file from their plugin
|
|
|
|
$template = apply_filters( 'wc_get_template_part', $template, $slug, $name );
|
2014-01-27 03:37:03 +00:00
|
|
|
|
2014-02-01 14:58:56 +00:00
|
|
|
if ( $template ) {
|
2013-09-12 13:42:57 +00:00
|
|
|
load_template( $template, false );
|
2014-02-01 14:58:56 +00:00
|
|
|
}
|
2013-09-12 13:42:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get other templates (e.g. product attributes) passing attributes and including the file.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param mixed $template_name
|
|
|
|
* @param array $args (default: array())
|
|
|
|
* @param string $template_path (default: '')
|
|
|
|
* @param string $default_path (default: '')
|
|
|
|
* @return void
|
|
|
|
*/
|
2013-11-25 12:45:04 +00:00
|
|
|
function wc_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
|
2014-02-01 14:58:56 +00:00
|
|
|
if ( $args && is_array( $args ) ) {
|
2013-09-12 13:42:57 +00:00
|
|
|
extract( $args );
|
2014-02-01 14:58:56 +00:00
|
|
|
}
|
2013-09-12 13:42:57 +00:00
|
|
|
|
2013-11-25 12:45:04 +00:00
|
|
|
$located = wc_locate_template( $template_name, $template_path, $default_path );
|
2013-09-12 13:42:57 +00:00
|
|
|
|
2014-02-11 14:48:28 +00:00
|
|
|
if ( ! file_exists( $located ) ) {
|
2014-02-13 09:25:24 +00:00
|
|
|
_doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' );
|
2014-02-11 14:48:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-12 13:42:57 +00:00
|
|
|
do_action( 'woocommerce_before_template_part', $template_name, $template_path, $located, $args );
|
|
|
|
|
|
|
|
include( $located );
|
|
|
|
|
|
|
|
do_action( 'woocommerce_after_template_part', $template_name, $template_path, $located, $args );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Locate a template and return the path for inclusion.
|
|
|
|
*
|
|
|
|
* This is the load order:
|
|
|
|
*
|
|
|
|
* yourtheme / $template_path / $template_name
|
|
|
|
* yourtheme / $template_name
|
|
|
|
* $default_path / $template_name
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param mixed $template_name
|
|
|
|
* @param string $template_path (default: '')
|
|
|
|
* @param string $default_path (default: '')
|
|
|
|
* @return string
|
|
|
|
*/
|
2013-11-25 12:45:04 +00:00
|
|
|
function wc_locate_template( $template_name, $template_path = '', $default_path = '' ) {
|
2014-02-01 14:58:56 +00:00
|
|
|
if ( ! $template_path ) {
|
|
|
|
$template_path = WC()->template_path();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! $default_path ) {
|
|
|
|
$default_path = WC()->plugin_path() . '/templates/';
|
|
|
|
}
|
2013-09-12 13:42:57 +00:00
|
|
|
|
|
|
|
// Look within passed path within the theme - this is priority
|
|
|
|
$template = locate_template(
|
|
|
|
array(
|
|
|
|
trailingslashit( $template_path ) . $template_name,
|
|
|
|
$template_name
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Get default template
|
2014-02-01 14:58:56 +00:00
|
|
|
if ( ! $template ) {
|
2013-09-12 13:42:57 +00:00
|
|
|
$template = $default_path . $template_name;
|
2014-02-01 14:58:56 +00:00
|
|
|
}
|
2013-09-12 13:42:57 +00:00
|
|
|
|
|
|
|
// Return what we found
|
|
|
|
return apply_filters('woocommerce_locate_template', $template, $template_name, $template_path);
|
|
|
|
}
|
|
|
|
|
2013-08-09 16:11:15 +00:00
|
|
|
/**
|
|
|
|
* 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(
|
2014-02-17 13:14:41 +00:00
|
|
|
'AED' => __( 'United Arab Emirates Dirham', 'woocommerce' ),
|
2013-08-09 16:11:15 +00:00
|
|
|
'AUD' => __( 'Australian Dollars', 'woocommerce' ),
|
2014-03-17 18:33:08 +00:00
|
|
|
'BDT' => __( 'Bangladeshi Taka', 'woocommerce' ),
|
2013-08-09 16:11:15 +00:00
|
|
|
'BRL' => __( 'Brazilian Real', 'woocommerce' ),
|
2013-08-21 07:29:44 +00:00
|
|
|
'BGN' => __( 'Bulgarian Lev', 'woocommerce' ),
|
2013-08-09 16:11:15 +00:00
|
|
|
'CAD' => __( 'Canadian Dollars', 'woocommerce' ),
|
2014-02-01 15:00:57 +00:00
|
|
|
'CLP' => __( 'Chilean Peso', 'woocommerce' ),
|
2013-08-09 16:11:15 +00:00
|
|
|
'CNY' => __( 'Chinese Yuan', 'woocommerce' ),
|
2014-01-31 18:16:56 +00:00
|
|
|
'COP' => __( 'Colombian Peso', 'woocommerce' ),
|
2013-08-09 16:11:15 +00:00
|
|
|
'CZK' => __( 'Czech Koruna', 'woocommerce' ),
|
|
|
|
'DKK' => __( 'Danish Krone', 'woocommerce' ),
|
|
|
|
'EUR' => __( 'Euros', 'woocommerce' ),
|
|
|
|
'HKD' => __( 'Hong Kong Dollar', 'woocommerce' ),
|
2014-02-09 19:31:03 +00:00
|
|
|
'HRK' => __( 'Croatia kuna', 'woocommerce' ),
|
2013-08-09 16:11:15 +00:00
|
|
|
'HUF' => __( 'Hungarian Forint', 'woocommerce' ),
|
2013-11-14 10:44:58 +00:00
|
|
|
'ISK' => __( 'Icelandic krona', 'woocommerce' ),
|
2013-08-09 16:11:15 +00:00
|
|
|
'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' ),
|
2014-01-19 19:55:29 +00:00
|
|
|
'NGN' => __( 'Nigerian Naira', 'woocommerce' ),
|
2013-08-09 16:11:15 +00:00
|
|
|
'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' ),
|
2013-08-21 17:24:51 +00:00
|
|
|
'VND' => __( 'Vietnamese Dong', 'woocommerce' ),
|
2013-08-09 16:11:15 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Currency symbol.
|
|
|
|
* @param string $currency (default: '')
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function get_woocommerce_currency_symbol( $currency = '' ) {
|
2014-02-01 14:58:56 +00:00
|
|
|
if ( ! $currency ) {
|
2013-08-09 16:11:15 +00:00
|
|
|
$currency = get_woocommerce_currency();
|
2014-02-01 14:58:56 +00:00
|
|
|
}
|
2013-08-09 16:11:15 +00:00
|
|
|
|
|
|
|
switch ( $currency ) {
|
2014-02-14 07:17:22 +00:00
|
|
|
case 'AED' :
|
2014-03-12 13:50:51 +00:00
|
|
|
$currency_symbol = 'د.إ';
|
2014-02-14 07:17:22 +00:00
|
|
|
break;
|
2014-03-17 18:33:08 +00:00
|
|
|
case 'BDT':
|
|
|
|
$currency_symbol = '৳ ';
|
|
|
|
break;
|
2013-08-09 16:11:15 +00:00
|
|
|
case 'BRL' :
|
|
|
|
$currency_symbol = 'R$';
|
|
|
|
break;
|
2013-08-21 07:29:44 +00:00
|
|
|
case 'BGN' :
|
|
|
|
$currency_symbol = 'лв.';
|
|
|
|
break;
|
2013-08-09 16:11:15 +00:00
|
|
|
case 'AUD' :
|
|
|
|
case 'CAD' :
|
2014-02-01 14:55:58 +00:00
|
|
|
case 'CLP' :
|
2013-08-09 16:11:15 +00:00
|
|
|
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;
|
2013-11-14 10:42:05 +00:00
|
|
|
case 'INR' : $currency_symbol = 'Rs.'; break;
|
2013-11-14 10:44:58 +00:00
|
|
|
case 'ISK' : $currency_symbol = 'Kr.'; break;
|
2013-08-09 16:11:15 +00:00
|
|
|
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;
|
2013-08-21 17:24:51 +00:00
|
|
|
case 'VND' : $currency_symbol = '₫'; break;
|
2014-01-19 19:55:29 +00:00
|
|
|
case 'NGN' : $currency_symbol = '₦'; break;
|
2013-08-09 16:11:15 +00:00
|
|
|
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: "")
|
|
|
|
*/
|
2013-11-25 12:45:04 +00:00
|
|
|
function wc_mail( $to, $subject, $message, $headers = "Content-Type: text/html\r\n", $attachments = "" ) {
|
2013-08-09 16:11:15 +00:00
|
|
|
global $woocommerce;
|
|
|
|
|
2013-11-25 14:01:32 +00:00
|
|
|
$mailer = WC()->mailer();
|
2013-08-09 16:11:15 +00:00
|
|
|
|
|
|
|
$mailer->send( $to, $subject, $message, $headers, $attachments );
|
2013-08-21 07:29:44 +00:00
|
|
|
}
|
2013-09-12 13:41:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get an image size.
|
|
|
|
*
|
|
|
|
* Variable is filtered by woocommerce_get_image_size_{image_size}
|
|
|
|
*
|
|
|
|
* @param string $image_size
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function wc_get_image_size( $image_size ) {
|
|
|
|
if ( in_array( $image_size, array( 'shop_thumbnail', 'shop_catalog', 'shop_single' ) ) ) {
|
|
|
|
$size = get_option( $image_size . '_image_size', array() );
|
|
|
|
$size['width'] = isset( $size['width'] ) ? $size['width'] : '300';
|
|
|
|
$size['height'] = isset( $size['height'] ) ? $size['height'] : '300';
|
|
|
|
$size['crop'] = isset( $size['crop'] ) ? $size['crop'] : 1;
|
|
|
|
} else {
|
|
|
|
$size = array(
|
|
|
|
'width' => '300',
|
|
|
|
'height' => '300',
|
|
|
|
'crop' => 1
|
|
|
|
);
|
|
|
|
}
|
2014-02-01 14:58:56 +00:00
|
|
|
|
2013-09-12 13:41:02 +00:00
|
|
|
return apply_filters( 'woocommerce_get_image_size_' . $image_size, $size );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Queue some JavaScript code to be output in the footer.
|
|
|
|
*
|
|
|
|
* @param string $code
|
|
|
|
*/
|
|
|
|
function wc_enqueue_js( $code ) {
|
|
|
|
global $wc_queued_js;
|
|
|
|
|
2014-02-01 14:58:56 +00:00
|
|
|
if ( empty( $wc_queued_js ) ) {
|
|
|
|
$wc_queued_js = '';
|
|
|
|
}
|
2013-09-12 13:41:02 +00:00
|
|
|
|
|
|
|
$wc_queued_js .= "\n" . $code . "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Output any queued javascript code in the footer.
|
|
|
|
*/
|
|
|
|
function wc_print_js() {
|
|
|
|
global $wc_queued_js;
|
|
|
|
|
|
|
|
if ( ! empty( $wc_queued_js ) ) {
|
|
|
|
|
2014-01-27 03:37:03 +00:00
|
|
|
echo "<!-- WooCommerce JavaScript -->\n<script type=\"text/javascript\">\njQuery(function($) {";
|
2013-09-12 13:41:02 +00:00
|
|
|
|
|
|
|
// Sanitize
|
|
|
|
$wc_queued_js = wp_check_invalid_utf8( $wc_queued_js );
|
|
|
|
$wc_queued_js = preg_replace( '/&#(x)?0*(?(1)27|39);?/i', "'", $wc_queued_js );
|
|
|
|
$wc_queued_js = str_replace( "\r", '', $wc_queued_js );
|
|
|
|
|
|
|
|
echo $wc_queued_js . "});\n</script>\n";
|
|
|
|
|
|
|
|
unset( $wc_queued_js );
|
|
|
|
}
|
2013-10-17 14:29:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a cookie - wrapper for setcookie using WP constants
|
2013-11-03 23:54:56 +00:00
|
|
|
*
|
2013-10-17 14:29:39 +00:00
|
|
|
* @param string $name Name of the cookie being set
|
|
|
|
* @param string $value Value of the cookie
|
|
|
|
* @param integer $expire Expiry of the cookie
|
2014-03-19 09:16:26 +00:00
|
|
|
* @param string $secure Whether the cookie should be served only over https
|
2013-10-17 14:29:39 +00:00
|
|
|
*/
|
2014-03-19 09:16:26 +00:00
|
|
|
function wc_setcookie( $name, $value, $expire = 0, $secure = false ) {
|
2013-10-17 14:29:39 +00:00
|
|
|
if ( ! headers_sent() ) {
|
2014-03-19 09:16:26 +00:00
|
|
|
setcookie( $name, $value, $expire, COOKIEPATH, COOKIE_DOMAIN, $secure );
|
2013-10-17 14:29:39 +00:00
|
|
|
} elseif ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
|
|
|
|
trigger_error( "Cookie cannot be set - headers already sent", E_USER_NOTICE );
|
|
|
|
}
|
2013-11-03 23:54:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-11-06 06:23:19 +00:00
|
|
|
* Get the URL to the WooCommerce REST API
|
2013-11-03 23:54:56 +00:00
|
|
|
*
|
2013-11-06 06:23:19 +00:00
|
|
|
* @since 2.1
|
|
|
|
* @param string $path an endpoint to include in the URL
|
|
|
|
* @return string the URL
|
2013-11-03 23:54:56 +00:00
|
|
|
*/
|
2013-11-06 06:23:19 +00:00
|
|
|
function get_woocommerce_api_url( $path ) {
|
2013-11-03 23:54:56 +00:00
|
|
|
|
2013-11-06 06:23:19 +00:00
|
|
|
$url = get_home_url( null, 'wc-api/v' . WC_API::VERSION . '/', ( 'yes' === get_option( 'woocommerce_force_ssl_checkout' ) ) ? 'https' : 'http' );
|
2013-11-03 23:54:56 +00:00
|
|
|
|
2014-02-01 14:58:56 +00:00
|
|
|
if ( ! empty( $path ) && is_string( $path ) ) {
|
2013-11-06 06:23:19 +00:00
|
|
|
$url .= ltrim( $path, '/' );
|
2014-02-01 14:58:56 +00:00
|
|
|
}
|
2013-11-03 23:54:56 +00:00
|
|
|
|
2013-11-06 06:23:19 +00:00
|
|
|
return $url;
|
2013-11-03 23:54:56 +00:00
|
|
|
}
|