Nuked whitespace. Closes #1846.

This commit is contained in:
Mike Jolley 2012-11-27 16:22:47 +00:00
parent 5124604710
commit b1ec4b289a
144 changed files with 3480 additions and 3480 deletions

View File

@ -14,7 +14,7 @@ register_importer( 'woocommerce_tax_rate_csv', __( 'WooCommerce Tax Rates (CSV)'
/** /**
* woocommerce_tax_rates_importer function. * woocommerce_tax_rates_importer function.
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -25,7 +25,7 @@ function woocommerce_tax_rates_importer() {
if ( ! class_exists( 'WP_Importer' ) ) { if ( ! class_exists( 'WP_Importer' ) ) {
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php'; $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
if ( file_exists( $class_wp_importer ) ) if ( file_exists( $class_wp_importer ) )
require $class_wp_importer; require $class_wp_importer;
} }

View File

@ -7,12 +7,12 @@
* @package WooCommerce/Admin/Importers * @package WooCommerce/Admin/Importers
* @version 1.7.0 * @version 1.7.0
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( class_exists( 'WP_Importer' ) ) { if ( class_exists( 'WP_Importer' ) ) {
class WC_CSV_Tax_Rates_Import extends WP_Importer { class WC_CSV_Tax_Rates_Import extends WP_Importer {
var $id; var $id;
var $file_url; var $file_url;
var $import_page; var $import_page;
@ -20,17 +20,17 @@ if ( class_exists( 'WP_Importer' ) ) {
var $posts = array(); var $posts = array();
var $imported; var $imported;
var $skipped; var $skipped;
/** /**
* __construct function. * __construct function.
* *
* @access public * @access public
* @return void * @return void
*/ */
public function __construct() { public function __construct() {
$this->import_page = 'woocommerce_tax_rate_csv'; $this->import_page = 'woocommerce_tax_rate_csv';
} }
/** /**
* Registered callback function for the WordPress Importer * Registered callback function for the WordPress Importer
* *
@ -38,13 +38,13 @@ if ( class_exists( 'WP_Importer' ) ) {
*/ */
function dispatch() { function dispatch() {
$this->header(); $this->header();
if ( ! empty( $_POST['delimiter'] ) ) if ( ! empty( $_POST['delimiter'] ) )
$this->delimiter = stripslashes( trim( $_POST['delimiter'] ) ); $this->delimiter = stripslashes( trim( $_POST['delimiter'] ) );
if ( ! $this->delimiter ) if ( ! $this->delimiter )
$this->delimiter = ','; $this->delimiter = ',';
$step = empty( $_GET['step'] ) ? 0 : (int) $_GET['step']; $step = empty( $_GET['step'] ) ? 0 : (int) $_GET['step'];
switch ( $step ) { switch ( $step ) {
case 0: case 0:
@ -58,26 +58,26 @@ if ( class_exists( 'WP_Importer' ) ) {
$file = get_attached_file( $this->id ); $file = get_attached_file( $this->id );
else else
$file = ABSPATH . $this->file_url; $file = ABSPATH . $this->file_url;
add_filter( 'http_request_timeout', array( &$this, 'bump_request_timeout' ) ); add_filter( 'http_request_timeout', array( &$this, 'bump_request_timeout' ) );
if ( function_exists( 'gc_enable' ) ) if ( function_exists( 'gc_enable' ) )
gc_enable(); gc_enable();
@set_time_limit(0); @set_time_limit(0);
@ob_flush(); @ob_flush();
@flush(); @flush();
$this->import( $file ); $this->import( $file );
} }
break; break;
} }
$this->footer(); $this->footer();
} }
/** /**
* format_data_from_csv function. * format_data_from_csv function.
* *
* @access public * @access public
* @param mixed $data * @param mixed $data
* @param mixed $enc * @param mixed $enc
@ -89,134 +89,134 @@ if ( class_exists( 'WP_Importer' ) ) {
/** /**
* import function. * import function.
* *
* @access public * @access public
* @param mixed $file * @param mixed $file
* @return void * @return void
*/ */
function import( $file ) { function import( $file ) {
global $woocommerce, $wpdb; global $woocommerce, $wpdb;
$this->imported = $this->skipped = 0; $this->imported = $this->skipped = 0;
if ( ! is_file($file) ) { if ( ! is_file($file) ) {
echo '<p><strong>' . __( 'Sorry, there has been an error.', 'woocommerce' ) . '</strong><br />'; echo '<p><strong>' . __( 'Sorry, there has been an error.', 'woocommerce' ) . '</strong><br />';
echo __( 'The file does not exist, please try again.', 'woocommerce' ) . '</p>'; echo __( 'The file does not exist, please try again.', 'woocommerce' ) . '</p>';
$this->footer(); $this->footer();
die(); die();
} }
$new_rates = array(); $new_rates = array();
if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ) { if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ) {
$header = fgetcsv( $handle, 0, $this->delimiter ); $header = fgetcsv( $handle, 0, $this->delimiter );
if ( sizeof( $header ) == 6 ) { if ( sizeof( $header ) == 6 ) {
$rates = get_option( 'woocommerce_tax_rates' ); $rates = get_option( 'woocommerce_tax_rates' );
while ( ( $row = fgetcsv( $handle, 0, $this->delimiter ) ) !== FALSE ) { while ( ( $row = fgetcsv( $handle, 0, $this->delimiter ) ) !== FALSE ) {
$rate = array(); $rate = array();
list( $rate['countries'], $rate['class'], $rate['label'], $rate['rate'], $rate['compound'], $rate['shipping'] ) = $row; list( $rate['countries'], $rate['class'], $rate['label'], $rate['rate'], $rate['compound'], $rate['shipping'] ) = $row;
$parsed_countries = array(); $parsed_countries = array();
$rate['countries'] = array_map( 'trim', explode( '|', $rate['countries'] ) ); $rate['countries'] = array_map( 'trim', explode( '|', $rate['countries'] ) );
foreach( $rate['countries'] as $country ) { foreach( $rate['countries'] as $country ) {
if ( strstr( $country, ':' ) ) { if ( strstr( $country, ':' ) ) {
list( $country, $state ) = array_map( 'trim', explode( ':', $country ) ); list( $country, $state ) = array_map( 'trim', explode( ':', $country ) );
if ( ! isset( $parsed_countries[ $country ] ) ) if ( ! isset( $parsed_countries[ $country ] ) )
$parsed_countries[ $country ] = array(); $parsed_countries[ $country ] = array();
$parsed_countries[ $country ][] = $state; $parsed_countries[ $country ][] = $state;
} else { } else {
if ( ! isset( $parsed_countries[ $country ] ) ) if ( ! isset( $parsed_countries[ $country ] ) )
$parsed_countries[ $country ] = array(); $parsed_countries[ $country ] = array();
$parsed_countries[ $country ][] = '*'; $parsed_countries[ $country ][] = '*';
} }
} }
$rate['countries'] = $parsed_countries; $rate['countries'] = $parsed_countries;
$rate['shipping'] = $rate['shipping'] ? 'yes' : 'no'; $rate['shipping'] = $rate['shipping'] ? 'yes' : 'no';
$rate['compound'] = $rate['compound'] ? 'yes' : 'no'; $rate['compound'] = $rate['compound'] ? 'yes' : 'no';
$new_rates[] = $rate; $new_rates[] = $rate;
unset( $rate, $row ); unset( $rate, $row );
$this->imported++; $this->imported++;
} }
$rates = array_merge( $rates, $new_rates ); $rates = array_merge( $rates, $new_rates );
update_option( 'woocommerce_tax_rates', $rates ); update_option( 'woocommerce_tax_rates', $rates );
} elseif ( sizeof( $header ) == 8 ) { } elseif ( sizeof( $header ) == 8 ) {
$rates = get_option( 'woocommerce_local_tax_rates' ); $rates = get_option( 'woocommerce_local_tax_rates' );
while ( ( $row = fgetcsv( $handle, 0, $this->delimiter ) ) !== FALSE ) { while ( ( $row = fgetcsv( $handle, 0, $this->delimiter ) ) !== FALSE ) {
$rate = array(); $rate = array();
list( $rate['country'], $rate['state'], $rate['postcode'], $rate['class'], $rate['label'], $rate['rate'], $rate['compound'], $rate['shipping'] ) = $row; list( $rate['country'], $rate['state'], $rate['postcode'], $rate['class'], $rate['label'], $rate['rate'], $rate['compound'], $rate['shipping'] ) = $row;
if ( ! $rate['country'] || ! $rate['postcode'] || ! $rate['rate'] ) { if ( ! $rate['country'] || ! $rate['postcode'] || ! $rate['rate'] ) {
$this->skipped++; $this->skipped++;
continue; continue;
} }
$rate['state'] = $rate['state'] ? $rate['state'] : '*'; $rate['state'] = $rate['state'] ? $rate['state'] : '*';
$rate['shipping'] = $rate['shipping'] ? 'yes' : 'no'; $rate['shipping'] = $rate['shipping'] ? 'yes' : 'no';
$rate['compound'] = $rate['compound'] ? 'yes' : 'no'; $rate['compound'] = $rate['compound'] ? 'yes' : 'no';
$rate['postcode'] = array_map( 'trim', explode( '|', $rate['postcode'] ) ); $rate['postcode'] = array_map( 'trim', explode( '|', $rate['postcode'] ) );
$new_rates[] = $rate; $new_rates[] = $rate;
unset( $rate, $row ); unset( $rate, $row );
$this->imported++; $this->imported++;
} }
$rates = array_merge( $rates, $new_rates ); $rates = array_merge( $rates, $new_rates );
update_option( 'woocommerce_local_tax_rates', $rates ); update_option( 'woocommerce_local_tax_rates', $rates );
} else { } else {
echo '<p><strong>' . __( 'Sorry, there has been an error.', 'woocommerce' ) . '</strong><br />'; echo '<p><strong>' . __( 'Sorry, there has been an error.', 'woocommerce' ) . '</strong><br />';
echo __( 'The CSV is invalid.', 'woocommerce' ) . '</p>'; echo __( 'The CSV is invalid.', 'woocommerce' ) . '</p>';
$this->footer(); $this->footer();
die(); die();
} }
fclose( $handle ); fclose( $handle );
} }
// Show Result // Show Result
echo '<div class="updated settings-error below-h2"><p> echo '<div class="updated settings-error below-h2"><p>
'.sprintf( __( 'Import complete - imported <strong>%s</strong> tax rates and skipped <strong>%s</strong>.', 'woocommerce' ), $this->imported, $this->skipped ).' '.sprintf( __( 'Import complete - imported <strong>%s</strong> tax rates and skipped <strong>%s</strong>.', 'woocommerce' ), $this->imported, $this->skipped ).'
</p></div>'; </p></div>';
$this->import_end(); $this->import_end();
} }
/** /**
* Performs post-import cleanup of files and the cache * Performs post-import cleanup of files and the cache
*/ */
function import_end() { function import_end() {
echo '<p>' . __( 'All done!', 'woocommerce' ) . ' <a href="' . admin_url('admin.php?page=woocommerce_settings&tab=tax') . '">' . __( 'View Tax Rates', 'woocommerce' ) . '</a>' . '</p>'; echo '<p>' . __( 'All done!', 'woocommerce' ) . ' <a href="' . admin_url('admin.php?page=woocommerce_settings&tab=tax') . '">' . __( 'View Tax Rates', 'woocommerce' ) . '</a>' . '</p>';
do_action( 'import_end' ); do_action( 'import_end' );
} }
/** /**
* Handles the CSV upload and initial parsing of the file to prepare for * Handles the CSV upload and initial parsing of the file to prepare for
* displaying author import options * displaying author import options
@ -224,40 +224,40 @@ if ( class_exists( 'WP_Importer' ) ) {
* @return bool False if error uploading or invalid file, true otherwise * @return bool False if error uploading or invalid file, true otherwise
*/ */
function handle_upload() { function handle_upload() {
if ( empty( $_POST['file_url'] ) ) { if ( empty( $_POST['file_url'] ) ) {
$file = wp_import_handle_upload(); $file = wp_import_handle_upload();
if ( isset( $file['error'] ) ) { if ( isset( $file['error'] ) ) {
echo '<p><strong>' . __( 'Sorry, there has been an error.', 'woocommerce' ) . '</strong><br />'; echo '<p><strong>' . __( 'Sorry, there has been an error.', 'woocommerce' ) . '</strong><br />';
echo esc_html( $file['error'] ) . '</p>'; echo esc_html( $file['error'] ) . '</p>';
return false; return false;
} }
$this->id = (int) $file['id']; $this->id = (int) $file['id'];
} else { } else {
if ( file_exists( ABSPATH . $_POST['file_url'] ) ) { if ( file_exists( ABSPATH . $_POST['file_url'] ) ) {
$this->file_url = esc_attr( $_POST['file_url'] ); $this->file_url = esc_attr( $_POST['file_url'] );
} else { } else {
echo '<p><strong>' . __( 'Sorry, there has been an error.', 'woocommerce' ) . '</strong></p>'; echo '<p><strong>' . __( 'Sorry, there has been an error.', 'woocommerce' ) . '</strong></p>';
return false; return false;
} }
} }
return true; return true;
} }
/** /**
* header function. * header function.
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -268,32 +268,32 @@ if ( class_exists( 'WP_Importer' ) ) {
/** /**
* footer function. * footer function.
* *
* @access public * @access public
* @return void * @return void
*/ */
function footer() { function footer() {
echo '</div>'; echo '</div>';
} }
/** /**
* greet function. * greet function.
* *
* @access public * @access public
* @return void * @return void
*/ */
function greet() { function greet() {
global $woocommerce; global $woocommerce;
echo '<div class="narrow">'; echo '<div class="narrow">';
echo '<p>' . __( 'Hi there! Upload a CSV file containing tax rates to import the contents into your shop. Choose a .csv file to upload, then click "Upload file and import".', 'woocommerce' ).'</p>'; echo '<p>' . __( 'Hi there! Upload a CSV file containing tax rates to import the contents into your shop. Choose a .csv file to upload, then click "Upload file and import".', 'woocommerce' ).'</p>';
echo '<p>' . sprintf( __( 'Tax rates need to be defined with columns in a specific order (6 columns). <a href="%s">Click here to download a sample</a>.', 'woocommerce' ), $woocommerce->plugin_url() . '/admin/importers/samples/sample_tax_rates.csv' ) . '</p>'; echo '<p>' . sprintf( __( 'Tax rates need to be defined with columns in a specific order (6 columns). <a href="%s">Click here to download a sample</a>.', 'woocommerce' ), $woocommerce->plugin_url() . '/admin/importers/samples/sample_tax_rates.csv' ) . '</p>';
echo '<p>' . sprintf( __( 'Local tax rates also need to be defined with columns in a specific order (8 columns). <a href="%s">Click here to download a sample</a>.', 'woocommerce' ), $woocommerce->plugin_url() . '/admin/importers/samples/sample_local_tax_rates.csv' ) . '</p>'; echo '<p>' . sprintf( __( 'Local tax rates also need to be defined with columns in a specific order (8 columns). <a href="%s">Click here to download a sample</a>.', 'woocommerce' ), $woocommerce->plugin_url() . '/admin/importers/samples/sample_local_tax_rates.csv' ) . '</p>';
$action = 'admin.php?import=woocommerce_tax_rate_csv&step=1'; $action = 'admin.php?import=woocommerce_tax_rate_csv&step=1';
$bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() ); $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
$size = wp_convert_bytes_to_hr( $bytes ); $size = wp_convert_bytes_to_hr( $bytes );
$upload_dir = wp_upload_dir(); $upload_dir = wp_upload_dir();
@ -336,10 +336,10 @@ if ( class_exists( 'WP_Importer' ) ) {
</form> </form>
<?php <?php
endif; endif;
echo '</div>'; echo '</div>';
} }
/** /**
* Added to http_request_timeout filter to force timeout at 60 seconds during import * Added to http_request_timeout filter to force timeout at 60 seconds during import
* @return int 60 * @return int 60

File diff suppressed because it is too large Load Diff

View File

@ -10,23 +10,23 @@
* @package WooCommerce/Classes * @package WooCommerce/Classes
* @author WooThemes * @author WooThemes
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class WC_CSV_Exporter { class WC_CSV_Exporter {
/** /**
* @var mixed * @var mixed
* @access private * @access private
*/ */
private $_csv = ''; private $_csv = '';
/** /**
* @var string * @var string
* @access private * @access private
*/ */
private $_filename = ''; private $_filename = '';
/** /**
* @var string * @var string
* @access private * @access private
@ -35,80 +35,80 @@ class WC_CSV_Exporter {
/** /**
* __construct function. * __construct function.
* *
* @access public * @access public
* @param bool $output (default: true) * @param bool $output (default: true)
* @param mixed $filename * @param mixed $filename
* @return void * @return void
*/ */
function __construct( $columns = array(), $output = true, $filename = '' ) { function __construct( $columns = array(), $output = true, $filename = '' ) {
$this->_csv = ''; $this->_csv = '';
$this->_filename = $filename ? $filename : 'export.csv'; $this->_filename = $filename ? $filename : 'export.csv';
if ( $this->_output = $output ) if ( $this->_output = $output )
$this->start(); $this->start();
if ( $columns ) if ( $columns )
$this->set_columns( $columns ); $this->set_columns( $columns );
} }
function set_filename( $filename ) { function set_filename( $filename ) {
$this->_filename = $filename ? $filename : 'export.csv'; $this->_filename = $filename ? $filename : 'export.csv';
} }
/** /**
* set_columns function. * set_columns function.
* *
* @access public * @access public
* @return void * @return void
*/ */
function set_columns( $columns = array() ) { function set_columns( $columns = array() ) {
$this->add_row( $columns ); $this->add_row( $columns );
unset( $columns ); unset( $columns );
} }
/** /**
* add_row function. * add_row function.
* *
* @access public * @access public
* @return void * @return void
*/ */
function add_row( $row ) { function add_row( $row ) {
$row = implode( ',', array_map( array( &$this, 'wrap_column' ), $row ) ) . "\n"; $row = implode( ',', array_map( array( &$this, 'wrap_column' ), $row ) ) . "\n";
if ( $this->_output ) if ( $this->_output )
fwrite( $this->_csv, $row ); fwrite( $this->_csv, $row );
else else
$this->_csv += $row; $this->_csv += $row;
unset( $row ); unset( $row );
} }
/** /**
* start function. * start function.
* *
* @access public * @access public
* @return void * @return void
*/ */
function start() { function start() {
if ( headers_sent() ) if ( headers_sent() )
wp_die( 'Headers already sent' ); wp_die( 'Headers already sent' );
@set_time_limit(0); @set_time_limit(0);
@ob_clean(); @ob_clean();
header( "Content-Type: text/csv; charset=UTF-8" ); header( "Content-Type: text/csv; charset=UTF-8" );
header( "Content-Disposition: attachment; filename={$this->_filename}" ); header( "Content-Disposition: attachment; filename={$this->_filename}" );
header( "Pragma: no-cache" ); header( "Pragma: no-cache" );
header( "Expires: 0" ); header( "Expires: 0" );
$this->_csv = fopen( 'php://output', 'w') ; $this->_csv = fopen( 'php://output', 'w') ;
} }
/** /**
* end function. * end function.
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -116,10 +116,10 @@ class WC_CSV_Exporter {
fclose( $this->_csv ); fclose( $this->_csv );
exit; exit;
} }
/** /**
* wrap_column function. * wrap_column function.
* *
* @access public * @access public
* @param mixed $data * @param mixed $data
* @return void * @return void
@ -127,5 +127,5 @@ class WC_CSV_Exporter {
function wrap_column( $data ) { function wrap_column( $data ) {
return '"' . str_replace( '"', '""', $data ) . '"'; return '"' . str_replace( '"', '""', $data ) . '"';
} }
} }

View File

@ -1,5 +1,5 @@
<?php <?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
?> ?>
<div id="message" class="updated woocommerce-message wc-connect"> <div id="message" class="updated woocommerce-message wc-connect">
<div class="squeezer"> <div class="squeezer">

View File

@ -1,5 +1,5 @@
<?php <?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
?> ?>
<div id="message" class="updated woocommerce-message wc-connect"> <div id="message" class="updated woocommerce-message wc-connect">
<div class="squeezer"> <div class="squeezer">

View File

@ -1,5 +1,5 @@
<?php <?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
?> ?>
<div id="message" class="updated woocommerce-message wc-connect"> <div id="message" class="updated woocommerce-message wc-connect">
<div class="squeezer"> <div class="squeezer">

View File

@ -1,5 +1,5 @@
<?php <?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
?> ?>
<div id="message" class="updated woocommerce-message wc-connect"> <div id="message" class="updated woocommerce-message wc-connect">
<div class="squeezer"> <div class="squeezer">

View File

@ -16,21 +16,21 @@ global $wpdb, $woocommerce;
$existing_file_paths = $wpdb->get_results( "SELECT * FROM ". $wpdb->postmeta . " WHERE meta_key = '_file_path'" ); $existing_file_paths = $wpdb->get_results( "SELECT * FROM ". $wpdb->postmeta . " WHERE meta_key = '_file_path'" );
if ( $existing_file_paths ) { if ( $existing_file_paths ) {
foreach( $existing_file_paths as $existing_file_path ) { foreach( $existing_file_paths as $existing_file_path ) {
$existing_file_path->meta_value = trim( $existing_file_path->meta_value ); $existing_file_path->meta_value = trim( $existing_file_path->meta_value );
if ( $existing_file_path->meta_value ) if ( $existing_file_path->meta_value )
$file_paths = maybe_serialize( array( md5( $existing_file_path->meta_value ) => $existing_file_path->meta_value ) ); $file_paths = maybe_serialize( array( md5( $existing_file_path->meta_value ) => $existing_file_path->meta_value ) );
else else
$file_paths = ''; $file_paths = '';
$wpdb->query( $wpdb->prepare( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_file_paths', meta_value = %s WHERE meta_id = %d", $file_paths, $existing_file_path->meta_id ) ); $wpdb->query( $wpdb->prepare( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_file_paths', meta_value = %s WHERE meta_id = %d", $file_paths, $existing_file_path->meta_id ) );
$wpdb->query( $wpdb->prepare( "UPDATE " . $wpdb->prefix . "woocommerce_downloadable_product_permissions SET download_id = %s WHERE product_id = %d", md5( $existing_file_path->meta_value ), $existing_file_path->post_id ) ); $wpdb->query( $wpdb->prepare( "UPDATE " . $wpdb->prefix . "woocommerce_downloadable_product_permissions SET download_id = %s WHERE product_id = %d", md5( $existing_file_path->meta_value ), $existing_file_path->post_id ) );
} }
} }
// Update table primary keys // Update table primary keys
@ -45,11 +45,11 @@ $shop_page_id = woocommerce_get_page_id( 'shop' );
if ( empty( $permalinks ) && $shop_page_id > 0 ) { if ( empty( $permalinks ) && $shop_page_id > 0 ) {
$base_slug = $shop_page_id > 0 && get_page( $shop_page_id ) ? get_page_uri( $shop_page_id ) : 'shop'; $base_slug = $shop_page_id > 0 && get_page( $shop_page_id ) ? get_page_uri( $shop_page_id ) : 'shop';
$category_base = get_option('woocommerce_prepend_shop_page_to_urls') == "yes" ? trailingslashit( $base_slug ) : ''; $category_base = get_option('woocommerce_prepend_shop_page_to_urls') == "yes" ? trailingslashit( $base_slug ) : '';
$category_slug = get_option('woocommerce_product_category_slug') ? get_option('woocommerce_product_category_slug') : _x( 'product-category', 'slug', 'woocommerce' ); $category_slug = get_option('woocommerce_product_category_slug') ? get_option('woocommerce_product_category_slug') : _x( 'product-category', 'slug', 'woocommerce' );
$tag_slug = get_option('woocommerce_product_tag_slug') ? get_option('woocommerce_product_tag_slug') : _x( 'product-tag', 'slug', 'woocommerce' ); $tag_slug = get_option('woocommerce_product_tag_slug') ? get_option('woocommerce_product_tag_slug') : _x( 'product-tag', 'slug', 'woocommerce' );
if ( 'yes' == get_option('woocommerce_prepend_shop_page_to_products') ) { if ( 'yes' == get_option('woocommerce_prepend_shop_page_to_products') ) {
$product_base = trailingslashit( $base_slug ); $product_base = trailingslashit( $base_slug );
} else { } else {
@ -59,8 +59,8 @@ if ( empty( $permalinks ) && $shop_page_id > 0 ) {
$product_base = trailingslashit( _x('product', 'slug', 'woocommerce') ); $product_base = trailingslashit( _x('product', 'slug', 'woocommerce') );
} }
} }
if ( get_option('woocommerce_prepend_category_to_products') == 'yes' ) if ( get_option('woocommerce_prepend_category_to_products') == 'yes' )
$product_base .= trailingslashit('%product_cat%'); $product_base .= trailingslashit('%product_cat%');
$permalinks = array( $permalinks = array(
@ -69,8 +69,8 @@ if ( empty( $permalinks ) && $shop_page_id > 0 ) {
'attribute_base' => untrailingslashit( $category_base ), 'attribute_base' => untrailingslashit( $category_base ),
'tag_base' => untrailingslashit( $category_base . $tag_slug ) 'tag_base' => untrailingslashit( $category_base . $tag_slug )
); );
update_option( 'woocommerce_permalinks', $permalinks ); update_option( 'woocommerce_permalinks', $permalinks );
} }
// Update subcat display settings // Update subcat display settings
@ -98,28 +98,28 @@ $order_item_rows = $wpdb->get_results( "
" ); " );
foreach ( $order_item_rows as $order_item_row ) { foreach ( $order_item_rows as $order_item_row ) {
$order_items = (array) maybe_unserialize( $order_item_row->meta_value ); $order_items = (array) maybe_unserialize( $order_item_row->meta_value );
foreach ( $order_items as $order_item ) { foreach ( $order_items as $order_item ) {
if ( ! isset( $order_item['line_total'] ) && isset( $order_item['taxrate'] ) && isset( $order_item['cost'] ) ) { if ( ! isset( $order_item['line_total'] ) && isset( $order_item['taxrate'] ) && isset( $order_item['cost'] ) ) {
$order_item['line_tax'] = number_format( ( $order_item['cost'] * $order_item['qty'] ) * ( $order_item['taxrate'] / 100 ), 2, '.', '' ); $order_item['line_tax'] = number_format( ( $order_item['cost'] * $order_item['qty'] ) * ( $order_item['taxrate'] / 100 ), 2, '.', '' );
$order_item['line_total'] = $order_item['cost'] * $order_item['qty']; $order_item['line_total'] = $order_item['cost'] * $order_item['qty'];
$order_item['line_subtotal_tax'] = $order_item['line_tax']; $order_item['line_subtotal_tax'] = $order_item['line_tax'];
$order_item['line_subtotal'] = $order_item['line_total']; $order_item['line_subtotal'] = $order_item['line_total'];
} }
$order_item['line_tax'] = isset( $order_item['line_tax'] ) ? $order_item['line_tax'] : 0; $order_item['line_tax'] = isset( $order_item['line_tax'] ) ? $order_item['line_tax'] : 0;
$order_item['line_total'] = isset( $order_item['line_total'] ) ? $order_item['line_total'] : 0; $order_item['line_total'] = isset( $order_item['line_total'] ) ? $order_item['line_total'] : 0;
$order_item['line_subtotal_tax'] = isset( $order_item['line_subtotal_tax'] ) ? $order_item['line_subtotal_tax'] : 0; $order_item['line_subtotal_tax'] = isset( $order_item['line_subtotal_tax'] ) ? $order_item['line_subtotal_tax'] : 0;
$order_item['line_subtotal'] = isset( $order_item['line_subtotal'] ) ? $order_item['line_subtotal'] : 0; $order_item['line_subtotal'] = isset( $order_item['line_subtotal'] ) ? $order_item['line_subtotal'] : 0;
$item_id = woocommerce_add_order_item( $order_item_row->post_id, array( $item_id = woocommerce_add_order_item( $order_item_row->post_id, array(
'order_item_name' => $order_item['name'], 'order_item_name' => $order_item['name'],
'order_item_type' => 'line_item' 'order_item_type' => 'line_item'
) ); ) );
// Add line item meta // Add line item meta
if ( $item_id ) { if ( $item_id ) {
woocommerce_add_order_item_meta( $item_id, '_qty', absint( $order_item['qty'] ) ); woocommerce_add_order_item_meta( $item_id, '_qty', absint( $order_item['qty'] ) );
@ -130,9 +130,9 @@ foreach ( $order_item_rows as $order_item_row ) {
woocommerce_add_order_item_meta( $item_id, '_line_subtotal_tax', woocommerce_format_decimal( $order_item['line_subtotal_tax'] ) ); woocommerce_add_order_item_meta( $item_id, '_line_subtotal_tax', woocommerce_format_decimal( $order_item['line_subtotal_tax'] ) );
woocommerce_add_order_item_meta( $item_id, '_line_total', woocommerce_format_decimal( $order_item['line_total'] ) ); woocommerce_add_order_item_meta( $item_id, '_line_total', woocommerce_format_decimal( $order_item['line_total'] ) );
woocommerce_add_order_item_meta( $item_id, '_line_tax', woocommerce_format_decimal( $order_item['line_tax'] ) ); woocommerce_add_order_item_meta( $item_id, '_line_tax', woocommerce_format_decimal( $order_item['line_tax'] ) );
$meta_rows = array(); $meta_rows = array();
// Insert meta // Insert meta
if ( ! empty( $order_item['item_meta'] ) ) { if ( ! empty( $order_item['item_meta'] ) ) {
foreach ( $order_item['item_meta'] as $key => $meta ) { foreach ( $order_item['item_meta'] as $key => $meta ) {
@ -144,7 +144,7 @@ foreach ( $order_item_rows as $order_item_row ) {
} }
} }
} }
// Insert meta rows at once // Insert meta rows at once
if ( sizeof( $meta_rows ) > 0 ) { if ( sizeof( $meta_rows ) > 0 ) {
$wpdb->query( $wpdb->prepare( " $wpdb->query( $wpdb->prepare( "
@ -152,7 +152,7 @@ foreach ( $order_item_rows as $order_item_row ) {
VALUES " . implode( ',', $meta_rows ) . "; VALUES " . implode( ',', $meta_rows ) . ";
", $order_item_row->post_id ) ); ", $order_item_row->post_id ) );
} }
// Delete from DB (rename) // Delete from DB (rename)
$wpdb->query( $wpdb->prepare( " $wpdb->query( $wpdb->prepare( "
UPDATE {$wpdb->postmeta} UPDATE {$wpdb->postmeta}
@ -161,7 +161,7 @@ foreach ( $order_item_rows as $order_item_row ) {
AND post_id = %d AND post_id = %d
", $order_item_row->post_id ) ); ", $order_item_row->post_id ) );
} }
unset( $meta_rows, $item_id, $order_item ); unset( $meta_rows, $item_id, $order_item );
} }
} }
@ -174,27 +174,27 @@ $order_tax_rows = $wpdb->get_results( "
" ); " );
foreach ( $order_tax_rows as $order_tax_row ) { foreach ( $order_tax_rows as $order_tax_row ) {
$order_taxes = (array) maybe_unserialize( $order_tax_row->meta_value ); $order_taxes = (array) maybe_unserialize( $order_tax_row->meta_value );
if ( $order_taxes ) { if ( $order_taxes ) {
foreach( $order_taxes as $order_tax ) { foreach( $order_taxes as $order_tax ) {
if ( ! isset( $order_tax['label'] ) || ! isset( $order_tax['cart_tax'] ) || ! isset( $order_tax['shipping_tax'] ) ) if ( ! isset( $order_tax['label'] ) || ! isset( $order_tax['cart_tax'] ) || ! isset( $order_tax['shipping_tax'] ) )
continue; continue;
$item_id = woocommerce_add_order_item( $order_tax_row->post_id, array( $item_id = woocommerce_add_order_item( $order_tax_row->post_id, array(
'order_item_name' => $order_tax['label'], 'order_item_name' => $order_tax['label'],
'order_item_type' => 'tax' 'order_item_type' => 'tax'
) ); ) );
// Add line item meta // Add line item meta
if ( $item_id ) { if ( $item_id ) {
woocommerce_add_order_item_meta( $item_id, 'compound', absint( isset( $order_tax['compound'] ) ? $order_tax['compound'] : 0 ) ); woocommerce_add_order_item_meta( $item_id, 'compound', absint( isset( $order_tax['compound'] ) ? $order_tax['compound'] : 0 ) );
woocommerce_add_order_item_meta( $item_id, 'tax_amount', woocommerce_clean( $order_tax['cart_tax'] ) ); woocommerce_add_order_item_meta( $item_id, 'tax_amount', woocommerce_clean( $order_tax['cart_tax'] ) );
woocommerce_add_order_item_meta( $item_id, 'shipping_tax_amount', woocommerce_clean( $order_tax['shipping_tax'] ) ); woocommerce_add_order_item_meta( $item_id, 'shipping_tax_amount', woocommerce_clean( $order_tax['shipping_tax'] ) );
} }
// Delete from DB (rename) // Delete from DB (rename)
$wpdb->query( $wpdb->prepare( " $wpdb->query( $wpdb->prepare( "
UPDATE {$wpdb->postmeta} UPDATE {$wpdb->postmeta}
@ -202,7 +202,7 @@ foreach ( $order_tax_rows as $order_tax_row ) {
WHERE meta_key = '_order_taxes' WHERE meta_key = '_order_taxes'
AND post_id = %d AND post_id = %d
", $order_tax_row->post_id ) ); ", $order_tax_row->post_id ) );
unset( $tax_amount ); unset( $tax_amount );
} }
} }

View File

@ -78,7 +78,7 @@ function woocommerce_edit_product_columns( $columns ) {
if ( empty( $columns ) && ! is_array( $columns ) ) if ( empty( $columns ) && ! is_array( $columns ) )
$columns = array(); $columns = array();
unset( $columns['title'], $columns['comments'], $columns['date'] ); unset( $columns['title'], $columns['comments'], $columns['date'] );
$columns["cb"] = "<input type=\"checkbox\" />"; $columns["cb"] = "<input type=\"checkbox\" />";
@ -1010,34 +1010,34 @@ function woocommerce_admin_product_bulk_edit_save( $post_id, $post ) {
update_post_meta( $post_id, '_weight', esc_html( stripslashes( $_REQUEST['_weight'] ) ) ); update_post_meta( $post_id, '_weight', esc_html( stripslashes( $_REQUEST['_weight'] ) ) );
if ( ! empty( $_REQUEST['change_dimensions'] ) ) { if ( ! empty( $_REQUEST['change_dimensions'] ) ) {
if ( isset( $_REQUEST['_length'] ) ) if ( isset( $_REQUEST['_length'] ) )
update_post_meta( $post_id, '_length', esc_html( stripslashes( $_REQUEST['_length'] ) ) ); update_post_meta( $post_id, '_length', esc_html( stripslashes( $_REQUEST['_length'] ) ) );
if ( isset( $_REQUEST['_width'] ) ) if ( isset( $_REQUEST['_width'] ) )
update_post_meta( $post_id, '_width', esc_html( stripslashes( $_REQUEST['_width'] ) ) ); update_post_meta( $post_id, '_width', esc_html( stripslashes( $_REQUEST['_width'] ) ) );
if ( isset( $_REQUEST['_height'] ) ) if ( isset( $_REQUEST['_height'] ) )
update_post_meta( $post_id, '_height', esc_html( stripslashes( $_REQUEST['_height'] ) ) ); update_post_meta( $post_id, '_height', esc_html( stripslashes( $_REQUEST['_height'] ) ) );
} }
if ( ! empty( $_REQUEST['_stock_status'] ) ) if ( ! empty( $_REQUEST['_stock_status'] ) )
update_post_meta( $post_id, '_stock_status', stripslashes( $_REQUEST['_stock_status'] ) ); update_post_meta( $post_id, '_stock_status', stripslashes( $_REQUEST['_stock_status'] ) );
if ( ! empty( $_REQUEST['_visibility'] ) ) if ( ! empty( $_REQUEST['_visibility'] ) )
update_post_meta( $post_id, '_visibility', stripslashes( $_REQUEST['_visibility'] ) ); update_post_meta( $post_id, '_visibility', stripslashes( $_REQUEST['_visibility'] ) );
if ( ! empty( $_REQUEST['_featured'] ) ) if ( ! empty( $_REQUEST['_featured'] ) )
update_post_meta( $post_id, '_featured', stripslashes( $_REQUEST['_featured'] ) ); update_post_meta( $post_id, '_featured', stripslashes( $_REQUEST['_featured'] ) );
// Handle price - remove dates and set to lowest // Handle price - remove dates and set to lowest
if ( $product->is_type( 'simple' ) || $product->is_type( 'external' ) ) { if ( $product->is_type( 'simple' ) || $product->is_type( 'external' ) ) {
$price_changed = false; $price_changed = false;
if ( ! empty( $_REQUEST['change_regular_price'] ) ) { if ( ! empty( $_REQUEST['change_regular_price'] ) ) {
$old_price = $product->regular_price; $old_price = $product->regular_price;
$change_regular_price = absint( $_REQUEST['change_regular_price'] ); $change_regular_price = absint( $_REQUEST['change_regular_price'] );
$regular_price = esc_attr( stripslashes( $_REQUEST['_regular_price'] ) ); $regular_price = esc_attr( stripslashes( $_REQUEST['_regular_price'] ) );
switch ( $change_regular_price ) { switch ( $change_regular_price ) {
case 1 : case 1 :
$new_price = $regular_price; $new_price = $regular_price;
@ -1050,7 +1050,7 @@ function woocommerce_admin_product_bulk_edit_save( $post_id, $post ) {
$new_price = $old_price + $regular_price; $new_price = $old_price + $regular_price;
} }
break; break;
case 3 : case 3 :
if ( strstr( $regular_price, '%' ) ) { if ( strstr( $regular_price, '%' ) ) {
$percent = str_replace( '%', '', $regular_price ) / 100; $percent = str_replace( '%', '', $regular_price ) / 100;
$new_price = $old_price - ( $old_price * $percent ); $new_price = $old_price - ( $old_price * $percent );
@ -1059,20 +1059,20 @@ function woocommerce_admin_product_bulk_edit_save( $post_id, $post ) {
} }
break; break;
} }
if ( isset( $new_price ) && $new_price != $product->regular_price ) { if ( isset( $new_price ) && $new_price != $product->regular_price ) {
$price_changed = true; $price_changed = true;
update_post_meta( $post_id, '_regular_price', $new_price ); update_post_meta( $post_id, '_regular_price', $new_price );
$product->regular_price = $new_price; $product->regular_price = $new_price;
} }
} }
if ( ! empty( $_REQUEST['change_sale_price'] ) ) { if ( ! empty( $_REQUEST['change_sale_price'] ) ) {
$old_price = $product->sale_price; $old_price = $product->sale_price;
$change_sale_price = absint( $_REQUEST['change_sale_price'] ); $change_sale_price = absint( $_REQUEST['change_sale_price'] );
$sale_price = esc_attr( stripslashes( $_REQUEST['_sale_price'] ) ); $sale_price = esc_attr( stripslashes( $_REQUEST['_sale_price'] ) );
switch ( $change_sale_price ) { switch ( $change_sale_price ) {
case 1 : case 1 :
$new_price = $sale_price; $new_price = $sale_price;
@ -1085,7 +1085,7 @@ function woocommerce_admin_product_bulk_edit_save( $post_id, $post ) {
$new_price = $old_price + $sale_price; $new_price = $old_price + $sale_price;
} }
break; break;
case 3 : case 3 :
if ( strstr( $sale_price, '%' ) ) { if ( strstr( $sale_price, '%' ) ) {
$percent = str_replace( '%', '', $sale_price ) / 100; $percent = str_replace( '%', '', $sale_price ) / 100;
$new_price = $old_price - ( $old_price * $percent ); $new_price = $old_price - ( $old_price * $percent );
@ -1093,7 +1093,7 @@ function woocommerce_admin_product_bulk_edit_save( $post_id, $post ) {
$new_price = $old_price - $sale_price; $new_price = $old_price - $sale_price;
} }
break; break;
case 4 : case 4 :
if ( strstr( $sale_price, '%' ) ) { if ( strstr( $sale_price, '%' ) ) {
$percent = str_replace( '%', '', $sale_price ) / 100; $percent = str_replace( '%', '', $sale_price ) / 100;
$new_price = $product->regular_price - ( $product->regular_price * $percent ); $new_price = $product->regular_price - ( $product->regular_price * $percent );
@ -1102,18 +1102,18 @@ function woocommerce_admin_product_bulk_edit_save( $post_id, $post ) {
} }
break; break;
} }
if ( isset( $new_price ) && $new_price != $product->sale_price ) { if ( isset( $new_price ) && $new_price != $product->sale_price ) {
$price_changed = true; $price_changed = true;
update_post_meta( $post_id, '_sale_price', $new_price ); update_post_meta( $post_id, '_sale_price', $new_price );
$product->sale_price = $new_price; $product->sale_price = $new_price;
} }
} }
if ( $price_changed ) { if ( $price_changed ) {
update_post_meta( $post_id, '_sale_price_dates_from', '' ); update_post_meta( $post_id, '_sale_price_dates_from', '' );
update_post_meta( $post_id, '_sale_price_dates_to', '' ); update_post_meta( $post_id, '_sale_price_dates_to', '' );
if ( $product->regular_price < $product->sale_price ) { if ( $product->regular_price < $product->sale_price ) {
$product->sale_price = ''; $product->sale_price = '';
update_post_meta( $post_id, '_sale_price', '' ); update_post_meta( $post_id, '_sale_price', '' );
@ -1129,22 +1129,22 @@ function woocommerce_admin_product_bulk_edit_save( $post_id, $post ) {
// Handle stock // Handle stock
if ( ! $product->is_type( 'grouped' ) ) { if ( ! $product->is_type( 'grouped' ) ) {
if ( ! empty( $_REQUEST['change_stock'] ) ) { if ( ! empty( $_REQUEST['change_stock'] ) ) {
update_post_meta( $post_id, '_stock', (int) $_REQUEST['_stock'] ); update_post_meta( $post_id, '_stock', (int) $_REQUEST['_stock'] );
update_post_meta( $post_id, '_manage_stock', 'yes' ); update_post_meta( $post_id, '_manage_stock', 'yes' );
} }
if ( ! empty( $_REQUEST['_manage_stock'] ) ) { if ( ! empty( $_REQUEST['_manage_stock'] ) ) {
if ( $_REQUEST['_manage_stock'] == 'yes' ) { if ( $_REQUEST['_manage_stock'] == 'yes' ) {
update_post_meta( $post_id, '_manage_stock', 'yes' ); update_post_meta( $post_id, '_manage_stock', 'yes' );
} else { } else {
update_post_meta( $post_id, '_manage_stock', 'no' ); update_post_meta( $post_id, '_manage_stock', 'no' );
update_post_meta( $post_id, '_stock', '0' ); update_post_meta( $post_id, '_stock', '0' );
} }
} }
} }
// Clear transient // Clear transient
@ -1181,18 +1181,18 @@ add_filter( 'views_edit-product', 'woocommerce_default_sorting_link' );
/** /**
* woocommerce_disable_checked_ontop function. * woocommerce_disable_checked_ontop function.
* *
* @access public * @access public
* @param mixed $args * @param mixed $args
* @param mixed $post_id * @param mixed $post_id
* @return void * @return void
*/ */
function woocommerce_disable_checked_ontop( $args ) { function woocommerce_disable_checked_ontop( $args ) {
if ( $args['taxonomy'] == 'product_cat' ) { if ( $args['taxonomy'] == 'product_cat' ) {
$args['checked_ontop'] = false; $args['checked_ontop'] = false;
} }
return $args; return $args;
} }

View File

@ -56,34 +56,34 @@ function woocommerce_custom_coupon_columns( $column ) {
case "products" : case "products" :
$product_ids = get_post_meta( $post->ID, 'product_ids', true ); $product_ids = get_post_meta( $post->ID, 'product_ids', true );
$product_ids = $product_ids ? array_map( 'absint', explode( ',', $product_ids ) ) : array(); $product_ids = $product_ids ? array_map( 'absint', explode( ',', $product_ids ) ) : array();
if ( sizeof( $product_ids ) > 0 ) if ( sizeof( $product_ids ) > 0 )
echo esc_html( implode( ', ', $product_ids ) ); echo esc_html( implode( ', ', $product_ids ) );
else else
echo '&ndash;'; echo '&ndash;';
break; break;
case "usage_limit" : case "usage_limit" :
$usage_limit = get_post_meta( $post->ID, 'usage_limit', true ); $usage_limit = get_post_meta( $post->ID, 'usage_limit', true );
if ( $usage_limit ) if ( $usage_limit )
echo esc_html( $usage_limit ); echo esc_html( $usage_limit );
else else
echo '&ndash;'; echo '&ndash;';
break; break;
case "usage" : case "usage" :
$usage_count = absint( get_post_meta( $post->ID, 'usage_count', true ) ); $usage_count = absint( get_post_meta( $post->ID, 'usage_count', true ) );
$usage_limit = esc_html( get_post_meta($post->ID, 'usage_limit', true) ); $usage_limit = esc_html( get_post_meta($post->ID, 'usage_limit', true) );
if ( $usage_limit ) if ( $usage_limit )
printf( __( '%s / %s', 'woocommerce' ), $usage_count, $usage_limit ); printf( __( '%s / %s', 'woocommerce' ), $usage_count, $usage_limit );
else else
printf( __( '%s / &infin;', 'woocommerce' ), $usage_count ); printf( __( '%s / &infin;', 'woocommerce' ), $usage_count );
break; break;
case "expiry_date" : case "expiry_date" :
$expiry_date = get_post_meta($post->ID, 'expiry_date', true); $expiry_date = get_post_meta($post->ID, 'expiry_date', true);
if ( $expiry_date ) if ( $expiry_date )
echo esc_html( date_i18n( 'F j, Y', strtotime( $expiry_date ) ) ); echo esc_html( date_i18n( 'F j, Y', strtotime( $expiry_date ) ) );
else else
echo '&ndash;'; echo '&ndash;';
break; break;
case "description" : case "description" :

View File

@ -76,16 +76,16 @@ function woocommerce_custom_order_columns( $column ) {
break; break;
case "order_title" : case "order_title" :
if ( $order->user_id ) if ( $order->user_id )
$user_info = get_userdata( $order->user_id ); $user_info = get_userdata( $order->user_id );
if ( ! empty( $user_info ) ) { if ( ! empty( $user_info ) ) {
$user = '<a href="user-edit.php?user_id=' . absint( $user_info->ID ) . '">'; $user = '<a href="user-edit.php?user_id=' . absint( $user_info->ID ) . '">';
if ( $user_info->first_name || $user_info->last_name ) if ( $user_info->first_name || $user_info->last_name )
$user .= esc_html( $user_info->first_name . ' ' . $user_info->last_name ); $user .= esc_html( $user_info->first_name . ' ' . $user_info->last_name );
else else
$user .= esc_html( $user_info->display_name ); $user .= esc_html( $user_info->display_name );
$user .= '</a>'; $user .= '</a>';
@ -98,7 +98,7 @@ function woocommerce_custom_order_columns( $column ) {
if ( $order->billing_email ) if ( $order->billing_email )
echo '<small class="meta">' . __( 'Email:', 'woocommerce' ) . ' ' . '<a href="' . esc_url( 'mailto:' . $order->billing_email ) . '">' . esc_html( $order->billing_email ) . '</a></small>'; echo '<small class="meta">' . __( 'Email:', 'woocommerce' ) . ' ' . '<a href="' . esc_url( 'mailto:' . $order->billing_email ) . '">' . esc_html( $order->billing_email ) . '</a></small>';
if ( $order->billing_phone ) if ( $order->billing_phone )
echo '<small class="meta">' . __( 'Tel:', 'woocommerce' ) . ' ' . esc_html( $order->billing_phone ) . '</small>'; echo '<small class="meta">' . __( 'Tel:', 'woocommerce' ) . ' ' . esc_html( $order->billing_phone ) . '</small>';
@ -394,7 +394,7 @@ add_filter( "manage_edit-shop_order_sortable_columns", 'woocommerce_custom_shop_
*/ */
function woocommerce_custom_shop_order_orderby( $vars ) { function woocommerce_custom_shop_order_orderby( $vars ) {
global $typenow, $wp_query; global $typenow, $wp_query;
if ( $typenow != 'shop_order' ) if ( $typenow != 'shop_order' )
return $vars; return $vars;
// Sorting // Sorting
@ -443,9 +443,9 @@ function woocommerce_shop_order_search_custom_fields( $wp ) {
) ) ); ) ) );
// Query matching custom fields - this seems faster than meta_query // Query matching custom fields - this seems faster than meta_query
$post_ids = $wpdb->get_col( $post_ids = $wpdb->get_col(
$wpdb->prepare( $wpdb->prepare(
"SELECT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN ('" . implode( "','", $search_fields ) . "') AND meta_value LIKE '%%%s%%'", esc_attr( $_GET['s'] ) "SELECT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN ('" . implode( "','", $search_fields ) . "') AND meta_value LIKE '%%%s%%'", esc_attr( $_GET['s'] )
) )
); );
@ -473,7 +473,7 @@ function woocommerce_shop_order_search_custom_fields( $wp ) {
// Add ID // Add ID
$search_order_id = str_replace( 'Order #', '', $_GET['s'] ); $search_order_id = str_replace( 'Order #', '', $_GET['s'] );
if ( is_numeric( $search_order_id ) ) if ( is_numeric( $search_order_id ) )
$post_ids[] = $search_order_id; $post_ids[] = $search_order_id;
// Add blank ID so not all results are returned if the search finds nothing // Add blank ID so not all results are returned if the search finds nothing

View File

@ -1,4 +1,4 @@
<?php <?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
?> ?>
<div class="wc-metabox closed"> <div class="wc-metabox closed">

View File

@ -1,16 +1,16 @@
<?php <?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
?> ?>
<tr class="fee" data-order_item_id="<?php echo $item_id; ?>"> <tr class="fee" data-order_item_id="<?php echo $item_id; ?>">
<td class="check-column"><input type="checkbox" /></td> <td class="check-column"><input type="checkbox" /></td>
<td class="thumb"></td> <td class="thumb"></td>
<td class="name"> <td class="name">
<input type="text" placeholder="<?php _e( 'Fee Name', 'woocommerce' ); ?>" name="order_item_name[<?php echo absint( $item_id ); ?>]" value="<?php if ( isset( $item['name'] ) ) echo esc_attr( $item['name'] ); ?>" /> <input type="text" placeholder="<?php _e( 'Fee Name', 'woocommerce' ); ?>" name="order_item_name[<?php echo absint( $item_id ); ?>]" value="<?php if ( isset( $item['name'] ) ) echo esc_attr( $item['name'] ); ?>" />
<input type="hidden" class="order_item_id" name="order_item_id[]" value="<?php echo esc_attr( $item_id ); ?>" /> <input type="hidden" class="order_item_id" name="order_item_id[]" value="<?php echo esc_attr( $item_id ); ?>" />
</td> </td>
<td class="tax_class" width="1%"> <td class="tax_class" width="1%">
<select class="tax_class" name="order_item_tax_class[<?php echo absint( $item_id ); ?>]" title="<?php _e( 'Tax class', 'woocommerce' ); ?>"> <select class="tax_class" name="order_item_tax_class[<?php echo absint( $item_id ); ?>]" title="<?php _e( 'Tax class', 'woocommerce' ); ?>">
<?php $tax_class = isset( $item['tax_class'] ) ? sanitize_title( $item['tax_class'] ) : ''; ?> <?php $tax_class = isset( $item['tax_class'] ) ? sanitize_title( $item['tax_class'] ) : ''; ?>
@ -18,15 +18,15 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
<optgroup label="<?php _e( 'Taxable', 'woocommerce' ); ?>"> <optgroup label="<?php _e( 'Taxable', 'woocommerce' ); ?>">
<?php <?php
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('woocommerce_tax_classes' ) ) ) ); $tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('woocommerce_tax_classes' ) ) ) );
$classes_options = array(); $classes_options = array();
$classes_options[''] = __( 'Standard', 'woocommerce' ); $classes_options[''] = __( 'Standard', 'woocommerce' );
if ( $tax_classes ) if ( $tax_classes )
foreach ( $tax_classes as $class ) foreach ( $tax_classes as $class )
$classes_options[ sanitize_title( $class ) ] = $class; $classes_options[ sanitize_title( $class ) ] = $class;
foreach ( $classes_options as $value => $name ) foreach ( $classes_options as $value => $name )
echo '<option value="' . esc_attr( $value ) . '" ' . selected( $value, $tax_class, false ) . '>'. esc_html( $name ) . '</option>'; echo '<option value="' . esc_attr( $value ) . '" ' . selected( $value, $tax_class, false ) . '>'. esc_html( $name ) . '</option>';
?> ?>
</optgroup> </optgroup>

View File

@ -1,30 +1,30 @@
<?php <?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
?> ?>
<tr class="item <?php if ( ! empty( $class ) ) echo $class; ?>" data-order_item_id="<?php echo $item_id; ?>"> <tr class="item <?php if ( ! empty( $class ) ) echo $class; ?>" data-order_item_id="<?php echo $item_id; ?>">
<td class="check-column"><input type="checkbox" /></td> <td class="check-column"><input type="checkbox" /></td>
<td class="thumb"> <td class="thumb">
<a href="<?php echo esc_url( admin_url( 'post.php?post=' . absint( $_product->id ) . '&action=edit' ) ); ?>" class="tips" data-tip="<?php <a href="<?php echo esc_url( admin_url( 'post.php?post=' . absint( $_product->id ) . '&action=edit' ) ); ?>" class="tips" data-tip="<?php
echo '<strong>' . __( 'Product ID:', 'woocommerce' ) . '</strong> ' . absint( $item['product_id'] ); echo '<strong>' . __( 'Product ID:', 'woocommerce' ) . '</strong> ' . absint( $item['product_id'] );
if ( $item['variation_id'] ) if ( $item['variation_id'] )
echo '<br/><strong>' . __( 'Variation ID:', 'woocommerce' ) . '</strong> ' . absint( $item['variation_id'] ); echo '<br/><strong>' . __( 'Variation ID:', 'woocommerce' ) . '</strong> ' . absint( $item['variation_id'] );
if ( $_product->get_sku() ) if ( $_product->get_sku() )
echo '<br/><strong>' . __( 'Product SKU:', 'woocommerce' ).'</strong> ' . esc_html( $_product->get_sku() ); echo '<br/><strong>' . __( 'Product SKU:', 'woocommerce' ).'</strong> ' . esc_html( $_product->get_sku() );
?>"><?php echo $_product->get_image(); ?></a> ?>"><?php echo $_product->get_image(); ?></a>
</td> </td>
<td class="name"> <td class="name">
<?php if ( $_product->get_sku() ) echo esc_html( $_product->get_sku() ) . ' &ndash; '; ?> <?php if ( $_product->get_sku() ) echo esc_html( $_product->get_sku() ) . ' &ndash; '; ?>
<a target="_blank" href="<?php echo esc_url( admin_url( 'post.php?post='. absint( $_product->id ) .'&action=edit' ) ); ?>"><?php echo esc_html( $item['name'] ); ?></a> <a target="_blank" href="<?php echo esc_url( admin_url( 'post.php?post='. absint( $_product->id ) .'&action=edit' ) ); ?>"><?php echo esc_html( $item['name'] ); ?></a>
<input type="hidden" class="order_item_id" name="order_item_id[]" value="<?php echo esc_attr( $item_id ); ?>" /> <input type="hidden" class="order_item_id" name="order_item_id[]" value="<?php echo esc_attr( $item_id ); ?>" />
<?php <?php
if ( isset( $_product->variation_data ) ) if ( isset( $_product->variation_data ) )
echo '<br/>' . woocommerce_get_formatted_variation( $_product->variation_data, true ); echo '<br/>' . woocommerce_get_formatted_variation( $_product->variation_data, true );
?> ?>
<table class="meta" cellspacing="0"> <table class="meta" cellspacing="0">
@ -37,9 +37,9 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
<?php <?php
if ( $metadata = $order->has_meta( $item_id )) { if ( $metadata = $order->has_meta( $item_id )) {
foreach ( $metadata as $meta ) { foreach ( $metadata as $meta ) {
// Skip hidden core fields // Skip hidden core fields
if ( in_array( $meta['meta_key'], apply_filters( 'woocommerce_hidden_order_itemmeta', array( if ( in_array( $meta['meta_key'], apply_filters( 'woocommerce_hidden_order_itemmeta', array(
'_qty', '_qty',
'_tax_class', '_tax_class',
'_product_id', '_product_id',
@ -49,7 +49,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
'_line_total', '_line_total',
'_line_tax' '_line_tax'
) ) ) ) continue; ) ) ) ) continue;
// Handle serialised fields // Handle serialised fields
if ( is_serialized( $meta['meta_value'] ) ) { if ( is_serialized( $meta['meta_value'] ) ) {
if ( is_serialized_string( $meta['meta_value'] ) ) { if ( is_serialized_string( $meta['meta_value'] ) ) {
@ -62,8 +62,8 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
$meta['meta_key'] = esc_attr( $meta['meta_key'] ); $meta['meta_key'] = esc_attr( $meta['meta_key'] );
$meta['meta_value'] = esc_textarea( $meta['meta_value'] ); // using a <textarea /> $meta['meta_value'] = esc_textarea( $meta['meta_value'] ); // using a <textarea />
$meta['meta_id'] = (int) $meta['meta_id']; $meta['meta_id'] = (int) $meta['meta_id'];
echo '<tr data-meta_id="' . $meta['meta_id'] . '"> echo '<tr data-meta_id="' . $meta['meta_id'] . '">
<td><input type="text" name="meta_key[' . $meta['meta_id'] . ']" value="' . $meta['meta_key'] . '" /></td> <td><input type="text" name="meta_key[' . $meta['meta_id'] . ']" value="' . $meta['meta_key'] . '" /></td>
<td><input type="text" name="meta_value[' . $meta['meta_id'] . ']" value="' . $meta['meta_value'] . '" /></td> <td><input type="text" name="meta_value[' . $meta['meta_id'] . ']" value="' . $meta['meta_value'] . '" /></td>
@ -82,17 +82,17 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
<select class="tax_class" name="order_item_tax_class[<?php echo absint( $item_id ); ?>]" title="<?php _e( 'Tax class', 'woocommerce' ); ?>"> <select class="tax_class" name="order_item_tax_class[<?php echo absint( $item_id ); ?>]" title="<?php _e( 'Tax class', 'woocommerce' ); ?>">
<?php <?php
$item_value = isset( $item['tax_class'] ) ? sanitize_title( $item['tax_class'] ) : ''; $item_value = isset( $item['tax_class'] ) ? sanitize_title( $item['tax_class'] ) : '';
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('woocommerce_tax_classes' ) ) ) ); $tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('woocommerce_tax_classes' ) ) ) );
$classes_options = array(); $classes_options = array();
$classes_options[''] = __( 'Standard', 'woocommerce' ); $classes_options[''] = __( 'Standard', 'woocommerce' );
if ( $tax_classes ) if ( $tax_classes )
foreach ( $tax_classes as $class ) foreach ( $tax_classes as $class )
$classes_options[ sanitize_title( $class ) ] = $class; $classes_options[ sanitize_title( $class ) ] = $class;
foreach ( $classes_options as $value => $name ) foreach ( $classes_options as $value => $name )
echo '<option value="' . esc_attr( $value ) . '" ' . selected( $value, $item_value, false ) . '>'. esc_html( $name ) . '</option>'; echo '<option value="' . esc_attr( $value ) . '" ' . selected( $value, $item_value, false ) . '>'. esc_html( $name ) . '</option>';
?> ?>
</select> </select>
@ -104,13 +104,13 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
<td class="line_cost" width="1%"> <td class="line_cost" width="1%">
<label><?php _e( 'Total', 'woocommerce' ); ?>: <input type="number" step="any" min="0" name="line_total[<?php echo absint( $item_id ); ?>]" placeholder="0.00" value="<?php if ( isset( $item['line_total'] ) ) echo esc_attr( $item['line_total'] ); ?>" class="line_total" /></label> <label><?php _e( 'Total', 'woocommerce' ); ?>: <input type="number" step="any" min="0" name="line_total[<?php echo absint( $item_id ); ?>]" placeholder="0.00" value="<?php if ( isset( $item['line_total'] ) ) echo esc_attr( $item['line_total'] ); ?>" class="line_total" /></label>
<span class="subtotal"><label><?php _e( 'Subtotal', 'woocommerce' ); ?>: <input type="number" step="any" min="0" name="line_subtotal[<?php echo absint( $item_id ); ?>]" placeholder="0.00" value="<?php if ( isset( $item['line_subtotal'] ) ) echo esc_attr( $item['line_subtotal'] ); ?>" class="line_subtotal" /></label></span> <span class="subtotal"><label><?php _e( 'Subtotal', 'woocommerce' ); ?>: <input type="number" step="any" min="0" name="line_subtotal[<?php echo absint( $item_id ); ?>]" placeholder="0.00" value="<?php if ( isset( $item['line_subtotal'] ) ) echo esc_attr( $item['line_subtotal'] ); ?>" class="line_subtotal" /></label></span>
</td> </td>
<td class="line_tax" width="1%"> <td class="line_tax" width="1%">
<input type="number" step="any" min="0" name="line_tax[<?php echo absint( $item_id ); ?>]" placeholder="0.00" value="<?php if ( isset( $item['line_tax'] ) ) echo esc_attr( $item['line_tax'] ); ?>" class="line_tax" /> <input type="number" step="any" min="0" name="line_tax[<?php echo absint( $item_id ); ?>]" placeholder="0.00" value="<?php if ( isset( $item['line_tax'] ) ) echo esc_attr( $item['line_tax'] ); ?>" class="line_tax" />
<span class="subtotal"><input type="number" step="any" min="0" name="line_subtotal_tax[<?php echo absint( $item_id ); ?>]" placeholder="0.00" value="<?php if ( isset( $item['line_subtotal_tax'] ) ) echo esc_attr( $item['line_subtotal_tax'] ); ?>" class="line_subtotal_tax" /></span> <span class="subtotal"><input type="number" step="any" min="0" name="line_subtotal_tax[<?php echo absint( $item_id ); ?>]" placeholder="0.00" value="<?php if ( isset( $item['line_subtotal_tax'] ) ) echo esc_attr( $item['line_subtotal_tax'] ); ?>" class="line_subtotal_tax" /></span>
</td> </td>

View File

@ -1,4 +1,4 @@
<?php <?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
?> ?>
<div class="tax_row" data-order_item_id="<?php echo $item_id; ?>"> <div class="tax_row" data-order_item_id="<?php echo $item_id; ?>">

View File

@ -1,4 +1,4 @@
<?php <?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
?> ?>
<div class="woocommerce_variation wc-metabox closed"> <div class="woocommerce_variation wc-metabox closed">
@ -10,7 +10,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
foreach ( $parent_data['attributes'] as $attribute ) { foreach ( $parent_data['attributes'] as $attribute ) {
// Only deal with attributes that are variations // Only deal with attributes that are variations
if ( ! $attribute['is_variation'] ) if ( ! $attribute['is_variation'] )
continue; continue;
// Get current value for variation (if set) // Get current value for variation (if set)
@ -60,7 +60,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
<td>&nbsp;</td> <td>&nbsp;</td>
</tr> </tr>
<?php endif; ?> <?php endif; ?>
<tr> <tr>
<td> <td>
<label><?php _e( 'Price:', 'woocommerce' ); ?></label> <label><?php _e( 'Price:', 'woocommerce' ); ?></label>
@ -68,10 +68,10 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
</td> </td>
<td> <td>
<label><?php _e( 'Sale Price:', 'woocommerce' ); ?> <a href="#" class="sale_schedule"><?php _e( 'Schedule', 'woocommerce' ); ?></a><a href="#" class="cancel_sale_schedule" style="display:none"><?php _e( 'Cancel schedule', 'woocommerce' ); ?></a></label> <label><?php _e( 'Sale Price:', 'woocommerce' ); ?> <a href="#" class="sale_schedule"><?php _e( 'Schedule', 'woocommerce' ); ?></a><a href="#" class="cancel_sale_schedule" style="display:none"><?php _e( 'Cancel schedule', 'woocommerce' ); ?></a></label>
<input type="number" size="5" name="variable_sale_price[<?php echo $loop; ?>]" value="<?php if ( isset( $_sale_price ) ) echo esc_attr( $_sale_price ); ?>" step="any" min="0" /> <input type="number" size="5" name="variable_sale_price[<?php echo $loop; ?>]" value="<?php if ( isset( $_sale_price ) ) echo esc_attr( $_sale_price ); ?>" step="any" min="0" />
</td> </td>
</tr> </tr>
<tr class="sale_price_dates_fields" style="display:none"> <tr class="sale_price_dates_fields" style="display:none">
<td> <td>
<label><?php _e( 'Sale start date:', 'woocommerce' ) ?></label> <label><?php _e( 'Sale start date:', 'woocommerce' ) ?></label>
@ -82,7 +82,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
<input type="text" name="variable_sale_price_dates_to[<?php echo $loop; ?>]" value="<?php echo ! empty( $_sale_price_dates_to ) ? date_i18n( 'Y-m-d', $_sale_price_dates_to ) : ''; ?>" placeholder="<?php echo _x('To&hellip;', 'placeholder', 'woocommerce') ?> YYYY-MM-DD" maxlength="10" pattern="[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" /> <input type="text" name="variable_sale_price_dates_to[<?php echo $loop; ?>]" value="<?php echo ! empty( $_sale_price_dates_to ) ? date_i18n( 'Y-m-d', $_sale_price_dates_to ) : ''; ?>" placeholder="<?php echo _x('To&hellip;', 'placeholder', 'woocommerce') ?> YYYY-MM-DD" maxlength="10" pattern="[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" />
</td> </td>
</tr> </tr>
<?php if ( get_option( 'woocommerce_enable_weight', true ) !== 'no' || get_option( 'woocommerce_enable_dimensions', true ) !== 'no' ) : ?> <?php if ( get_option( 'woocommerce_enable_weight', true ) !== 'no' || get_option( 'woocommerce_enable_dimensions', true ) !== 'no' ) : ?>
<tr> <tr>
<?php if ( get_option( 'woocommerce_enable_weight', true ) !== 'no' ) : ?> <?php if ( get_option( 'woocommerce_enable_weight', true ) !== 'no' ) : ?>
@ -116,11 +116,11 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
'selected' => isset( $shipping_class ) ? esc_attr( $shipping_class ) : '', 'selected' => isset( $shipping_class ) ? esc_attr( $shipping_class ) : '',
'echo' => 0 'echo' => 0
); );
echo wp_dropdown_categories( $args ); echo wp_dropdown_categories( $args );
?></td> ?></td>
<td> <td>
<label><?php _e( 'Tax class:', 'woocommerce' ); ?></label> <label><?php _e( 'Tax class:', 'woocommerce' ); ?></label>
<select name="variable_tax_class[<?php echo $loop; ?>]"><?php <select name="variable_tax_class[<?php echo $loop; ?>]"><?php
foreach ( $parent_data['tax_class_options'] as $key => $value ) foreach ( $parent_data['tax_class_options'] as $key => $value )
echo '<option value="' . esc_attr( $key ) . '" ' . selected( $key, $_tax_class, false ) . '>' . esc_html( $value ) . '</option>'; echo '<option value="' . esc_attr( $key ) . '" ' . selected( $key, $_tax_class, false ) . '>' . esc_html( $value ) . '</option>';
@ -131,7 +131,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
<td rowspan="2"> <td rowspan="2">
<div class="file_path_field"> <div class="file_path_field">
<label><?php _e( 'File paths:', 'woocommerce' ); ?> <a class="tips" data-tip="<?php _e( 'Enter one or more File Paths, one per line, to make this variation a downloadable product, or leave blank.', 'woocommerce' ); ?>" href="#">[?]</a></label> <label><?php _e( 'File paths:', 'woocommerce' ); ?> <a class="tips" data-tip="<?php _e( 'Enter one or more File Paths, one per line, to make this variation a downloadable product, or leave blank.', 'woocommerce' ); ?>" href="#">[?]</a></label>
<textarea style="float:left;" class="short file_paths" cols="20" rows="2" placeholder="<?php _e( 'File paths/URLs, one per line', 'woocommerce' ); ?>" name="variable_file_paths[<?php echo $loop; ?>]" wrap="off"><?php if ( isset( $_file_paths ) ) echo esc_textarea( $_file_paths ); ?></textarea> <textarea style="float:left;" class="short file_paths" cols="20" rows="2" placeholder="<?php _e( 'File paths/URLs, one per line', 'woocommerce' ); ?>" name="variable_file_paths[<?php echo $loop; ?>]" wrap="off"><?php if ( isset( $_file_paths ) ) echo esc_textarea( $_file_paths ); ?></textarea>
<input type="button" class="upload_file_button button" value="<?php _e( 'Upload a file', 'woocommerce' ); ?>" title="<?php _e( 'Upload', 'woocommerce' ); ?>" /> <input type="button" class="upload_file_button button" value="<?php _e( 'Upload a file', 'woocommerce' ); ?>" title="<?php _e( 'Upload', 'woocommerce' ); ?>" />
</div> </div>
</td> </td>

View File

@ -35,9 +35,9 @@ function woocommerce_coupon_data_meta_box( $post ) {
// Description // Description
woocommerce_wp_text_input( array( 'id' => 'coupon_description', 'label' => __( 'Coupon description', 'woocommerce' ), 'description' => __( 'Optionally enter a description for this coupon for your reference.', 'woocommerce' ), 'value' => $post->post_excerpt, 'name' => 'excerpt' ) ); woocommerce_wp_text_input( array( 'id' => 'coupon_description', 'label' => __( 'Coupon description', 'woocommerce' ), 'description' => __( 'Optionally enter a description for this coupon for your reference.', 'woocommerce' ), 'value' => $post->post_excerpt, 'name' => 'excerpt' ) );
echo '</div><div class="options_group">'; echo '</div><div class="options_group">';
// Type // Type
woocommerce_wp_select( array( 'id' => 'discount_type', 'label' => __( 'Discount type', 'woocommerce' ), 'options' => $woocommerce->get_coupon_discount_types() ) ); woocommerce_wp_select( array( 'id' => 'discount_type', 'label' => __( 'Discount type', 'woocommerce' ), 'options' => $woocommerce->get_coupon_discount_types() ) );
@ -46,7 +46,7 @@ function woocommerce_coupon_data_meta_box( $post ) {
'step' => 'any', 'step' => 'any',
'min' => '0' 'min' => '0'
) ) ); ) ) );
// Free Shipping // Free Shipping
woocommerce_wp_checkbox( array( 'id' => 'free_shipping', 'label' => __( 'Enable free shipping', 'woocommerce' ), 'description' => sprintf(__( 'Check this box if the coupon grants free shipping. The <a href="%s">free shipping method</a> must be enabled with the "must use coupon" setting checked.', 'woocommerce' ), admin_url('admin.php?page=woocommerce_settings&tab=shipping&section=WC_Free_Shipping')) ) ); woocommerce_wp_checkbox( array( 'id' => 'free_shipping', 'label' => __( 'Enable free shipping', 'woocommerce' ), 'description' => sprintf(__( 'Check this box if the coupon grants free shipping. The <a href="%s">free shipping method</a> must be enabled with the "must use coupon" setting checked.', 'woocommerce' ), admin_url('admin.php?page=woocommerce_settings&tab=shipping&section=WC_Free_Shipping')) ) );
@ -55,7 +55,7 @@ function woocommerce_coupon_data_meta_box( $post ) {
// Apply before tax // Apply before tax
woocommerce_wp_checkbox( array( 'id' => 'apply_before_tax', 'label' => __( 'Apply before tax', 'woocommerce' ), 'description' => __( 'Check this box if the coupon should be applied before calculating cart tax.', 'woocommerce' ) ) ); woocommerce_wp_checkbox( array( 'id' => 'apply_before_tax', 'label' => __( 'Apply before tax', 'woocommerce' ), 'description' => __( 'Check this box if the coupon should be applied before calculating cart tax.', 'woocommerce' ) ) );
echo '</div><div class="options_group">'; echo '</div><div class="options_group">';
// minimum spend // minimum spend
@ -78,10 +78,10 @@ function woocommerce_coupon_data_meta_box( $post ) {
$title = get_the_title( $product_id ); $title = get_the_title( $product_id );
$sku = get_post_meta( $product_id, '_sku', true ); $sku = get_post_meta( $product_id, '_sku', true );
if ( ! $title ) if ( ! $title )
continue; continue;
if ( ! empty( $sku ) ) if ( ! empty( $sku ) )
$sku = ' (SKU: ' . $sku . ')'; $sku = ' (SKU: ' . $sku . ')';
echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $title . $sku ) . '</option>'; echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $title . $sku ) . '</option>';
@ -103,10 +103,10 @@ function woocommerce_coupon_data_meta_box( $post ) {
$title = get_the_title( $product_id ); $title = get_the_title( $product_id );
$sku = get_post_meta( $product_id, '_sku', true ); $sku = get_post_meta( $product_id, '_sku', true );
if ( ! $title ) if ( ! $title )
continue; continue;
if ( ! empty( $sku ) ) if ( ! empty( $sku ) )
$sku = ' (SKU: ' . $sku . ')'; $sku = ' (SKU: ' . $sku . ')';
echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $title . $sku ) . '</option>'; echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $title . $sku ) . '</option>';
@ -183,11 +183,11 @@ function woocommerce_coupon_data_meta_box( $post ) {
*/ */
function woocommerce_process_shop_coupon_meta( $post_id, $post ) { function woocommerce_process_shop_coupon_meta( $post_id, $post ) {
global $wpdb, $woocommerce_errors; global $wpdb, $woocommerce_errors;
// Ensure coupon code is correctly formatted // Ensure coupon code is correctly formatted
$post->post_title = apply_filters( 'woocommerce_coupon_code', $post->post_title ); $post->post_title = apply_filters( 'woocommerce_coupon_code', $post->post_title );
$wpdb->update( $wpdb->posts, array( 'post_title' => $post->post_title ), array( 'ID' => $post_id ) ); $wpdb->update( $wpdb->posts, array( 'post_title' => $post->post_title ), array( 'ID' => $post_id ) );
// Check for dupe coupons // Check for dupe coupons
$coupon_found = $wpdb->get_var( $wpdb->prepare( " $coupon_found = $wpdb->get_var( $wpdb->prepare( "
SELECT $wpdb->posts.ID SELECT $wpdb->posts.ID
@ -197,7 +197,7 @@ function woocommerce_process_shop_coupon_meta( $post_id, $post ) {
AND $wpdb->posts.post_title = '%s' AND $wpdb->posts.post_title = '%s'
AND $wpdb->posts.ID != %s AND $wpdb->posts.ID != %s
", $post->post_title, $post_id ) ); ", $post->post_title, $post_id ) );
if ( $coupon_found ) if ( $coupon_found )
$woocommerce_errors[] = __( 'Coupon code already exists - customers will use the latest coupon with this code.', 'woocommerce' ); $woocommerce_errors[] = __( 'Coupon code already exists - customers will use the latest coupon with this code.', 'woocommerce' );

View File

@ -23,7 +23,7 @@ function woocommerce_order_data_meta_box($post) {
global $post, $wpdb, $thepostid, $theorder, $order_status, $woocommerce; global $post, $wpdb, $thepostid, $theorder, $order_status, $woocommerce;
$thepostid = absint( $post->ID ); $thepostid = absint( $post->ID );
if ( ! is_object( $theorder ) ) if ( ! is_object( $theorder ) )
$theorder = new WC_Order( $thepostid ); $theorder = new WC_Order( $thepostid );
@ -176,16 +176,16 @@ function woocommerce_order_data_meta_box($post) {
// Display values // Display values
echo '<div class="address">'; echo '<div class="address">';
if ( $order->get_formatted_billing_address() ) if ( $order->get_formatted_billing_address() )
echo '<p><strong>' . __( 'Address', 'woocommerce' ) . ':</strong><br/> ' . $order->get_formatted_billing_address() . '</p>'; echo '<p><strong>' . __( 'Address', 'woocommerce' ) . ':</strong><br/> ' . $order->get_formatted_billing_address() . '</p>';
else else
echo '<p class="none_set"><strong>' . __( 'Address', 'woocommerce' ) . ':</strong> ' . __( 'No billing address set.', 'woocommerce' ) . '</p>'; echo '<p class="none_set"><strong>' . __( 'Address', 'woocommerce' ) . ':</strong> ' . __( 'No billing address set.', 'woocommerce' ) . '</p>';
foreach ( $billing_data as $key => $field ) { foreach ( $billing_data as $key => $field ) {
if ( empty( $field['show'] ) ) if ( empty( $field['show'] ) )
continue; continue;
$field_name = 'billing_' . $key; $field_name = 'billing_' . $key;
if ( $order->$field_name ) if ( $order->$field_name )
echo '<p><strong>' . esc_html( $field['label'] ) . ':</strong> ' . esc_html( $order->$field_name ) . '</p>'; echo '<p><strong>' . esc_html( $field['label'] ) . ':</strong> ' . esc_html( $order->$field_name ) . '</p>';
} }
@ -195,7 +195,7 @@ function woocommerce_order_data_meta_box($post) {
echo '<div class="edit_address"><p><button class="button load_customer_billing">'.__( 'Load billing address', 'woocommerce' ).'</button></p>'; echo '<div class="edit_address"><p><button class="button load_customer_billing">'.__( 'Load billing address', 'woocommerce' ).'</button></p>';
foreach ( $billing_data as $key => $field ) { foreach ( $billing_data as $key => $field ) {
if ( ! isset( $field['type'] ) ) if ( ! isset( $field['type'] ) )
$field['type'] = 'text'; $field['type'] = 'text';
switch ( $field['type'] ) { switch ( $field['type'] ) {
case "select" : case "select" :
@ -260,16 +260,16 @@ function woocommerce_order_data_meta_box($post) {
// Display values // Display values
echo '<div class="address">'; echo '<div class="address">';
if ( $order->get_formatted_shipping_address() ) if ( $order->get_formatted_shipping_address() )
echo '<p><strong>' . __( 'Address', 'woocommerce' ) . ':</strong><br/> ' . $order->get_formatted_shipping_address() . '</p>'; echo '<p><strong>' . __( 'Address', 'woocommerce' ) . ':</strong><br/> ' . $order->get_formatted_shipping_address() . '</p>';
else else
echo '<p class="none_set"><strong>' . __( 'Address', 'woocommerce' ) . ':</strong> ' . __( 'No shipping address set.', 'woocommerce' ) . '</p>'; echo '<p class="none_set"><strong>' . __( 'Address', 'woocommerce' ) . ':</strong> ' . __( 'No shipping address set.', 'woocommerce' ) . '</p>';
if ( $shipping_data ) foreach ( $shipping_data as $key => $field ) { if ( $shipping_data ) foreach ( $shipping_data as $key => $field ) {
if ( empty( $field['show'] ) ) if ( empty( $field['show'] ) )
continue; continue;
$field_name = 'shipping_' . $key; $field_name = 'shipping_' . $key;
if ( $order->$field_name ) if ( $order->$field_name )
echo '<p><strong>' . esc_html( $field['label'] ) . ':</strong> ' . esc_html( $order->$field_name ) . '</p>'; echo '<p><strong>' . esc_html( $field['label'] ) . ':</strong> ' . esc_html( $order->$field_name ) . '</p>';
} }
@ -279,7 +279,7 @@ function woocommerce_order_data_meta_box($post) {
echo '<div class="edit_address"><p><button class="button load_customer_shipping">' . __( 'Load shipping address', 'woocommerce' ) . '</button> <button class="button billing-same-as-shipping">'. __( 'Copy from billing', 'woocommerce' ) . '</button></p>'; echo '<div class="edit_address"><p><button class="button load_customer_shipping">' . __( 'Load shipping address', 'woocommerce' ) . '</button> <button class="button billing-same-as-shipping">'. __( 'Copy from billing', 'woocommerce' ) . '</button></p>';
if ( $shipping_data ) foreach ( $shipping_data as $key => $field ) { if ( $shipping_data ) foreach ( $shipping_data as $key => $field ) {
if ( ! isset( $field['type'] ) ) if ( ! isset( $field['type'] ) )
$field['type'] = 'text'; $field['type'] = 'text';
switch ( $field['type'] ) { switch ( $field['type'] ) {
case "select" : case "select" :
@ -315,7 +315,7 @@ function woocommerce_order_items_meta_box( $post ) {
$theorder = new WC_Order( $thepostid ); $theorder = new WC_Order( $thepostid );
$order = $theorder; $order = $theorder;
$data = get_post_custom( $post->ID ); $data = get_post_custom( $post->ID );
?> ?>
<div class="woocommerce_order_items_wrapper"> <div class="woocommerce_order_items_wrapper">
@ -324,7 +324,7 @@ function woocommerce_order_items_meta_box( $post ) {
<tr> <tr>
<th><input type="checkbox" class="check-column" /></th> <th><input type="checkbox" class="check-column" /></th>
<th class="item" colspan="2"><?php _e( 'Item', 'woocommerce' ); ?></th> <th class="item" colspan="2"><?php _e( 'Item', 'woocommerce' ); ?></th>
<?php do_action( 'woocommerce_admin_order_item_headers' ); ?> <?php do_action( 'woocommerce_admin_order_item_headers' ); ?>
<th class="tax_class"><?php _e( 'Tax Class', 'woocommerce' ); ?>&nbsp;<a class="tips" data-tip="<?php _e( 'Tax class for the line item', 'woocommerce' ); ?>." href="#">[?]</a></th> <th class="tax_class"><?php _e( 'Tax Class', 'woocommerce' ); ?>&nbsp;<a class="tips" data-tip="<?php _e( 'Tax class for the line item', 'woocommerce' ); ?>." href="#">[?]</a></th>
@ -339,29 +339,29 @@ function woocommerce_order_items_meta_box( $post ) {
<tbody id="order_items_list"> <tbody id="order_items_list">
<?php <?php
// List order items // List order items
$order_items = $order->get_items( array( 'line_item', 'fee' ) ); $order_items = $order->get_items( array( 'line_item', 'fee' ) );
foreach ( $order_items as $item_id => $item ) { foreach ( $order_items as $item_id => $item ) {
switch ( $item['type'] ) { switch ( $item['type'] ) {
case 'line_item' : case 'line_item' :
$_product = $order->get_product_from_item( $item ); $_product = $order->get_product_from_item( $item );
$item_meta = $order->get_item_meta( $item_id ); $item_meta = $order->get_item_meta( $item_id );
include( 'order-item-html.php' ); include( 'order-item-html.php' );
break; break;
case 'fee' : case 'fee' :
include( 'order-fee-html.php' ); include( 'order-fee-html.php' );
break; break;
} }
} }
?> ?>
</tbody> </tbody>
</table> </table>
</div> </div>
<p class="bulk_actions"> <p class="bulk_actions">
<select> <select>
<option value=""><?php _e( 'Actions', 'woocommerce' ); ?></option> <option value=""><?php _e( 'Actions', 'woocommerce' ); ?></option>
@ -388,7 +388,7 @@ function woocommerce_order_items_meta_box( $post ) {
<option value="increase_stock"><?php _e( 'Increase Line Stock', 'woocommerce' ); ?></option> <option value="increase_stock"><?php _e( 'Increase Line Stock', 'woocommerce' ); ?></option>
</optgroup> </optgroup>
</select> </select>
<button type="button" class="button do_bulk_action"><?php _e( 'Apply', 'woocommerce' ); ?></button> <button type="button" class="button do_bulk_action"><?php _e( 'Apply', 'woocommerce' ); ?></button>
</p> </p>
@ -456,9 +456,9 @@ function woocommerce_order_actions_meta_box($post) {
else else
$delete_text = __( 'Move to Trash', 'woocommerce' ); $delete_text = __( 'Move to Trash', 'woocommerce' );
?><a class="submitdelete deletion" href="<?php echo esc_url( get_delete_post_link( $post->ID ) ); ?>"><?php echo $delete_text; ?></a><?php ?><a class="submitdelete deletion" href="<?php echo esc_url( get_delete_post_link( $post->ID ) ); ?>"><?php echo $delete_text; ?></a><?php
} }
?></div> ?></div>
<input type="submit" class="button save_order button-primary tips" name="save" value="<?php _e( 'Save Order', 'woocommerce' ); ?>" data-tip="<?php _e( 'Save/update the order', 'woocommerce' ); ?>" /> <input type="submit" class="button save_order button-primary tips" name="save" value="<?php _e( 'Save Order', 'woocommerce' ); ?>" data-tip="<?php _e( 'Save/update the order', 'woocommerce' ); ?>" />
</li> </li>
</ul> </ul>
@ -475,10 +475,10 @@ function woocommerce_order_actions_meta_box($post) {
*/ */
function woocommerce_order_totals_meta_box( $post ) { function woocommerce_order_totals_meta_box( $post ) {
global $woocommerce, $theorder; global $woocommerce, $theorder;
if ( ! is_object( $theorder ) ) if ( ! is_object( $theorder ) )
$theorder = new WC_Order( $post->ID ); $theorder = new WC_Order( $post->ID );
$order = $theorder; $order = $theorder;
$data = get_post_custom( $post->ID ); $data = get_post_custom( $post->ID );
@ -490,7 +490,7 @@ function woocommerce_order_totals_meta_box( $post ) {
<li class="left"> <li class="left">
<label><?php _e( 'Cart Discount:', 'woocommerce' ); ?>&nbsp;<a class="tips" data-tip="<?php _e( 'Discounts before tax - calculated by comparing subtotals to totals.', 'woocommerce' ); ?>" href="#">[?]</a></label> <label><?php _e( 'Cart Discount:', 'woocommerce' ); ?>&nbsp;<a class="tips" data-tip="<?php _e( 'Discounts before tax - calculated by comparing subtotals to totals.', 'woocommerce' ); ?>" href="#">[?]</a></label>
<input type="number" step="any" min="0" id="_cart_discount" name="_cart_discount" placeholder="0.00" value="<?php <input type="number" step="any" min="0" id="_cart_discount" name="_cart_discount" placeholder="0.00" value="<?php
if ( isset( $data['_cart_discount'][0] ) ) if ( isset( $data['_cart_discount'][0] ) )
echo esc_attr( $data['_cart_discount'][0] ); echo esc_attr( $data['_cart_discount'][0] );
?>" class="calculated" /> ?>" class="calculated" />
</li> </li>
@ -498,7 +498,7 @@ function woocommerce_order_totals_meta_box( $post ) {
<li class="right"> <li class="right">
<label><?php _e( 'Order Discount:', 'woocommerce' ); ?>&nbsp;<a class="tips" data-tip="<?php _e( 'Discounts after tax - user defined.', 'woocommerce' ); ?>" href="#">[?]</a></label> <label><?php _e( 'Order Discount:', 'woocommerce' ); ?>&nbsp;<a class="tips" data-tip="<?php _e( 'Discounts after tax - user defined.', 'woocommerce' ); ?>" href="#">[?]</a></label>
<input type="number" step="any" min="0" id="_order_discount" name="_order_discount" placeholder="0.00" value="<?php <input type="number" step="any" min="0" id="_order_discount" name="_order_discount" placeholder="0.00" value="<?php
if ( isset( $data['_order_discount'][0] ) ) if ( isset( $data['_order_discount'][0] ) )
echo esc_attr( $data['_order_discount'][0] ); echo esc_attr( $data['_order_discount'][0] );
?>" /> ?>" />
</li> </li>
@ -509,19 +509,19 @@ function woocommerce_order_totals_meta_box( $post ) {
<div class="totals_group"> <div class="totals_group">
<h4><?php _e( 'Shipping', 'woocommerce' ); ?></h4> <h4><?php _e( 'Shipping', 'woocommerce' ); ?></h4>
<ul class="totals"> <ul class="totals">
<li class="wide"> <li class="wide">
<label><?php _e( 'Label:', 'woocommerce' ); ?></label> <label><?php _e( 'Label:', 'woocommerce' ); ?></label>
<input type="text" id="_shipping_method_title" name="_shipping_method_title" placeholder="<?php _e( 'The shipping title the customer sees', 'woocommerce' ); ?>" value="<?php <input type="text" id="_shipping_method_title" name="_shipping_method_title" placeholder="<?php _e( 'The shipping title the customer sees', 'woocommerce' ); ?>" value="<?php
if ( isset( $data['_shipping_method_title'][0] ) ) if ( isset( $data['_shipping_method_title'][0] ) )
echo esc_attr( $data['_shipping_method_title'][0] ); echo esc_attr( $data['_shipping_method_title'][0] );
?>" class="first" /> ?>" class="first" />
</li> </li>
<li class="left"> <li class="left">
<label><?php _e( 'Cost:', 'woocommerce' ); ?></label> <label><?php _e( 'Cost:', 'woocommerce' ); ?></label>
<input type="number" step="any" min="0" id="_order_shipping" name="_order_shipping" placeholder="0.00 <?php _e( '(ex. tax)', 'woocommerce' ); ?>" value="<?php <input type="number" step="any" min="0" id="_order_shipping" name="_order_shipping" placeholder="0.00 <?php _e( '(ex. tax)', 'woocommerce' ); ?>" value="<?php
if ( isset( $data['_order_shipping'][0] ) ) if ( isset( $data['_order_shipping'][0] ) )
echo esc_attr( $data['_order_shipping'][0] ); echo esc_attr( $data['_order_shipping'][0] );
?>" class="first" /> ?>" class="first" />
</li> </li>
@ -574,7 +574,7 @@ function woocommerce_order_totals_meta_box( $post ) {
<li class="left"> <li class="left">
<label><?php _e( 'Sales Tax:', 'woocommerce' ); ?>&nbsp;<a class="tips" data-tip="<?php _e( 'Total tax for line items + fees.', 'woocommerce' ); ?>" href="#">[?]</a></label> <label><?php _e( 'Sales Tax:', 'woocommerce' ); ?>&nbsp;<a class="tips" data-tip="<?php _e( 'Total tax for line items + fees.', 'woocommerce' ); ?>" href="#">[?]</a></label>
<input type="number" step="any" min="0" id="_order_tax" name="_order_tax" placeholder="0.00" value="<?php <input type="number" step="any" min="0" id="_order_tax" name="_order_tax" placeholder="0.00" value="<?php
if ( isset( $data['_order_tax'][0] ) ) if ( isset( $data['_order_tax'][0] ) )
echo esc_attr( $data['_order_tax'][0] ); echo esc_attr( $data['_order_tax'][0] );
?>" class="calculated" /> ?>" class="calculated" />
</li> </li>
@ -582,7 +582,7 @@ function woocommerce_order_totals_meta_box( $post ) {
<li class="right"> <li class="right">
<label><?php _e( 'Shipping Tax:', 'woocommerce' ); ?></label> <label><?php _e( 'Shipping Tax:', 'woocommerce' ); ?></label>
<input type="number" step="any" min="0" id="_order_shipping_tax" name="_order_shipping_tax" placeholder="0.00" value="<?php <input type="number" step="any" min="0" id="_order_shipping_tax" name="_order_shipping_tax" placeholder="0.00" value="<?php
if ( isset( $data['_order_shipping_tax'][0] ) ) if ( isset( $data['_order_shipping_tax'][0] ) )
echo esc_attr( $data['_order_shipping_tax'][0] ); echo esc_attr( $data['_order_shipping_tax'][0] );
?>" /> ?>" />
</li> </li>
@ -597,7 +597,7 @@ function woocommerce_order_totals_meta_box( $post ) {
<li class="left"> <li class="left">
<label><?php _e( 'Order Total:', 'woocommerce' ); ?></label> <label><?php _e( 'Order Total:', 'woocommerce' ); ?></label>
<input type="number" step="any" min="0" id="_order_total" name="_order_total" placeholder="0.00" value="<?php <input type="number" step="any" min="0" id="_order_total" name="_order_total" placeholder="0.00" value="<?php
if ( isset( $data['_order_total'][0] ) ) if ( isset( $data['_order_total'][0] ) )
echo esc_attr( $data['_order_total'][0] ); echo esc_attr( $data['_order_total'][0] );
?>" class="calculated" /> ?>" class="calculated" />
</li> </li>
@ -733,95 +733,95 @@ function woocommerce_process_shop_order_meta( $post_id, $post ) {
// Tax rows // Tax rows
if ( isset( $_POST['order_taxes_id'] ) ) { if ( isset( $_POST['order_taxes_id'] ) ) {
$get_values = array( 'order_taxes_id', 'order_taxes_label', 'order_taxes_compound', 'order_taxes_amount', 'order_taxes_shipping_amount' ); $get_values = array( 'order_taxes_id', 'order_taxes_label', 'order_taxes_compound', 'order_taxes_amount', 'order_taxes_shipping_amount' );
foreach( $get_values as $value ) foreach( $get_values as $value )
$$value = isset( $_POST[ $value ] ) ? $_POST[ $value ] : array(); $$value = isset( $_POST[ $value ] ) ? $_POST[ $value ] : array();
foreach( $order_taxes_id as $item_id ) { foreach( $order_taxes_id as $item_id ) {
$item_id = absint( $item_id ); $item_id = absint( $item_id );
if ( ! $order_taxes_label[ $item_id ] ) if ( ! $order_taxes_label[ $item_id ] )
$order_taxes_label[ $item_id ] = $woocommerce->countries->tax_or_vat(); $order_taxes_label[ $item_id ] = $woocommerce->countries->tax_or_vat();
if ( isset( $order_taxes_label[ $item_id ] ) ) if ( isset( $order_taxes_label[ $item_id ] ) )
$wpdb->update( $wpdb->update(
$wpdb->prefix . "woocommerce_order_items", $wpdb->prefix . "woocommerce_order_items",
array( 'order_item_name' => woocommerce_clean( $order_taxes_label[ $item_id ] ) ), array( 'order_item_name' => woocommerce_clean( $order_taxes_label[ $item_id ] ) ),
array( 'order_item_id' => $item_id ), array( 'order_item_id' => $item_id ),
array( '%s' ), array( '%s' ),
array( '%d' ) array( '%d' )
); );
if ( isset( $order_taxes_compound[ $item_id ] ) ) if ( isset( $order_taxes_compound[ $item_id ] ) )
woocommerce_update_order_item_meta( $item_id, 'compound', isset( $order_taxes_compound[ $item_id ] ) ? 1 : 0 ); woocommerce_update_order_item_meta( $item_id, 'compound', isset( $order_taxes_compound[ $item_id ] ) ? 1 : 0 );
if ( isset( $order_taxes_amount[ $item_id ] ) ) if ( isset( $order_taxes_amount[ $item_id ] ) )
woocommerce_update_order_item_meta( $item_id, 'tax_amount', woocommerce_clean( $order_taxes_amount[ $item_id ] ) ); woocommerce_update_order_item_meta( $item_id, 'tax_amount', woocommerce_clean( $order_taxes_amount[ $item_id ] ) );
if ( isset( $order_taxes_shipping_amount[ $item_id ] ) ) if ( isset( $order_taxes_shipping_amount[ $item_id ] ) )
woocommerce_update_order_item_meta( $item_id, 'shipping_tax_amount', woocommerce_clean( $order_taxes_shipping_amount[ $item_id ] ) ); woocommerce_update_order_item_meta( $item_id, 'shipping_tax_amount', woocommerce_clean( $order_taxes_shipping_amount[ $item_id ] ) );
} }
} }
// Order items + fees // Order items + fees
if ( isset( $_POST['order_item_id'] ) ) { if ( isset( $_POST['order_item_id'] ) ) {
$get_values = array( 'order_item_id', 'order_item_name', 'order_item_qty', 'line_subtotal', 'line_subtotal_tax', 'line_total', 'line_tax', 'order_item_tax_class' ); $get_values = array( 'order_item_id', 'order_item_name', 'order_item_qty', 'line_subtotal', 'line_subtotal_tax', 'line_total', 'line_tax', 'order_item_tax_class' );
foreach( $get_values as $value ) foreach( $get_values as $value )
$$value = isset( $_POST[ $value ] ) ? $_POST[ $value ] : array(); $$value = isset( $_POST[ $value ] ) ? $_POST[ $value ] : array();
foreach ( $order_item_id as $item_id ) { foreach ( $order_item_id as $item_id ) {
$item_id = absint( $item_id ); $item_id = absint( $item_id );
if ( isset( $order_item_name[ $item_id ] ) ) if ( isset( $order_item_name[ $item_id ] ) )
$wpdb->update( $wpdb->update(
$wpdb->prefix . "woocommerce_order_items", $wpdb->prefix . "woocommerce_order_items",
array( 'order_item_name' => woocommerce_clean( $order_item_name[ $item_id ] ) ), array( 'order_item_name' => woocommerce_clean( $order_item_name[ $item_id ] ) ),
array( 'order_item_id' => $item_id ), array( 'order_item_id' => $item_id ),
array( '%s' ), array( '%s' ),
array( '%d' ) array( '%d' )
); );
if ( isset( $order_item_qty[ $item_id ] ) ) if ( isset( $order_item_qty[ $item_id ] ) )
woocommerce_update_order_item_meta( $item_id, '_qty', apply_filters( 'woocommerce_stock_amount', $order_item_qty[ $item_id ] ) ); woocommerce_update_order_item_meta( $item_id, '_qty', apply_filters( 'woocommerce_stock_amount', $order_item_qty[ $item_id ] ) );
if ( isset( $item_tax_class[ $item_id ] ) ) if ( isset( $item_tax_class[ $item_id ] ) )
woocommerce_update_order_item_meta( $item_id, '_tax_class', woocommerce_clean( $item_tax_class[ $item_id ] ) ); woocommerce_update_order_item_meta( $item_id, '_tax_class', woocommerce_clean( $item_tax_class[ $item_id ] ) );
if ( isset( $line_subtotal[ $item_id ] ) ) if ( isset( $line_subtotal[ $item_id ] ) )
woocommerce_update_order_item_meta( $item_id, '_line_subtotal', woocommerce_clean( $line_subtotal[ $item_id ] ) ); woocommerce_update_order_item_meta( $item_id, '_line_subtotal', woocommerce_clean( $line_subtotal[ $item_id ] ) );
if ( isset( $line_subtotal_tax[ $item_id ] ) ) if ( isset( $line_subtotal_tax[ $item_id ] ) )
woocommerce_update_order_item_meta( $item_id, '_line_subtotal_tax', woocommerce_clean( $line_subtotal_tax[ $item_id ] ) ); woocommerce_update_order_item_meta( $item_id, '_line_subtotal_tax', woocommerce_clean( $line_subtotal_tax[ $item_id ] ) );
if ( isset( $line_total[ $item_id ] ) ) if ( isset( $line_total[ $item_id ] ) )
woocommerce_update_order_item_meta( $item_id, '_line_total', woocommerce_clean( $line_total[ $item_id ] ) ); woocommerce_update_order_item_meta( $item_id, '_line_total', woocommerce_clean( $line_total[ $item_id ] ) );
if ( isset( $line_tax[ $item_id ] ) ) if ( isset( $line_tax[ $item_id ] ) )
woocommerce_update_order_item_meta( $item_id, '_line_tax', woocommerce_clean( $line_tax[ $item_id ] ) ); woocommerce_update_order_item_meta( $item_id, '_line_tax', woocommerce_clean( $line_tax[ $item_id ] ) );
} }
} }
// Save meta // Save meta
$meta_keys = isset( $_POST['meta_key'] ) ? $_POST['meta_key'] : ''; $meta_keys = isset( $_POST['meta_key'] ) ? $_POST['meta_key'] : '';
$meta_values = isset( $_POST['meta_value'] ) ? $_POST['meta_value'] : ''; $meta_values = isset( $_POST['meta_value'] ) ? $_POST['meta_value'] : '';
foreach ( $meta_keys as $id => $value ) { foreach ( $meta_keys as $id => $value ) {
$wpdb->update( $wpdb->update(
$wpdb->prefix . "woocommerce_order_itemmeta", $wpdb->prefix . "woocommerce_order_itemmeta",
array( array(
'meta_key' => $value, 'meta_key' => $value,
'meta_value' => empty( $meta_values[ $id ] ) ? '' : $meta_values[ $id ] 'meta_value' => empty( $meta_values[ $id ] ) ? '' : $meta_values[ $id ]
), ),
array( 'meta_id' => $id ), array( 'meta_id' => $id ),
array( '%s', '%s' ), array( '%s', '%s' ),
array( '%d' ) array( '%d' )
); );
} }
@ -830,7 +830,7 @@ function woocommerce_process_shop_order_meta( $post_id, $post ) {
// Order status // Order status
$order->update_status( $_POST['order_status'] ); $order->update_status( $_POST['order_status'] );
// Handle button actions // Handle button actions
if ( ! empty( $_POST['order_email'] ) ) { if ( ! empty( $_POST['order_email'] ) ) {

View File

@ -41,12 +41,12 @@ function woocommerce_order_downloads_meta_box() {
} }
// don't show permissions to files that have since been removed // don't show permissions to files that have since been removed
if ( ! $product->exists() || ! $product->has_file( $download->download_id ) ) if ( ! $product->exists() || ! $product->has_file( $download->download_id ) )
continue; continue;
$loop++; $loop++;
$file_count++; $file_count++;
include( 'order-download-permission-html.php' ); include( 'order-download-permission-html.php' );
} }
?> ?>
@ -77,7 +77,7 @@ function woocommerce_order_downloads_meta_box() {
$sku = get_post_meta( $product->ID, '_sku', true ); $sku = get_post_meta( $product->ID, '_sku', true );
if ( $sku ) if ( $sku )
$sku = ' SKU: ' . $sku; $sku = ' SKU: ' . $sku;
echo '<option value="' . esc_attr( $product->ID ) . '">' . esc_html( $product->post_title . ' (#' . $product->ID . '' . $sku . ')' ) . '</option>'; echo '<option value="' . esc_attr( $product->ID ) . '">' . esc_html( $product->post_title . ' (#' . $product->ID . '' . $sku . ')' ) . '</option>';
@ -123,9 +123,9 @@ function woocommerce_order_downloads_meta_box() {
jQuery('.order_download_permissions .wc-metaboxes').append( response ); jQuery('.order_download_permissions .wc-metaboxes').append( response );
} else { } else {
alert('<?php _e( 'Could not grant access - the user may already have permission for this file.', 'woocommerce' ); ?>'); alert('<?php _e( 'Could not grant access - the user may already have permission for this file.', 'woocommerce' ); ?>');
} }
jQuery( ".date-picker" ).datepicker({ jQuery( ".date-picker" ).datepicker({
@ -215,7 +215,7 @@ function woocommerce_order_downloads_save( $post_id, $post ) {
$customer_email = get_post_meta( $post->ID, '_billing_email', true ); $customer_email = get_post_meta( $post->ID, '_billing_email', true );
$customer_user = get_post_meta( $post->ID, '_customer_user', true ); $customer_user = get_post_meta( $post->ID, '_customer_user', true );
$product_ids_count = sizeof( $product_ids ); $product_ids_count = sizeof( $product_ids );
for ( $i = 0; $i < $product_ids_count; $i ++ ) { for ( $i = 0; $i < $product_ids_count; $i ++ ) {
$data = array( $data = array(
@ -239,8 +239,8 @@ function woocommerce_order_downloads_save( $post_id, $post ) {
'order_id' => $post_id, 'order_id' => $post_id,
'product_id' => absint( $product_ids[$i] ), 'product_id' => absint( $product_ids[$i] ),
'download_id' => woocommerce_clean( $download_ids[$i] ) 'download_id' => woocommerce_clean( $download_ids[$i] )
), ),
$format, array( '%d', '%d', '%s' ) $format, array( '%d', '%d', '%s' )
); );
} }

View File

@ -34,7 +34,7 @@ function woocommerce_order_notes_meta_box() {
if ( $notes ) { if ( $notes ) {
foreach( $notes as $note ) { foreach( $notes as $note ) {
$note_classes = get_comment_meta( $note->comment_ID, 'is_customer_note', true ) ? array( 'customer-note', 'note' ) : array( 'note' ); $note_classes = get_comment_meta( $note->comment_ID, 'is_customer_note', true ) ? array( 'customer-note', 'note' ) : array( 'note' );
?> ?>
<li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo implode( ' ', $note_classes ); ?>"> <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo implode( ' ', $note_classes ); ?>">
<div class="note_content"> <div class="note_content">

View File

@ -52,7 +52,7 @@ function variable_product_type_options() {
$tax_class_options = array(); $tax_class_options = array();
$tax_class_options['parent'] = __( 'Same as parent', 'woocommerce' ); $tax_class_options['parent'] = __( 'Same as parent', 'woocommerce' );
$tax_class_options[''] = __( 'Standard', 'woocommerce' ); $tax_class_options[''] = __( 'Standard', 'woocommerce' );
if ( $tax_classes ) if ( $tax_classes )
foreach ( $tax_classes as $class ) foreach ( $tax_classes as $class )
$tax_class_options[ sanitize_title( $class ) ] = esc_attr( $class ); $tax_class_options[ sanitize_title( $class ) ] = esc_attr( $class );
?> ?>
@ -103,19 +103,19 @@ function variable_product_type_options() {
'height' => get_post_meta( $post->ID, '_height', true ), 'height' => get_post_meta( $post->ID, '_height', true ),
'tax_class' => get_post_meta( $post->ID, '_tax_class', true ) 'tax_class' => get_post_meta( $post->ID, '_tax_class', true )
); );
if ( ! $parent_data['weight'] ) if ( ! $parent_data['weight'] )
$parent_data['weight'] = '0.00'; $parent_data['weight'] = '0.00';
if ( ! $parent_data['length'] ) if ( ! $parent_data['length'] )
$parent_data['length'] = '0'; $parent_data['length'] = '0';
if ( ! $parent_data['width'] ) if ( ! $parent_data['width'] )
$parent_data['width'] = '0'; $parent_data['width'] = '0';
if ( ! $parent_data['height'] ) if ( ! $parent_data['height'] )
$parent_data['height'] = '0'; $parent_data['height'] = '0';
// Get variations // Get variations
$args = array( $args = array(
'post_type' => 'product_variation', 'post_type' => 'product_variation',
@ -128,19 +128,19 @@ function variable_product_type_options() {
$variations = get_posts( $args ); $variations = get_posts( $args );
$loop = 0; $loop = 0;
if ( $variations ) foreach ( $variations as $variation ) { if ( $variations ) foreach ( $variations as $variation ) {
$variation_id = absint( $variation->ID ); $variation_id = absint( $variation->ID );
$variation_post_status = esc_attr( $variation->post_status ); $variation_post_status = esc_attr( $variation->post_status );
$variation_data = get_post_custom( $variation_id ); $variation_data = get_post_custom( $variation_id );
$variation_data['variation_post_id'] = $variation_id; $variation_data['variation_post_id'] = $variation_id;
// Grab shipping classes // Grab shipping classes
$shipping_classes = get_the_terms( $variation_id, 'product_shipping_class' ); $shipping_classes = get_the_terms( $variation_id, 'product_shipping_class' );
$shipping_class = ( $shipping_classes && ! is_wp_error( $shipping_classes ) ) ? current( $shipping_classes )->term_id : ''; $shipping_class = ( $shipping_classes && ! is_wp_error( $shipping_classes ) ) ? current( $shipping_classes )->term_id : '';
$variation_fields = array( $variation_fields = array(
'_sku', '_sku',
'_stock', '_stock',
'_price', '_price',
'_regular_price', '_regular_price',
'_sale_price', '_sale_price',
@ -158,28 +158,28 @@ function variable_product_type_options() {
'_sale_price_dates_from', '_sale_price_dates_from',
'_sale_price_dates_to' '_sale_price_dates_to'
); );
foreach ( $variation_fields as $field ) foreach ( $variation_fields as $field )
$$field = isset( $variation_data[ $field ][0] ) ? $variation_data[ $field ][0] : ''; $$field = isset( $variation_data[ $field ][0] ) ? $variation_data[ $field ][0] : '';
// Price backwards compat // Price backwards compat
if ( $_regular_price == '' && $_price ) if ( $_regular_price == '' && $_price )
$_regular_price = $_price; $_regular_price = $_price;
// Get image // Get image
$image = ''; $image = '';
$image_id = absint( $_thumbnail_id ); $image_id = absint( $_thumbnail_id );
if ( $image_id ) if ( $image_id )
$image = wp_get_attachment_url( $image_id ); $image = wp_get_attachment_url( $image_id );
// Format file paths // Format file paths
$_file_paths = maybe_unserialize( $_file_paths ); $_file_paths = maybe_unserialize( $_file_paths );
if ( is_array( $_file_paths ) ) if ( is_array( $_file_paths ) )
$_file_paths = implode( "\n", $_file_paths ); $_file_paths = implode( "\n", $_file_paths );
include( 'variation-admin-html.php' ); include( 'variation-admin-html.php' );
$loop++; $loop++;
} }
?> ?>
</div> </div>
@ -196,7 +196,7 @@ function variable_product_type_options() {
foreach ( $attributes as $attribute ) { foreach ( $attributes as $attribute ) {
// Only deal with attributes that are variations // Only deal with attributes that are variations
if ( ! $attribute['is_variation'] ) if ( ! $attribute['is_variation'] )
continue; continue;
// Get current value for variation (if set) // Get current value for variation (if set)
@ -235,9 +235,9 @@ function variable_product_type_options() {
jQuery('#variable_product_options').on('click', 'button.add_variation', function(){ jQuery('#variable_product_options').on('click', 'button.add_variation', function(){
jQuery('.woocommerce_variations').block({ message: null, overlayCSS: { background: '#fff url(<?php echo $woocommerce->plugin_url(); ?>/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } }); jQuery('.woocommerce_variations').block({ message: null, overlayCSS: { background: '#fff url(<?php echo $woocommerce->plugin_url(); ?>/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
var loop = jQuery('.woocommerce_variation').size(); var loop = jQuery('.woocommerce_variation').size();
var data = { var data = {
action: 'woocommerce_add_variation', action: 'woocommerce_add_variation',
post_id: <?php echo $post->ID; ?>, post_id: <?php echo $post->ID; ?>,
@ -248,7 +248,7 @@ function variable_product_type_options() {
jQuery.post('<?php echo admin_url('admin-ajax.php'); ?>', data, function(response) { jQuery.post('<?php echo admin_url('admin-ajax.php'); ?>', data, function(response) {
jQuery('.woocommerce_variations').append( response ); jQuery('.woocommerce_variations').append( response );
jQuery(".tips").tipTip({ jQuery(".tips").tipTip({
'attribute' : 'data-tip', 'attribute' : 'data-tip',
'fadeIn' : 50, 'fadeIn' : 50,
@ -379,7 +379,7 @@ function variable_product_type_options() {
jQuery('a.bulk_edit').click(function() { jQuery('a.bulk_edit').click(function() {
var field_to_edit = jQuery('select#field_to_edit').val(); var field_to_edit = jQuery('select#field_to_edit').val();
var input_tag = jQuery('select#field_to_edit :selected').attr('rel') ? jQuery('select#field_to_edit :selected').attr('rel') : 'input'; var input_tag = jQuery('select#field_to_edit :selected').attr('rel') ? jQuery('select#field_to_edit :selected').attr('rel') : 'input';
var value = prompt("<?php _e( 'Enter a value', 'woocommerce' ); ?>"); var value = prompt("<?php _e( 'Enter a value', 'woocommerce' ); ?>");
jQuery(input_tag + '[name^="' + field_to_edit + '"]').val( value ); jQuery(input_tag + '[name^="' + field_to_edit + '"]').val( value );
return false; return false;
@ -572,7 +572,7 @@ function process_product_meta_variable( $post_id ) {
for ( $i = 0; $i <= $max_loop; $i ++ ) { for ( $i = 0; $i <= $max_loop; $i ++ ) {
if ( ! isset( $variable_post_id[ $i ] ) ) if ( ! isset( $variable_post_id[ $i ] ) )
continue; continue;
$variation_id = absint( $variable_post_id[ $i ] ); $variation_id = absint( $variable_post_id[ $i ] );
@ -599,15 +599,15 @@ function process_product_meta_variable( $post_id ) {
'post_type' => 'product_variation', 'post_type' => 'product_variation',
'menu_order' => $variable_menu_order[ $i ] 'menu_order' => $variable_menu_order[ $i ]
); );
$variation_id = wp_insert_post( $variation ); $variation_id = wp_insert_post( $variation );
do_action( 'woocommerce_create_product_variation', $variation_id ); do_action( 'woocommerce_create_product_variation', $variation_id );
} else { } else {
$wpdb->update( $wpdb->posts, array( 'post_status' => $post_status, 'post_title' => $variation_post_title, 'menu_order' => $variable_menu_order[ $i ] ), array( 'ID' => $variation_id ) ); $wpdb->update( $wpdb->posts, array( 'post_status' => $post_status, 'post_title' => $variation_post_title, 'menu_order' => $variable_menu_order[ $i ] ), array( 'ID' => $variation_id ) );
do_action( 'woocommerce_update_product_variation', $variation_id ); do_action( 'woocommerce_update_product_variation', $variation_id );
} }
@ -625,22 +625,22 @@ function process_product_meta_variable( $post_id ) {
update_post_meta( $variation_id, '_virtual', woocommerce_clean( $is_virtual ) ); update_post_meta( $variation_id, '_virtual', woocommerce_clean( $is_virtual ) );
update_post_meta( $variation_id, '_downloadable', woocommerce_clean( $is_downloadable ) ); update_post_meta( $variation_id, '_downloadable', woocommerce_clean( $is_downloadable ) );
// Price handling // Price handling
$regular_price = woocommerce_clean( $variable_regular_price[ $i ] ); $regular_price = woocommerce_clean( $variable_regular_price[ $i ] );
$sale_price = woocommerce_clean( $variable_sale_price[ $i ] ); $sale_price = woocommerce_clean( $variable_sale_price[ $i ] );
$date_from = woocommerce_clean( $variable_sale_price_dates_from[ $i ] ); $date_from = woocommerce_clean( $variable_sale_price_dates_from[ $i ] );
$date_to = woocommerce_clean( $variable_sale_price_dates_to[ $i ] ); $date_to = woocommerce_clean( $variable_sale_price_dates_to[ $i ] );
update_post_meta( $variation_id, '_regular_price', $regular_price ); update_post_meta( $variation_id, '_regular_price', $regular_price );
update_post_meta( $variation_id, '_sale_price', $sale_price ); update_post_meta( $variation_id, '_sale_price', $sale_price );
// Save Dates // Save Dates
if ( $date_from ) if ( $date_from )
update_post_meta( $variation_id, '_sale_price_dates_from', strtotime( $date_from ) ); update_post_meta( $variation_id, '_sale_price_dates_from', strtotime( $date_from ) );
else else
update_post_meta( $variation_id, '_sale_price_dates_from', '' ); update_post_meta( $variation_id, '_sale_price_dates_from', '' );
if ( $date_to ) if ( $date_to )
update_post_meta( $variation_id, '_sale_price_dates_to', strtotime( $date_to ) ); update_post_meta( $variation_id, '_sale_price_dates_to', strtotime( $date_to ) );
else else
@ -657,13 +657,13 @@ function process_product_meta_variable( $post_id ) {
if ( $date_from && strtotime( $date_from ) < strtotime( 'NOW', current_time( 'timestamp' ) ) ) if ( $date_from && strtotime( $date_from ) < strtotime( 'NOW', current_time( 'timestamp' ) ) )
update_post_meta( $variation_id, '_price', $sale_price ); update_post_meta( $variation_id, '_price', $sale_price );
if ( $date_to && strtotime( $date_to ) < strtotime( 'NOW', current_time( 'timestamp' ) ) ) { if ( $date_to && strtotime( $date_to ) < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
update_post_meta( $variation_id, '_price', $regular_price ); update_post_meta( $variation_id, '_price', $regular_price );
update_post_meta( $variation_id, '_sale_price_dates_from', '' ); update_post_meta( $variation_id, '_sale_price_dates_from', '' );
update_post_meta( $variation_id, '_sale_price_dates_to', '' ); update_post_meta( $variation_id, '_sale_price_dates_to', '' );
} }
if ( $variable_tax_class[ $i ] !== 'parent' ) if ( $variable_tax_class[ $i ] !== 'parent' )
update_post_meta( $variation_id, '_tax_class', woocommerce_clean( $variable_tax_class[ $i ] ) ); update_post_meta( $variation_id, '_tax_class', woocommerce_clean( $variable_tax_class[ $i ] ) );
else else
@ -672,13 +672,13 @@ function process_product_meta_variable( $post_id ) {
if ( $is_downloadable == 'yes' ) { if ( $is_downloadable == 'yes' ) {
update_post_meta( $variation_id, '_download_limit', woocommerce_clean( $variable_download_limit[ $i ] ) ); update_post_meta( $variation_id, '_download_limit', woocommerce_clean( $variable_download_limit[ $i ] ) );
update_post_meta( $variation_id, '_download_expiry', woocommerce_clean( $variable_download_expiry[ $i ] ) ); update_post_meta( $variation_id, '_download_expiry', woocommerce_clean( $variable_download_expiry[ $i ] ) );
$_file_paths = array(); $_file_paths = array();
$file_paths = str_replace( "\r\n", "\n", $variable_file_paths[ $i ] ); $file_paths = str_replace( "\r\n", "\n", $variable_file_paths[ $i ] );
$file_paths = trim( preg_replace( "/\n+/", "\n", $file_paths ) ); $file_paths = trim( preg_replace( "/\n+/", "\n", $file_paths ) );
if ( $file_paths ) { if ( $file_paths ) {
$file_paths = explode( "\n", $file_paths ); $file_paths = explode( "\n", $file_paths );
foreach ( $file_paths as $file_path ) { foreach ( $file_paths as $file_path ) {
$file_path = woocommerce_clean( $file_path ); $file_path = woocommerce_clean( $file_path );
$_file_paths[ md5( $file_path ) ] = $file_path; $_file_paths[ md5( $file_path ) ] = $file_path;
@ -700,7 +700,7 @@ function process_product_meta_variable( $post_id ) {
wp_set_object_terms( $variation_id, $variable_shipping_class[ $i ], 'product_shipping_class'); wp_set_object_terms( $variation_id, $variable_shipping_class[ $i ], 'product_shipping_class');
// Remove old taxonomies attributes so data is kept up to date // Remove old taxonomies attributes so data is kept up to date
if ( $variation_id ) if ( $variation_id )
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key LIKE %s AND post_id = %d;", 'attribute_%', $variation_id ) ); $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key LIKE %s AND post_id = %d;", 'attribute_%', $variation_id ) );
// Update taxonomies // Update taxonomies
@ -714,7 +714,7 @@ function process_product_meta_variable( $post_id ) {
} }
} }
do_action( 'woocommerce_save_product_variation', $variation_id ); do_action( 'woocommerce_save_product_variation', $variation_id );
} }
@ -740,20 +740,20 @@ function process_product_meta_variable( $post_id ) {
$child_price = get_post_meta( $child, '_price', true ); $child_price = get_post_meta( $child, '_price', true );
$child_regular_price = get_post_meta( $child, '_regular_price', true ); $child_regular_price = get_post_meta( $child, '_regular_price', true );
$child_sale_price = get_post_meta( $child, '_sale_price', true ); $child_sale_price = get_post_meta( $child, '_sale_price', true );
// Regular prices // Regular prices
if ( ! is_numeric( $lowest_regular_price ) || $child_regular_price < $lowest_regular_price ) if ( ! is_numeric( $lowest_regular_price ) || $child_regular_price < $lowest_regular_price )
$lowest_regular_price = $child_regular_price; $lowest_regular_price = $child_regular_price;
if ( ! is_numeric( $highest_regular_price ) || $child_regular_price > $highest_regular_price ) if ( ! is_numeric( $highest_regular_price ) || $child_regular_price > $highest_regular_price )
$highest_regular_price = $child_regular_price; $highest_regular_price = $child_regular_price;
// Sale prices // Sale prices
if ( $child_price == $child_sale_price ) { if ( $child_price == $child_sale_price ) {
if ( $child_sale_price !== '' && ( ! is_numeric( $lowest_sale_price ) || $child_sale_price < $lowest_sale_price ) ) if ( $child_sale_price !== '' && ( ! is_numeric( $lowest_sale_price ) || $child_sale_price < $lowest_sale_price ) )
$lowest_sale_price = $child_sale_price; $lowest_sale_price = $child_sale_price;
if ( $child_sale_price !== '' && ( ! is_numeric( $highest_sale_price ) || $child_sale_price > $highest_sale_price ) ) if ( $child_sale_price !== '' && ( ! is_numeric( $highest_sale_price ) || $child_sale_price > $highest_sale_price ) )
$highest_sale_price = $child_sale_price; $highest_sale_price = $child_sale_price;
} }
} }

View File

@ -9,7 +9,7 @@
* @package WooCommerce/Admin/WritePanels * @package WooCommerce/Admin/WritePanels
* @version 1.7.0 * @version 1.7.0
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/** Variable products */ /** Variable products */
@ -69,9 +69,9 @@ function woocommerce_product_data_box() {
<div class="panel-wrap product_data"> <div class="panel-wrap product_data">
<span class="type_box"> &mdash; <?php echo $type_box; ?></span> <span class="type_box"> &mdash; <?php echo $type_box; ?></span>
<div class="wc-tabs-back"></div> <div class="wc-tabs-back"></div>
<ul class="product_data_tabs wc-tabs" style="display:none;"> <ul class="product_data_tabs wc-tabs" style="display:none;">
<li class="active general_options hide_if_grouped"><a href="#general_product_data"><?php _e( 'General', 'woocommerce' ); ?></a></li> <li class="active general_options hide_if_grouped"><a href="#general_product_data"><?php _e( 'General', 'woocommerce' ); ?></a></li>
@ -146,9 +146,9 @@ function woocommerce_product_data_box() {
// File URL // File URL
$file_paths = get_post_meta( $post->ID, '_file_paths', true ); $file_paths = get_post_meta( $post->ID, '_file_paths', true );
if ( is_array( $file_paths ) ) if ( is_array( $file_paths ) )
$file_paths = implode( "\n", $file_paths ); $file_paths = implode( "\n", $file_paths );
echo '<p class="form-field"><label for="_file_paths">' . __( 'File paths (one per line)', 'woocommerce' ) . ':</label> echo '<p class="form-field"><label for="_file_paths">' . __( 'File paths (one per line)', 'woocommerce' ) . ':</label>
<textarea style="float:left;height:5em;" id="_file_paths" class="short file_paths" cols="20" rows="3" placeholder="' . __( 'File paths/URLs, one per line', 'woocommerce' ) . '" name="_file_paths" wrap="off">' . esc_textarea( $file_paths ) . '</textarea> <textarea style="float:left;height:5em;" id="_file_paths" class="short file_paths" cols="20" rows="3" placeholder="' . __( 'File paths/URLs, one per line', 'woocommerce' ) . '" name="_file_paths" wrap="off">' . esc_textarea( $file_paths ) . '</textarea>
<input type="button" class="upload_file_button button" value="' . __( 'Upload a file', 'woocommerce' ) . '" /> <input type="button" class="upload_file_button button" value="' . __( 'Upload a file', 'woocommerce' ) . '" />
@ -169,27 +169,27 @@ function woocommerce_product_data_box() {
do_action( 'woocommerce_product_options_downloads' ); do_action( 'woocommerce_product_options_downloads' );
echo '</div>'; echo '</div>';
echo '<div class="options_group show_if_simple show_if_variable">'; echo '<div class="options_group show_if_simple show_if_variable">';
// Tax // Tax
woocommerce_wp_select( array( 'id' => '_tax_status', 'label' => __( 'Tax Status', 'woocommerce' ), 'options' => array( woocommerce_wp_select( array( 'id' => '_tax_status', 'label' => __( 'Tax Status', 'woocommerce' ), 'options' => array(
'taxable' => __( 'Taxable', 'woocommerce' ), 'taxable' => __( 'Taxable', 'woocommerce' ),
'shipping' => __( 'Shipping only', 'woocommerce' ), 'shipping' => __( 'Shipping only', 'woocommerce' ),
'none' => __( 'None', 'woocommerce' ) 'none' => __( 'None', 'woocommerce' )
) ) ); ) ) );
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option( 'woocommerce_tax_classes' ) ) ) ); $tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option( 'woocommerce_tax_classes' ) ) ) );
$classes_options = array(); $classes_options = array();
$classes_options[''] = __( 'Standard', 'woocommerce' ); $classes_options[''] = __( 'Standard', 'woocommerce' );
if ( $tax_classes ) if ( $tax_classes )
foreach ( $tax_classes as $class ) foreach ( $tax_classes as $class )
$classes_options[ sanitize_title( $class ) ] = esc_html( $class ); $classes_options[ sanitize_title( $class ) ] = esc_html( $class );
woocommerce_wp_select( array( 'id' => '_tax_class', 'label' => __( 'Tax Class', 'woocommerce' ), 'options' => $classes_options ) ); woocommerce_wp_select( array( 'id' => '_tax_class', 'label' => __( 'Tax Class', 'woocommerce' ), 'options' => $classes_options ) );
do_action( 'woocommerce_product_options_tax' ); do_action( 'woocommerce_product_options_tax' );
echo '</div>'; echo '</div>';
do_action( 'woocommerce_product_options_general_product_data' ); do_action( 'woocommerce_product_options_general_product_data' );
@ -199,7 +199,7 @@ function woocommerce_product_data_box() {
<div id="inventory_product_data" class="panel woocommerce_options_panel"> <div id="inventory_product_data" class="panel woocommerce_options_panel">
<?php <?php
echo '<div class="options_group">'; echo '<div class="options_group">';
if (get_option('woocommerce_manage_stock')=='yes') { if (get_option('woocommerce_manage_stock')=='yes') {
@ -242,9 +242,9 @@ function woocommerce_product_data_box() {
echo '</div>'; echo '</div>';
} }
echo '</div>'; echo '</div>';
echo '<div class="options_group show_if_simple show_if_variable">'; echo '<div class="options_group show_if_simple show_if_variable">';
// Individual product // Individual product
@ -259,11 +259,11 @@ function woocommerce_product_data_box() {
</div> </div>
<div id="shipping_product_data" class="panel woocommerce_options_panel"> <div id="shipping_product_data" class="panel woocommerce_options_panel">
<?php <?php
echo '<div class="options_group">'; echo '<div class="options_group">';
// Weight // Weight
if( get_option('woocommerce_enable_weight', true) !== 'no' ) : if( get_option('woocommerce_enable_weight', true) !== 'no' ) :
woocommerce_wp_text_input( array( 'id' => '_weight', 'label' => __( 'Weight', 'woocommerce' ) . ' ('.get_option('woocommerce_weight_unit').')', 'placeholder' => '0.00', 'description' => __( 'Weight in decimal form', 'woocommerce' ), 'type' => 'number', 'custom_attributes' => array( woocommerce_wp_text_input( array( 'id' => '_weight', 'label' => __( 'Weight', 'woocommerce' ) . ' ('.get_option('woocommerce_weight_unit').')', 'placeholder' => '0.00', 'description' => __( 'Weight in decimal form', 'woocommerce' ), 'type' => 'number', 'custom_attributes' => array(
@ -294,7 +294,7 @@ function woocommerce_product_data_box() {
do_action( 'woocommerce_product_options_dimensions' ); do_action( 'woocommerce_product_options_dimensions' );
echo '</div>'; echo '</div>';
echo '<div class="options_group">'; echo '<div class="options_group">';
// Shipping Class // Shipping Class
@ -313,7 +313,7 @@ function woocommerce_product_data_box() {
?><p class="form-field dimensions_field"><label for="product_shipping_class"><?php _e( 'Shipping class', 'woocommerce' ); ?></label> <?php wp_dropdown_categories( $args ); ?> <span class="description"><?php _e( 'Shipping classes are used by certain shipping methods to group similar products.', 'woocommerce' ); ?></span></p><?php ?><p class="form-field dimensions_field"><label for="product_shipping_class"><?php _e( 'Shipping class', 'woocommerce' ); ?></label> <?php wp_dropdown_categories( $args ); ?> <span class="description"><?php _e( 'Shipping classes are used by certain shipping methods to group similar products.', 'woocommerce' ); ?></span></p><?php
do_action( 'woocommerce_product_options_shipping' ); do_action( 'woocommerce_product_options_shipping' );
echo '</div>'; echo '</div>';
?> ?>
@ -344,7 +344,7 @@ function woocommerce_product_data_box() {
if ( ! taxonomy_exists( $attribute_taxonomy_name ) ) continue; if ( ! taxonomy_exists( $attribute_taxonomy_name ) ) continue;
// Get product data values for current taxonomy - this contains ordering and visibility data // Get product data values for current taxonomy - this contains ordering and visibility data
if ( isset( $attributes[ $attribute_taxonomy_name ] ) ) if ( isset( $attributes[ $attribute_taxonomy_name ] ) )
$attribute = $attributes[ $attribute_taxonomy_name ]; $attribute = $attributes[ $attribute_taxonomy_name ];
$position = empty( $attribute['position'] ) ? 0 : absint( $attribute['position'] ); $position = empty( $attribute['position'] ) ? 0 : absint( $attribute['position'] );
@ -487,14 +487,14 @@ function woocommerce_product_data_box() {
} }
?> ?>
</select> </select>
<button type="button" class="button save_attributes"><?php _e( 'Save attributes', 'woocommerce' ); ?></button> <button type="button" class="button save_attributes"><?php _e( 'Save attributes', 'woocommerce' ); ?></button>
</p> </p>
</div> </div>
<div id="linked_product_data" class="panel woocommerce_options_panel"> <div id="linked_product_data" class="panel woocommerce_options_panel">
<div class="options_group"> <div class="options_group">
<p class="form-field"><label for="upsell_ids"><?php _e( 'Up-Sells', 'woocommerce' ); ?></label> <p class="form-field"><label for="upsell_ids"><?php _e( 'Up-Sells', 'woocommerce' ); ?></label>
<select id="upsell_ids" name="upsell_ids[]" class="ajax_chosen_select_products" multiple="multiple" data-placeholder="<?php _e( 'Search for a product&hellip;', 'woocommerce' ); ?>"> <select id="upsell_ids" name="upsell_ids[]" class="ajax_chosen_select_products" multiple="multiple" data-placeholder="<?php _e( 'Search for a product&hellip;', 'woocommerce' ); ?>">
<?php <?php
@ -503,11 +503,11 @@ function woocommerce_product_data_box() {
foreach ( $product_ids as $product_id ) { foreach ( $product_ids as $product_id ) {
$title = get_the_title( $product_id ); $title = get_the_title( $product_id );
$sku = get_post_meta( $product_id, '_sku', true ); $sku = get_post_meta( $product_id, '_sku', true );
if ( ! $title ) if ( ! $title )
continue; continue;
if ( ! empty( $sku ) ) if ( ! empty( $sku ) )
$sku = ' (SKU: ' . $sku . ')'; $sku = ' (SKU: ' . $sku . ')';
echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $title . $sku ) . '</option>'; echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $title . $sku ) . '</option>';
@ -524,11 +524,11 @@ function woocommerce_product_data_box() {
foreach ( $product_ids as $product_id ) { foreach ( $product_ids as $product_id ) {
$title = get_the_title( $product_id ); $title = get_the_title( $product_id );
$sku = get_post_meta( $product_id, '_sku', true ); $sku = get_post_meta( $product_id, '_sku', true );
if ( ! $title ) if ( ! $title )
continue; continue;
if ( ! empty( $sku ) ) if ( ! empty( $sku ) )
$sku = ' (SKU: ' . $sku . ')'; $sku = ' (SKU: ' . $sku . ')';
echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $title . $sku ) . '</option>'; echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $title . $sku ) . '</option>';
@ -536,11 +536,11 @@ function woocommerce_product_data_box() {
} }
?> ?>
</select> <img class="help_tip" data-tip='<?php _e( 'Cross-sells are products which you promote in the cart, based on the current product.', 'woocommerce' ) ?>' src="<?php echo $woocommerce->plugin_url(); ?>/assets/images/help.png" /></p> </select> <img class="help_tip" data-tip='<?php _e( 'Cross-sells are products which you promote in the cart, based on the current product.', 'woocommerce' ) ?>' src="<?php echo $woocommerce->plugin_url(); ?>/assets/images/help.png" /></p>
</div> </div>
<?php <?php
echo '<div class="options_group grouping show_if_simple show_if_external">'; echo '<div class="options_group grouping show_if_simple show_if_external">';
// List Grouped products // List Grouped products
@ -563,7 +563,7 @@ function woocommerce_product_data_box() {
if ( $grouped_products ) { if ( $grouped_products ) {
foreach ( $grouped_products as $product ) { foreach ( $grouped_products as $product ) {
if ( $product->ID == $post->ID ) if ( $product->ID == $post->ID )
continue; continue;
$post_parents[ $product->ID ] = $product->post_title; $post_parents[ $product->ID ] = $product->post_title;
@ -572,14 +572,14 @@ function woocommerce_product_data_box() {
} }
woocommerce_wp_select( array( 'id' => 'parent_id', 'label' => __( 'Grouping', 'woocommerce' ), 'value' => absint( $post->post_parent ), 'options' => $post_parents, 'desc_tip' => true, 'description' => __( 'Set this option to make this product part of a grouped product.', 'woocommerce' ) ) ); woocommerce_wp_select( array( 'id' => 'parent_id', 'label' => __( 'Grouping', 'woocommerce' ), 'value' => absint( $post->post_parent ), 'options' => $post_parents, 'desc_tip' => true, 'description' => __( 'Set this option to make this product part of a grouped product.', 'woocommerce' ) ) );
woocommerce_wp_hidden_input( array( 'id' => 'previous_parent_id', 'value' => absint( $post->post_parent ) ) ); woocommerce_wp_hidden_input( array( 'id' => 'previous_parent_id', 'value' => absint( $post->post_parent ) ) );
do_action( 'woocommerce_product_options_grouping' ); do_action( 'woocommerce_product_options_grouping' );
echo '</div>'; echo '</div>';
?> ?>
<?php do_action( 'woocommerce_product_options_related' ); ?> <?php do_action( 'woocommerce_product_options_related' ); ?>
</div> </div>
@ -616,7 +616,7 @@ function woocommerce_product_data_box() {
</div> </div>
<?php do_action( 'woocommerce_product_write_panels' ); ?> <?php do_action( 'woocommerce_product_write_panels' ); ?>
<div class="clear"></div> <div class="clear"></div>
</div> </div>
@ -650,7 +650,7 @@ function woocommerce_process_product_meta( $post_id, $post ) {
// Set transient for product type // Set transient for product type
set_transient( 'wc_product_type_' . $post_id, $product_type ); set_transient( 'wc_product_type_' . $post_id, $product_type );
// Update post meta // Update post meta
update_post_meta( $post_id, '_regular_price', stripslashes( $_POST['_regular_price'] ) ); update_post_meta( $post_id, '_regular_price', stripslashes( $_POST['_regular_price'] ) );
update_post_meta( $post_id, '_sale_price', stripslashes( $_POST['_sale_price'] ) ); update_post_meta( $post_id, '_sale_price', stripslashes( $_POST['_sale_price'] ) );
@ -658,7 +658,7 @@ function woocommerce_process_product_meta( $post_id, $post ) {
update_post_meta( $post_id, '_tax_class', stripslashes( $_POST['_tax_class'] ) ); update_post_meta( $post_id, '_tax_class', stripslashes( $_POST['_tax_class'] ) );
update_post_meta( $post_id, '_visibility', stripslashes( $_POST['_visibility'] ) ); update_post_meta( $post_id, '_visibility', stripslashes( $_POST['_visibility'] ) );
update_post_meta( $post_id, '_purchase_note', stripslashes( $_POST['_purchase_note'] ) ); update_post_meta( $post_id, '_purchase_note', stripslashes( $_POST['_purchase_note'] ) );
update_post_meta( $post_id, '_featured', isset( $_POST['_featured'] ) ? 'yes' : 'no' ); update_post_meta( $post_id, '_featured', isset( $_POST['_featured'] ) ? 'yes' : 'no' );
// Dimensions // Dimensions
if ( $is_virtual == 'no' ) { if ( $is_virtual == 'no' ) {
@ -709,20 +709,20 @@ function woocommerce_process_product_meta( $post_id, $post ) {
if ( isset( $_POST['attribute_names'] ) ) { if ( isset( $_POST['attribute_names'] ) ) {
$attribute_names = $_POST['attribute_names']; $attribute_names = $_POST['attribute_names'];
$attribute_values = $_POST['attribute_values']; $attribute_values = $_POST['attribute_values'];
if ( isset( $_POST['attribute_visibility'] ) ) if ( isset( $_POST['attribute_visibility'] ) )
$attribute_visibility = $_POST['attribute_visibility']; $attribute_visibility = $_POST['attribute_visibility'];
if ( isset( $_POST['attribute_variation'] ) ) if ( isset( $_POST['attribute_variation'] ) )
$attribute_variation = $_POST['attribute_variation']; $attribute_variation = $_POST['attribute_variation'];
$attribute_is_taxonomy = $_POST['attribute_is_taxonomy']; $attribute_is_taxonomy = $_POST['attribute_is_taxonomy'];
$attribute_position = $_POST['attribute_position']; $attribute_position = $_POST['attribute_position'];
$attribute_names_count = sizeof( $attribute_names ); $attribute_names_count = sizeof( $attribute_names );
for ( $i=0; $i < $attribute_names_count; $i++ ) { for ( $i=0; $i < $attribute_names_count; $i++ ) {
if ( ! $attribute_names[ $i ] ) if ( ! $attribute_names[ $i ] )
continue; continue;
$is_visible = isset( $attribute_visibility[ $i ] ) ? 1 : 0; $is_visible = isset( $attribute_visibility[ $i ] ) ? 1 : 0;
@ -800,17 +800,17 @@ function woocommerce_process_product_meta( $post_id, $post ) {
update_post_meta( $post_id, '_product_attributes', $attributes ); update_post_meta( $post_id, '_product_attributes', $attributes );
// Sales and prices // Sales and prices
if ( in_array( $product_type, array( 'variable', 'grouped' ) ) ) { if ( in_array( $product_type, array( 'variable', 'grouped' ) ) ) {
// Variable and grouped products have no prices // Variable and grouped products have no prices
update_post_meta( $post_id, '_regular_price', '' ); update_post_meta( $post_id, '_regular_price', '' );
update_post_meta( $post_id, '_sale_price', '' ); update_post_meta( $post_id, '_sale_price', '' );
update_post_meta( $post_id, '_sale_price_dates_from', '' ); update_post_meta( $post_id, '_sale_price_dates_from', '' );
update_post_meta( $post_id, '_sale_price_dates_to', '' ); update_post_meta( $post_id, '_sale_price_dates_to', '' );
update_post_meta( $post_id, '_price', '' ); update_post_meta( $post_id, '_price', '' );
} else { } else {
$date_from = isset( $_POST['_sale_price_dates_from'] ) ? $_POST['_sale_price_dates_from'] : ''; $date_from = isset( $_POST['_sale_price_dates_from'] ) ? $_POST['_sale_price_dates_from'] : '';
$date_to = isset( $_POST['_sale_price_dates_to'] ) ? $_POST['_sale_price_dates_to'] : ''; $date_to = isset( $_POST['_sale_price_dates_to'] ) ? $_POST['_sale_price_dates_to'] : '';
@ -846,21 +846,21 @@ function woocommerce_process_product_meta( $post_id, $post ) {
// Update parent if grouped so price sorting works and stays in sync with the cheapest child // Update parent if grouped so price sorting works and stays in sync with the cheapest child
if ( $post->post_parent > 0 || $product_type == 'grouped' || $_POST['previous_parent_id'] > 0 ) { if ( $post->post_parent > 0 || $product_type == 'grouped' || $_POST['previous_parent_id'] > 0 ) {
$clear_parent_ids = array(); $clear_parent_ids = array();
if ( $post->post_parent > 0 ) if ( $post->post_parent > 0 )
$clear_parent_ids[] = $post->post_parent; $clear_parent_ids[] = $post->post_parent;
if ( $product_type == 'grouped' ) if ( $product_type == 'grouped' )
$clear_parent_ids[] = $post_id; $clear_parent_ids[] = $post_id;
if ( $_POST['previous_parent_id'] > 0 ) if ( $_POST['previous_parent_id'] > 0 )
$clear_parent_ids[] = absint( $_POST['previous_parent_id'] ); $clear_parent_ids[] = absint( $_POST['previous_parent_id'] );
if ( $clear_parent_ids ) { if ( $clear_parent_ids ) {
foreach( $clear_parent_ids as $clear_id ) { foreach( $clear_parent_ids as $clear_id ) {
$children_by_price = get_posts( array( $children_by_price = get_posts( array(
'post_parent' => $clear_id, 'post_parent' => $clear_id,
'orderby' => 'meta_value_num', 'orderby' => 'meta_value_num',
@ -876,7 +876,7 @@ function woocommerce_process_product_meta( $post_id, $post ) {
update_post_meta( $clear_id, '_price', $child_price ); update_post_meta( $clear_id, '_price', $child_price );
} }
} }
// Clear cache/transients // Clear cache/transients
$woocommerce->clear_product_transients( $clear_id ); $woocommerce->clear_product_transients( $clear_id );
} }
@ -889,7 +889,7 @@ function woocommerce_process_product_meta( $post_id, $post ) {
} else { } else {
update_post_meta( $post_id, '_sold_individually', '' ); update_post_meta( $post_id, '_sold_individually', '' );
} }
// Stock Data // Stock Data
if ( get_option('woocommerce_manage_stock') == 'yes' ) { if ( get_option('woocommerce_manage_stock') == 'yes' ) {
@ -940,7 +940,7 @@ function woocommerce_process_product_meta( $post_id, $post ) {
$upsells = array(); $upsells = array();
$ids = $_POST['upsell_ids']; $ids = $_POST['upsell_ids'];
foreach ( $ids as $id ) foreach ( $ids as $id )
if ( $id && $id > 0 ) if ( $id && $id > 0 )
$upsells[] = $id; $upsells[] = $id;
update_post_meta( $post_id, '_upsell_ids', $upsells ); update_post_meta( $post_id, '_upsell_ids', $upsells );
@ -953,9 +953,9 @@ function woocommerce_process_product_meta( $post_id, $post ) {
$crosssells = array(); $crosssells = array();
$ids = $_POST['crosssell_ids']; $ids = $_POST['crosssell_ids'];
foreach ( $ids as $id ) foreach ( $ids as $id )
if ( $id && $id > 0 ) if ( $id && $id > 0 )
$crosssells[] = $id; $crosssells[] = $id;
update_post_meta( $post_id, '_crosssell_ids', $crosssells ); update_post_meta( $post_id, '_crosssell_ids', $crosssells );
} else { } else {
delete_post_meta( $post_id, '_crosssell_ids' ); delete_post_meta( $post_id, '_crosssell_ids' );
@ -965,11 +965,11 @@ function woocommerce_process_product_meta( $post_id, $post ) {
if ( $is_downloadable == 'yes' ) { if ( $is_downloadable == 'yes' ) {
$_download_limit = absint( $_POST['_download_limit'] ); $_download_limit = absint( $_POST['_download_limit'] );
if ( ! $_download_limit ) if ( ! $_download_limit )
$_download_limit = ''; // 0 or blank = unlimited $_download_limit = ''; // 0 or blank = unlimited
$_download_expiry = absint( $_POST['_download_expiry'] ); $_download_expiry = absint( $_POST['_download_expiry'] );
if ( ! $_download_expiry ) if ( ! $_download_expiry )
$_download_expiry = ''; // 0 or blank = unlimited $_download_expiry = ''; // 0 or blank = unlimited
// file paths will be stored in an array keyed off md5(file path) // file paths will be stored in an array keyed off md5(file path)
@ -991,17 +991,17 @@ function woocommerce_process_product_meta( $post_id, $post ) {
update_post_meta( $post_id, '_file_paths', $_file_paths ); update_post_meta( $post_id, '_file_paths', $_file_paths );
} }
if ( isset( $_POST['_download_limit'] ) ) if ( isset( $_POST['_download_limit'] ) )
update_post_meta( $post_id, '_download_limit', esc_attr( $_download_limit ) ); update_post_meta( $post_id, '_download_limit', esc_attr( $_download_limit ) );
if ( isset( $_POST['_download_expiry'] ) ) if ( isset( $_POST['_download_expiry'] ) )
update_post_meta( $post_id, '_download_expiry', esc_attr( $_download_expiry ) ); update_post_meta( $post_id, '_download_expiry', esc_attr( $_download_expiry ) );
} }
// Product url // Product url
if ( $product_type == 'external' ) { if ( $product_type == 'external' ) {
if ( isset( $_POST['_product_url'] ) && $_POST['_product_url'] ) if ( isset( $_POST['_product_url'] ) && $_POST['_product_url'] )
update_post_meta( $post_id, '_product_url', esc_attr( $_POST['_product_url'] ) ); update_post_meta( $post_id, '_product_url', esc_attr( $_POST['_product_url'] ) );
if ( isset( $_POST['_button_text'] ) && $_POST['_button_text'] ) if ( isset( $_POST['_button_text'] ) && $_POST['_button_text'] )
update_post_meta( $post_id, '_button_text', esc_attr( $_POST['_button_text'] ) ); update_post_meta( $post_id, '_button_text', esc_attr( $_POST['_button_text'] ) );
} }
@ -1024,12 +1024,12 @@ add_action('woocommerce_process_product_meta', 'woocommerce_process_product_meta
* @return void * @return void
*/ */
function woocommerce_change_insert_into_post( $translation, $original ) { function woocommerce_change_insert_into_post( $translation, $original ) {
if ( ! isset( $_REQUEST['from'] ) ) if ( ! isset( $_REQUEST['from'] ) )
return $translation; return $translation;
$original = strtolower( $original ); $original = strtolower( $original );
if ( $_REQUEST['from'] == 'wc01' && ( $original == 'insert into post' || $original == 'use this image' ) ) if ( $_REQUEST['from'] == 'wc01' && ( $original == 'insert into post' || $original == 'use this image' ) )
return __( 'Use this file', 'woocommerce' ); return __( 'Use this file', 'woocommerce' );
return $translation; return $translation;

View File

@ -23,30 +23,30 @@ function woocommerce_product_images_box() {
?> ?>
<div id="product_images_container"> <div id="product_images_container">
<ul class="product_images"> <ul class="product_images">
<?php <?php
$thumbnail_id = get_post_thumbnail_id( $post->ID ); $thumbnail_id = get_post_thumbnail_id( $post->ID );
if ( $thumbnail_id ) if ( $thumbnail_id )
echo '<li class="image" data-post_id="' . $thumbnail_id . '"> echo '<li class="image" data-post_id="' . $thumbnail_id . '">
' . wp_get_attachment_image( $thumbnail_id, 'full' ) . ' ' . wp_get_attachment_image( $thumbnail_id, 'full' ) . '
<span class="loading"></span> <span class="loading"></span>
<ul class="actions"> <ul class="actions">
<li><a href="#" class="delete">' . __( 'Delete', 'woocommerce' ) . '</a></li> <li><a href="#" class="delete">' . __( 'Delete', 'woocommerce' ) . '</a></li>
<li><a href="' . admin_url( 'media-upload.php?post_id=' . $post->ID . '&attachment_id=' . $thumbnail_id . '&tab=library&width=640&height=553&TB_iframe=1' ) . '" class="view thickbox" onclick="return false;">' . __( 'View', 'woocommerce' ) . '</a></li> <li><a href="' . admin_url( 'media-upload.php?post_id=' . $post->ID . '&attachment_id=' . $thumbnail_id . '&tab=library&width=640&height=553&TB_iframe=1' ) . '" class="view thickbox" onclick="return false;">' . __( 'View', 'woocommerce' ) . '</a></li>
</ul> </ul>
</li>'; </li>';
$attachments =& get_children( 'post_parent=' . $post->ID . '&numberposts=-1&post_type=attachment&orderby=menu_order&order=ASC&post_mime_type=image' ); $attachments =& get_children( 'post_parent=' . $post->ID . '&numberposts=-1&post_type=attachment&orderby=menu_order&order=ASC&post_mime_type=image' );
foreach ( $attachments as $attachment_id => $attachment ) { foreach ( $attachments as $attachment_id => $attachment ) {
if ( $thumbnail_id == $attachment_id ) if ( $thumbnail_id == $attachment_id )
continue; continue;
$exclude_class = get_post_meta( $attachment_id, '_woocommerce_exclude_image', true ) == 1 ? 'excluded' : ''; $exclude_class = get_post_meta( $attachment_id, '_woocommerce_exclude_image', true ) == 1 ? 'excluded' : '';
echo '<li class="image ' . $exclude_class . '" data-post_id="' . $attachment_id . '"> echo '<li class="image ' . $exclude_class . '" data-post_id="' . $attachment_id . '">
' . wp_get_attachment_image( $attachment_id, 'full' ) . ' ' . wp_get_attachment_image( $attachment_id, 'full' ) . '
<span class="loading"></span> <span class="loading"></span>
<ul class="actions"> <ul class="actions">
<li><a href="#" class="delete">' . __( 'Delete', 'woocommerce' ) . '</a></li> <li><a href="#" class="delete">' . __( 'Delete', 'woocommerce' ) . '</a></li>
<li><a href="' . admin_url( 'media-upload.php?post_id=' . $post->ID . '&attachment_id=' . $attachment_id . '&tab=library&width=640&height=553&TB_iframe=1' ) . '" class="view thickbox" onclick="return false;">' . __( 'View', 'woocommerce' ) . '</a></li> <li><a href="' . admin_url( 'media-upload.php?post_id=' . $post->ID . '&attachment_id=' . $attachment_id . '&tab=library&width=640&height=553&TB_iframe=1' ) . '" class="view thickbox" onclick="return false;">' . __( 'View', 'woocommerce' ) . '</a></li>
@ -56,14 +56,14 @@ function woocommerce_product_images_box() {
?> ?>
</ul> </ul>
</div> </div>
<!-- Uploader section --> <!-- Uploader section -->
<div id="plupload-upload-ui" class="hide-if-no-js"> <div id="plupload-upload-ui" class="hide-if-no-js">
<div id="drag-drop-area"> <div id="drag-drop-area">
<p class="drag-drop-info"><?php _e('Drop files here'); ?></p> <p class="drag-drop-info"><?php _e('Drop files here'); ?></p>
<p><?php _ex('or', 'Uploader: Drop files here - or - Select Files'); ?></p> <p><?php _ex('or', 'Uploader: Drop files here - or - Select Files'); ?></p>
<p class="drag-drop-buttons"><input id="plupload-browse-button" type="button" value="<?php esc_attr_e('Select Files'); ?>" class="button" /></p> <p class="drag-drop-buttons"><input id="plupload-browse-button" type="button" value="<?php esc_attr_e('Select Files'); ?>" class="button" /></p>
</div> </div>
</div> </div>
<?php <?php
// Drag and drop code adapted from Drag & Drop Featured Image by Jonathan Lundström // Drag and drop code adapted from Drag & Drop Featured Image by Jonathan Lundström
@ -72,7 +72,7 @@ function woocommerce_product_images_box() {
'browse_button' => 'plupload-browse-button', 'browse_button' => 'plupload-browse-button',
'container' => 'plupload-upload-ui', 'container' => 'plupload-upload-ui',
'drop_element' => 'drag-drop-area', 'drop_element' => 'drag-drop-area',
'file_data_name' => 'async-upload', 'file_data_name' => 'async-upload',
'multiple_queues' => true, 'multiple_queues' => true,
'max_file_size' => wp_max_upload_size() . 'b', 'max_file_size' => wp_max_upload_size() . 'b',
'url' => admin_url('admin-ajax.php'), 'url' => admin_url('admin-ajax.php'),
@ -89,11 +89,11 @@ function woocommerce_product_images_box() {
); );
// Apply filters to initiate plupload: // Apply filters to initiate plupload:
$plupload_init = apply_filters( 'plupload_init', $plupload_init ); $plupload_init = apply_filters( 'plupload_init', $plupload_init );
?> ?>
<script type="text/javascript"> <script type="text/javascript">
jQuery(document).ready(function($){ jQuery(document).ready(function($){
function product_images_container_init() { function product_images_container_init() {
// Attribute ordering // Attribute ordering
$('#product_images_container ul.product_images').sortable({ $('#product_images_container ul.product_images').sortable({
@ -111,27 +111,27 @@ function woocommerce_product_images_box() {
stop:function(event,ui){ stop:function(event,ui){
ui.item.removeAttr('style'); ui.item.removeAttr('style');
}, },
update: function(event, ui) { update: function(event, ui) {
$('#product_images_container ul li.image').css('cursor','default'); $('#product_images_container ul li.image').css('cursor','default');
$('#product_images_container ul.product_images').sortable('disable'); $('#product_images_container ul.product_images').sortable('disable');
var post_id = <?php echo $post->ID; ?>; var post_id = <?php echo $post->ID; ?>;
var attachment_id = ui.item.attr( 'data-post_id' ); var attachment_id = ui.item.attr( 'data-post_id' );
var prev_attachment_id = ui.item.prev().attr( 'data-post_id' ); var prev_attachment_id = ui.item.prev().attr( 'data-post_id' );
var next_attachment_id = ui.item.next().attr( 'data-post_id' ); var next_attachment_id = ui.item.next().attr( 'data-post_id' );
// show spinner // show spinner
ui.item.addClass('loading'); ui.item.addClass('loading');
// go do the sorting stuff via ajax // go do the sorting stuff via ajax
jQuery.post( ajaxurl, { jQuery.post( ajaxurl, {
action: 'woocommerce_product_image_ordering', action: 'woocommerce_product_image_ordering',
post_id: post_id, post_id: post_id,
attachment_id: attachment_id, attachment_id: attachment_id,
prev_attachment_id: prev_attachment_id, prev_attachment_id: prev_attachment_id,
next_attachment_id: next_attachment_id, next_attachment_id: next_attachment_id,
_ajax_nonce: '<?php echo wp_create_nonce( 'product-image-ordering' ); ?>' _ajax_nonce: '<?php echo wp_create_nonce( 'product-image-ordering' ); ?>'
}, function( response ) { }, function( response ) {
ui.item.removeClass('loading'); ui.item.removeClass('loading');
$('#product_images_container ul li.image').css('cursor','move'); $('#product_images_container ul li.image').css('cursor','move');
$('#product_images_container ul.product_images').sortable('enable'); $('#product_images_container ul.product_images').sortable('enable');
@ -140,51 +140,51 @@ function woocommerce_product_images_box() {
} }
}); });
} }
product_images_container_init(); product_images_container_init();
// Delete images // Delete images
$('#product_images_container').on( 'click', 'a.delete', function() { $('#product_images_container').on( 'click', 'a.delete', function() {
$image = $(this).closest('li.image'); $image = $(this).closest('li.image');
var attachment_id = $image.attr('data-post_id'); var attachment_id = $image.attr('data-post_id');
if ( attachment_id ) { if ( attachment_id ) {
$image.addClass('loading'); $image.addClass('loading');
var answer = confirm('<?php _e( 'Are you sure you want to remove this attachment?', 'woocommerce' ); ?>'); var answer = confirm('<?php _e( 'Are you sure you want to remove this attachment?', 'woocommerce' ); ?>');
if ( answer ) { if ( answer ) {
jQuery.post( ajaxurl, { jQuery.post( ajaxurl, {
action: 'woocommerce_product_image_delete', action: 'woocommerce_product_image_delete',
post_id: <?php echo $post->ID; ?>, post_id: <?php echo $post->ID; ?>,
attachment_id: attachment_id, attachment_id: attachment_id,
_ajax_nonce: '<?php echo wp_create_nonce( 'product-image-delete' ); ?>' _ajax_nonce: '<?php echo wp_create_nonce( 'product-image-delete' ); ?>'
}, function( response ) { }, function( response ) {
$image.remove(); $image.remove();
} }
); );
} else { } else {
$image.removeClass('loading'); $image.removeClass('loading');
} }
} }
return false; return false;
} ); } );
// Drag and drop uploading of images // Drag and drop uploading of images
var uploader = new plupload.Uploader(<?php echo json_encode( $plupload_init ); ?>); var uploader = new plupload.Uploader(<?php echo json_encode( $plupload_init ); ?>);
// Check for drag'n'drop functionality: // Check for drag'n'drop functionality:
uploader.bind('Init', function(up){ uploader.bind('Init', function(up){
var uploaddiv = $('#plupload-upload-ui'); var uploaddiv = $('#plupload-upload-ui');
// Add classes and bind actions: // Add classes and bind actions:
if(up.features.dragdrop){ if(up.features.dragdrop){
uploaddiv.addClass('drag-drop'); uploaddiv.addClass('drag-drop');
@ -200,11 +200,11 @@ function woocommerce_product_images_box() {
// Initiate uploading script: // Initiate uploading script:
uploader.init(); uploader.init();
// File queue handler // File queue handler
uploader.bind('FilesAdded', function(up, files){ uploader.bind('FilesAdded', function(up, files){
var hundredmb = 100 * 1024 * 1024, max = parseInt(up.settings.max_file_size, 10); var hundredmb = 100 * 1024 * 1024, max = parseInt(up.settings.max_file_size, 10);
// Loop through files: // Loop through files:
plupload.each(files, function(file){ plupload.each(files, function(file){
if ( max > hundredmb && file.size > hundredmb && up.runtime != 'html5' ) { if ( max > hundredmb && file.size > hundredmb && up.runtime != 'html5' ) {
@ -215,22 +215,22 @@ function woocommerce_product_images_box() {
// Refresh and start: // Refresh and start:
up.refresh(); up.refresh();
up.start(); up.start();
// Block the UI // Block the UI
$('#product_images_container').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_writepanel_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } }); $('#product_images_container').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_writepanel_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
}); });
// Handle new uploads // Handle new uploads
uploader.bind( 'FileUploaded', function( up, file, response ) { uploader.bind( 'FileUploaded', function( up, file, response ) {
response = $.parseJSON( response.response ); response = $.parseJSON( response.response );
if ( response.error ) { if ( response.error ) {
alert( response.error ); alert( response.error );
} else { } else {
$('#product_images_container ul').append('<li class="image" data-post_id="' + response.post_id + '">\ $('#product_images_container ul').append('<li class="image" data-post_id="' + response.post_id + '">\
<img src="' + response.src + '" />\ <img src="' + response.src + '" />\
<span class="loading"></span>\ <span class="loading"></span>\
@ -239,46 +239,46 @@ function woocommerce_product_images_box() {
<li><a href="' + response.edit_url + '" class="view thickbox" onclick="return false;"><?php _e( 'View', 'woocommerce' ) ?></a></li>\ <li><a href="' + response.edit_url + '" class="view thickbox" onclick="return false;"><?php _e( 'View', 'woocommerce' ) ?></a></li>\
</ul>\ </ul>\
</li>'); </li>');
} }
$('#product_images_container').unblock(); $('#product_images_container').unblock();
}); });
// Refresh images when a thickbox (images) closes // Refresh images when a thickbox (images) closes
var loading_product_images = false; var loading_product_images = false;
jQuery(document).bind( 'tb_unload', function() { jQuery(document).bind( 'tb_unload', function() {
if ( loading_product_images ) if ( loading_product_images )
return; return;
loading_product_images = true; loading_product_images = true;
// Block // Block
$('#product_images_container').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_writepanel_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } }); $('#product_images_container').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_writepanel_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
// Re-load images // Re-load images
jQuery.post( ajaxurl, { jQuery.post( ajaxurl, {
action: 'woocommerce_product_image_refresh', action: 'woocommerce_product_image_refresh',
post_id: <?php echo $post->ID; ?>, post_id: <?php echo $post->ID; ?>,
_ajax_nonce: '<?php echo wp_create_nonce( 'product-image-refresh' ); ?>' _ajax_nonce: '<?php echo wp_create_nonce( 'product-image-refresh' ); ?>'
}, function( response ) { }, function( response ) {
if ( response ) { if ( response ) {
$("#product_images_container").html(response); $("#product_images_container").html(response);
} }
// Re-init // Re-init
product_images_container_init(); product_images_container_init();
// Unblock // Unblock
$('#product_images_container').unblock(); $('#product_images_container').unblock();
loading_product_images = false; loading_product_images = false;
} }
); );
} ); } );
}); });
</script> </script>
<?php <?php

View File

@ -9,7 +9,7 @@
* @package WooCommerce/Admin/WritePanels * @package WooCommerce/Admin/WritePanels
* @version 1.7.0 * @version 1.7.0
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/** Product data writepanel */ /** Product data writepanel */
@ -49,7 +49,7 @@ function woocommerce_meta_boxes() {
remove_meta_box( 'product_shipping_classdiv', 'product', 'side' ); remove_meta_box( 'product_shipping_classdiv', 'product', 'side' );
remove_meta_box( 'pageparentdiv', 'product', 'side' ); remove_meta_box( 'pageparentdiv', 'product', 'side' );
remove_meta_box( 'postimagediv', 'product', 'side' ); remove_meta_box( 'postimagediv', 'product', 'side' );
// Excerpt // Excerpt
if ( function_exists('wp_editor') ) { if ( function_exists('wp_editor') ) {
remove_meta_box( 'postexcerpt', 'product', 'normal' ); remove_meta_box( 'postexcerpt', 'product', 'normal' );
@ -223,9 +223,9 @@ add_filter('wp_insert_post_data', 'woocommerce_order_data');
/** /**
* Grant downloadable file access to any newly added files on any existing * Grant downloadable file access to any newly added files on any existing
* orders for this product that have previously been granted downloadable file access * orders for this product that have previously been granted downloadable file access
* *
* @access public * @access public
* @param int $product_id product identifier * @param int $product_id product identifier
* @param int $variation_id optional product variation identifier * @param int $variation_id optional product variation identifier
@ -234,7 +234,7 @@ add_filter('wp_insert_post_data', 'woocommerce_order_data');
function woocommerce_process_product_file_download_paths( $product_id, $variation_id, $file_paths ) { function woocommerce_process_product_file_download_paths( $product_id, $variation_id, $file_paths ) {
global $wpdb; global $wpdb;
if ( $variation_id ) if ( $variation_id )
$product_id = $variation_id; $product_id = $variation_id;
// determine whether any new files have been added // determine whether any new files have been added
@ -248,10 +248,10 @@ function woocommerce_process_product_file_download_paths( $product_id, $variatio
foreach ( $existing_permissions as $existing_permission ) { foreach ( $existing_permissions as $existing_permission ) {
$order = new WC_Order( $existing_permission->order_id ); $order = new WC_Order( $existing_permission->order_id );
if ( $order->id ) { if ( $order->id ) {
foreach ( $new_download_ids as $new_download_id ) { foreach ( $new_download_ids as $new_download_id ) {
// grant permission if it doesn't already exist // grant permission if it doesn't already exist
if ( ! $wpdb->get_var( $wpdb->prepare( "SELECT true FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE order_id = %d AND product_id = %d AND download_id = %s", $order->id, $product_id, $new_download_id ) ) ) { if ( ! $wpdb->get_var( $wpdb->prepare( "SELECT true FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE order_id = %d AND product_id = %d AND download_id = %s", $order->id, $product_id, $new_download_id ) ) ) {
woocommerce_downloadable_file_permission( $new_download_id, $product_id, $order ); woocommerce_downloadable_file_permission( $new_download_id, $product_id, $order );
} }
} }
@ -313,21 +313,21 @@ add_action( 'admin_notices', 'woocommerce_meta_boxes_show_errors' );
*/ */
function woocommerce_wp_text_input( $field ) { function woocommerce_wp_text_input( $field ) {
global $thepostid, $post, $woocommerce; global $thepostid, $post, $woocommerce;
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
$field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : ''; $field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
$field['class'] = isset( $field['class'] ) ? $field['class'] : 'short'; $field['class'] = isset( $field['class'] ) ? $field['class'] : 'short';
$field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true ); $field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id']; $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
$field['type'] = isset( $field['type'] ) ? $field['type'] : 'text'; $field['type'] = isset( $field['type'] ) ? $field['type'] : 'text';
// Custom attribute handling // Custom attribute handling
$custom_attributes = array(); $custom_attributes = array();
if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) )
foreach ( $field['custom_attributes'] as $attribute => $value ) foreach ( $field['custom_attributes'] as $attribute => $value )
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"'; $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field"><label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label><input type="' . esc_attr( $field['type'] ) . '" class="' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['value'] ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" ' . implode( ' ', $custom_attributes ) . ' /> '; echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field"><label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label><input type="' . esc_attr( $field['type'] ) . '" class="' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['value'] ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" ' . implode( ' ', $custom_attributes ) . ' /> ';
if ( ! empty( $field['description'] ) ) { if ( ! empty( $field['description'] ) ) {
@ -352,11 +352,11 @@ function woocommerce_wp_text_input( $field ) {
*/ */
function woocommerce_wp_hidden_input( $field ) { function woocommerce_wp_hidden_input( $field ) {
global $thepostid, $post; global $thepostid, $post;
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
$field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true ); $field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
$field['class'] = isset( $field['class'] ) ? $field['class'] : ''; $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
echo '<input type="hidden" class="' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['id'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['value'] ) . '" /> '; echo '<input type="hidden" class="' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['id'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['value'] ) . '" /> ';
} }

View File

@ -341,11 +341,11 @@ if ( $shop_page_id > 0 && sizeof(get_pages("child_of=$shop_page_id")) > 0 )
$woocommerce_settings['pages'] = apply_filters('woocommerce_page_settings', array( $woocommerce_settings['pages'] = apply_filters('woocommerce_page_settings', array(
array( array(
'title' => __( 'Page Setup', 'woocommerce' ), 'title' => __( 'Page Setup', 'woocommerce' ),
'type' => 'title', 'type' => 'title',
'desc' => sprintf( __( 'Set up core WooCommerce pages here, for example the base page. The base page can also be used in your %sproduct permalinks%s.', 'woocommerce' ), '<a target="_blank" href="' . admin_url( 'options-permalink.php' ) . '">', '</a>' ), 'desc' => sprintf( __( 'Set up core WooCommerce pages here, for example the base page. The base page can also be used in your %sproduct permalinks%s.', 'woocommerce' ), '<a target="_blank" href="' . admin_url( 'options-permalink.php' ) . '">', '</a>' ),
'id' => 'page_options' 'id' => 'page_options'
), ),
array( array(
@ -515,7 +515,7 @@ $woocommerce_settings['catalog'] = apply_filters('woocommerce_catalog_settings',
)), )),
'desc_tip' => true, 'desc_tip' => true,
), ),
array( array(
'title' => __( 'Shop Page Display', 'woocommerce' ), 'title' => __( 'Shop Page Display', 'woocommerce' ),
'desc' => __( 'This controls what is shown on the product archive.', 'woocommerce' ), 'desc' => __( 'This controls what is shown on the product archive.', 'woocommerce' ),
@ -530,7 +530,7 @@ $woocommerce_settings['catalog'] = apply_filters('woocommerce_catalog_settings',
), ),
'desc_tip' => true, 'desc_tip' => true,
), ),
array( array(
'title' => __( 'Default Category Display', 'woocommerce' ), 'title' => __( 'Default Category Display', 'woocommerce' ),
'desc' => __( 'This controls what is shown on category archives.', 'woocommerce' ), 'desc' => __( 'This controls what is shown on category archives.', 'woocommerce' ),
@ -948,7 +948,7 @@ $woocommerce_settings['payment_gateways'] = apply_filters('woocommerce_payment_g
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option( 'woocommerce_tax_classes' ) ) ) ); $tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option( 'woocommerce_tax_classes' ) ) ) );
$classes_options = array(); $classes_options = array();
if ( $tax_classes ) if ( $tax_classes )
foreach ( $tax_classes as $class ) foreach ( $tax_classes as $class )
$classes_options[ sanitize_title( $class ) ] = esc_html( $class ); $classes_options[ sanitize_title( $class ) ] = esc_html( $class );
@ -963,7 +963,7 @@ $woocommerce_settings['tax'] = apply_filters('woocommerce_tax_settings', array(
'default' => 'no', 'default' => 'no',
'type' => 'checkbox' 'type' => 'checkbox'
), ),
array( array(
'title' => __( 'Calculation Settings', 'woocommerce' ), 'title' => __( 'Calculation Settings', 'woocommerce' ),
'desc' => __( 'Calculate tax based on the customer shipping address', 'woocommerce' ), 'desc' => __( 'Calculate tax based on the customer shipping address', 'woocommerce' ),
@ -972,7 +972,7 @@ $woocommerce_settings['tax'] = apply_filters('woocommerce_tax_settings', array(
'type' => 'checkbox', 'type' => 'checkbox',
'checkboxgroup' => 'start' 'checkboxgroup' => 'start'
), ),
array( array(
'desc' => __( 'Round tax at subtotal level, instead of rounding per line', 'woocommerce' ), 'desc' => __( 'Round tax at subtotal level, instead of rounding per line', 'woocommerce' ),
'id' => 'woocommerce_tax_round_at_subtotal', 'id' => 'woocommerce_tax_round_at_subtotal',
@ -980,7 +980,7 @@ $woocommerce_settings['tax'] = apply_filters('woocommerce_tax_settings', array(
'type' => 'checkbox', 'type' => 'checkbox',
'checkboxgroup' => '' 'checkboxgroup' => ''
), ),
array( array(
'desc' => sprintf( __( 'Display the tax total when tax is %s', 'woocommerce' ), woocommerce_price( 0 ) ), 'desc' => sprintf( __( 'Display the tax total when tax is %s', 'woocommerce' ), woocommerce_price( 0 ) ),
'id' => 'woocommerce_display_cart_taxes_if_zero', 'id' => 'woocommerce_display_cart_taxes_if_zero',
@ -1027,7 +1027,7 @@ $woocommerce_settings['tax'] = apply_filters('woocommerce_tax_settings', array(
'options' => array( '' => 'Shipping tax class based on cart items', 'standard' => __( 'Standard', 'woocommerce' ) ) + $classes_options, 'options' => array( '' => 'Shipping tax class based on cart items', 'standard' => __( 'Standard', 'woocommerce' ) ) + $classes_options,
'desc_tip' => true, 'desc_tip' => true,
), ),
array( array(
'title' => __( 'Additional Tax classes', 'woocommerce' ), 'title' => __( 'Additional Tax classes', 'woocommerce' ),
'desc' => __( 'List additonal tax classes below (1 per line). This is in addition to the default <code>Standard Rate</code>.', 'woocommerce' ), 'desc' => __( 'List additonal tax classes below (1 per line). This is in addition to the default <code>Standard Rate</code>.', 'woocommerce' ),

View File

@ -21,46 +21,46 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
*/ */
function woocommerce_update_options( $options ) { function woocommerce_update_options( $options ) {
if ( empty( $_POST ) ) if ( empty( $_POST ) )
return false; return false;
// Options to update will be stored here // Options to update will be stored here
$update_options = array(); $update_options = array();
// Loop options and get values to save // Loop options and get values to save
foreach ( $options as $value ) { foreach ( $options as $value ) {
if ( ! isset( $value['id'] ) ) if ( ! isset( $value['id'] ) )
continue; continue;
$type = isset( $value['type'] ) ? sanitize_title( $value['type'] ) : ''; $type = isset( $value['type'] ) ? sanitize_title( $value['type'] ) : '';
// Get the option name // Get the option name
$option_value = null; $option_value = null;
switch ( $type ) { switch ( $type ) {
// Standard types // Standard types
case "checkbox" : case "checkbox" :
if ( isset( $_POST[$value['id']] ) ) { if ( isset( $_POST[$value['id']] ) ) {
$option_value = 'yes'; $option_value = 'yes';
} else { } else {
$option_value = 'no'; $option_value = 'no';
} }
break; break;
case "textarea" : case "textarea" :
if ( isset( $_POST[$value['id']] ) ) { if ( isset( $_POST[$value['id']] ) ) {
$option_value = wp_kses_post( $_POST[ $value['id'] ] ); $option_value = wp_kses_post( $_POST[ $value['id'] ] );
} else { } else {
$option_value = ''; $option_value = '';
} }
break; break;
case "text" : case "text" :
case 'email': case 'email':
case 'number': case 'number':
@ -69,7 +69,7 @@ function woocommerce_update_options( $options ) {
case "single_select_page" : case "single_select_page" :
case "single_select_country" : case "single_select_country" :
case 'radio' : case 'radio' :
if ( $value['id'] == 'woocommerce_price_thousand_sep' || $value['id'] == 'woocommerce_price_decimal_sep' ) { if ( $value['id'] == 'woocommerce_price_thousand_sep' || $value['id'] == 'woocommerce_price_decimal_sep' ) {
// price separators get a special treatment as they should allow a spaces (don't trim) // price separators get a special treatment as they should allow a spaces (don't trim)
@ -78,19 +78,19 @@ function woocommerce_update_options( $options ) {
} else { } else {
$option_value = ''; $option_value = '';
} }
} else { } else {
if ( isset( $_POST[$value['id']] ) ) { if ( isset( $_POST[$value['id']] ) ) {
$option_value = woocommerce_clean( $_POST[ $value['id'] ] ); $option_value = woocommerce_clean( $_POST[ $value['id'] ] );
} else { } else {
$option_value = ''; $option_value = '';
} }
} }
break; break;
// Special types // Special types
case "tax_rates" : case "tax_rates" :
@ -104,36 +104,36 @@ function woocommerce_update_options( $options ) {
$tax_compound = isset( $_POST['tax_compound'] ) ? $_POST['tax_compound'] : array(); $tax_compound = isset( $_POST['tax_compound'] ) ? $_POST['tax_compound'] : array();
$tax_label = isset( $_POST['tax_label'] ) ? $_POST['tax_label'] : array(); $tax_label = isset( $_POST['tax_label'] ) ? $_POST['tax_label'] : array();
$tax_classes_count = sizeof( $tax_classes ); $tax_classes_count = sizeof( $tax_classes );
for ( $i = 0; $i < $tax_classes_count; $i ++ ) { for ( $i = 0; $i < $tax_classes_count; $i ++ ) {
if ( isset( $tax_classes[ $i ] ) && isset( $tax_countries[ $i ] ) && isset( $tax_rate[ $i ] ) && is_numeric( $tax_rate[ $i ] ) ) { if ( isset( $tax_classes[ $i ] ) && isset( $tax_countries[ $i ] ) && isset( $tax_rate[ $i ] ) && is_numeric( $tax_rate[ $i ] ) ) {
$rate = woocommerce_clean( $tax_rate[ $i ] ); $rate = woocommerce_clean( $tax_rate[ $i ] );
$rate = number_format( $rate, 4, '.', '' ); $rate = number_format( $rate, 4, '.', '' );
$class = woocommerce_clean( $tax_classes[ $i ] ); $class = woocommerce_clean( $tax_classes[ $i ] );
$shipping = empty( $tax_shipping[ $i ] ) ? 'no' : 'yes'; $shipping = empty( $tax_shipping[ $i ] ) ? 'no' : 'yes';
$compound = empty( $tax_compound[ $i ] ) ? 'no' : 'yes'; $compound = empty( $tax_compound[ $i ] ) ? 'no' : 'yes';
// Handle countries // Handle countries
$counties_array = array(); $counties_array = array();
$countries = $tax_countries[ $i ]; $countries = $tax_countries[ $i ];
if ( $countries ) foreach ( $countries as $country ) { if ( $countries ) foreach ( $countries as $country ) {
$country = woocommerce_clean( $country ); $country = woocommerce_clean( $country );
$state = '*'; $state = '*';
if ( strstr( $country, ':' ) ) { if ( strstr( $country, ':' ) ) {
$cr = explode( ':', $country ); $cr = explode( ':', $country );
$country = current( $cr ); $country = current( $cr );
$state = end( $cr ); $state = end( $cr );
} }
$counties_array[ woocommerce_clean( $country ) ][] = woocommerce_clean( $state ); $counties_array[ woocommerce_clean( $country ) ][] = woocommerce_clean( $state );
} }
$tax_rates[] = array( $tax_rates[] = array(
'countries' => $counties_array, 'countries' => $counties_array,
'rate' => $rate, 'rate' => $rate,
@ -144,9 +144,9 @@ function woocommerce_update_options( $options ) {
); );
} }
} }
$update_options[ 'woocommerce_tax_rates' ] = $tax_rates; $update_options[ 'woocommerce_tax_rates' ] = $tax_rates;
// Local tax rates saving // Local tax rates saving
$local_tax_rates = array(); $local_tax_rates = array();
$tax_classes = isset( $_POST['local_tax_class'] ) ? $_POST['local_tax_class'] : array(); $tax_classes = isset( $_POST['local_tax_class'] ) ? $_POST['local_tax_class'] : array();
@ -160,36 +160,36 @@ function woocommerce_update_options( $options ) {
$tax_label = isset( $_POST['local_tax_label'] ) ? $_POST['local_tax_label'] : array(); $tax_label = isset( $_POST['local_tax_label'] ) ? $_POST['local_tax_label'] : array();
$tax_classes_count = sizeof( $tax_classes ); $tax_classes_count = sizeof( $tax_classes );
for ( $i = 0; $i < $tax_classes_count; $i ++ ) { for ( $i = 0; $i < $tax_classes_count; $i ++ ) {
if ( isset( $tax_classes[ $i ] ) && isset( $tax_countries[ $i ] ) && isset( $tax_rate[ $i ] ) && is_numeric( $tax_rate[ $i ] ) ) { if ( isset( $tax_classes[ $i ] ) && isset( $tax_countries[ $i ] ) && isset( $tax_rate[ $i ] ) && is_numeric( $tax_rate[ $i ] ) ) {
$rate = woocommerce_clean( $tax_rate[ $i ] ); $rate = woocommerce_clean( $tax_rate[ $i ] );
$rate = number_format( $rate, 4, '.', '' ); $rate = number_format( $rate, 4, '.', '' );
$class = woocommerce_clean( $tax_classes[ $i ] ); $class = woocommerce_clean( $tax_classes[ $i ] );
if ( ! empty( $tax_shipping[ $i ] ) ) $shipping = 'yes'; else $shipping = 'no'; if ( ! empty( $tax_shipping[ $i ] ) ) $shipping = 'yes'; else $shipping = 'no';
if ( ! empty( $tax_compound[ $i ] ) ) $compound = 'yes'; else $compound = 'no'; if ( ! empty( $tax_compound[ $i ] ) ) $compound = 'yes'; else $compound = 'no';
// Handle country // Handle country
$country = woocommerce_clean( $tax_countries[ $i ] ); $country = woocommerce_clean( $tax_countries[ $i ] );
$state = '*'; $state = '*';
if ( strstr( $country, ':' ) ) { if ( strstr( $country, ':' ) ) {
$cr = explode( ':', $country ); $cr = explode( ':', $country );
$country = current( $cr ); $country = current( $cr );
$state = end( $cr ); $state = end( $cr );
} }
// Handle postcodes/cities // Handle postcodes/cities
$location_type = $tax_location_type[ $i ] == 'city' ? 'city' : 'postcode'; $location_type = $tax_location_type[ $i ] == 'city' ? 'city' : 'postcode';
$locations = explode( "\n", $tax_location[ $i ] ); $locations = explode( "\n", $tax_location[ $i ] );
$locations = array_filter( array_map( 'woocommerce_clean', $locations ) ); $locations = array_filter( array_map( 'woocommerce_clean', $locations ) );
if ( $location_type == 'city' ) { if ( $location_type == 'city' ) {
$locations = array_map( 'sanitize_title', $locations ); $locations = array_map( 'sanitize_title', $locations );
} }
$local_tax_rates[] = array( $local_tax_rates[] = array(
'country' => $country, 'country' => $country,
'state' => $state, 'state' => $state,
@ -203,86 +203,86 @@ function woocommerce_update_options( $options ) {
); );
} }
} }
$update_options[ 'woocommerce_local_tax_rates' ] = $local_tax_rates; $update_options[ 'woocommerce_local_tax_rates' ] = $local_tax_rates;
break; break;
case "multi_select_countries" : case "multi_select_countries" :
// Get countries array // Get countries array
if ( isset( $_POST[ $value['id'] ] ) ) if ( isset( $_POST[ $value['id'] ] ) )
$selected_countries = array_map( 'woocommerce_clean', (array) $_POST[ $value['id'] ] ); $selected_countries = array_map( 'woocommerce_clean', (array) $_POST[ $value['id'] ] );
else else
$selected_countries = array(); $selected_countries = array();
$option_value = $selected_countries; $option_value = $selected_countries;
break; break;
case "image_width" : case "image_width" :
if ( isset( $_POST[$value['id'] ]['width'] ) ) { if ( isset( $_POST[$value['id'] ]['width'] ) ) {
$update_options[ $value['id'] ]['width'] = woocommerce_clean( $_POST[$value['id'] ]['width'] ); $update_options[ $value['id'] ]['width'] = woocommerce_clean( $_POST[$value['id'] ]['width'] );
$update_options[ $value['id'] ]['height'] = woocommerce_clean( $_POST[$value['id'] ]['height'] ); $update_options[ $value['id'] ]['height'] = woocommerce_clean( $_POST[$value['id'] ]['height'] );
if ( isset( $_POST[ $value['id'] ]['crop'] ) ) if ( isset( $_POST[ $value['id'] ]['crop'] ) )
$update_options[ $value['id'] ]['crop'] = 1; $update_options[ $value['id'] ]['crop'] = 1;
else else
$update_options[ $value['id'] ]['crop'] = 0; $update_options[ $value['id'] ]['crop'] = 0;
} else { } else {
$update_options[ $value['id'] ]['width'] = $value['default']['width']; $update_options[ $value['id'] ]['width'] = $value['default']['width'];
$update_options[ $value['id'] ]['height'] = $value['default']['height']; $update_options[ $value['id'] ]['height'] = $value['default']['height'];
$update_options[ $value['id'] ]['crop'] = $value['default']['crop']; $update_options[ $value['id'] ]['crop'] = $value['default']['crop'];
} }
break; break;
// Custom handling // Custom handling
default : default :
do_action( 'woocommerce_update_option_' . $type, $value ); do_action( 'woocommerce_update_option_' . $type, $value );
break; break;
} }
if ( ! is_null( $option_value ) ) { if ( ! is_null( $option_value ) ) {
// Check if option is an array // Check if option is an array
if ( strstr( $value['id'], '[' ) ) { if ( strstr( $value['id'], '[' ) ) {
parse_str( $value['id'], $option_array ); parse_str( $value['id'], $option_array );
// Option name is first key // Option name is first key
$option_name = current( array_keys( $option_array ) ); $option_name = current( array_keys( $option_array ) );
// Get old option value // Get old option value
if ( ! isset( $update_options[ $option_name ] ) ) if ( ! isset( $update_options[ $option_name ] ) )
$update_options[ $option_name ] = get_option( $option_name, array() ); $update_options[ $option_name ] = get_option( $option_name, array() );
if ( ! is_array( $update_options[ $option_name ] ) ) if ( ! is_array( $update_options[ $option_name ] ) )
$update_options[ $option_name ] = array(); $update_options[ $option_name ] = array();
// Set keys and value // Set keys and value
$key = key( $option_array[ $option_name ] ); $key = key( $option_array[ $option_name ] );
$update_options[ $option_name ][ $key ] = $option_value; $update_options[ $option_name ][ $key ] = $option_value;
// Single value // Single value
} else { } else {
$update_options[ $value['id'] ] = $option_value; $update_options[ $value['id'] ] = $option_value;
} }
} }
// Custom handling // Custom handling
do_action( 'woocommerce_update_option', $value ); do_action( 'woocommerce_update_option', $value );
} }
// Now save the options // Now save the options
foreach( $update_options as $name => $value ) foreach( $update_options as $name => $value )
update_option( $name, $value, true ); update_option( $name, $value, true );
return true; return true;
} }

View File

@ -18,7 +18,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
*/ */
function woocommerce_tax_rates_setting() { function woocommerce_tax_rates_setting() {
global $woocommerce; global $woocommerce;
woocommerce_export_tax_rates(); woocommerce_export_tax_rates();
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option( 'woocommerce_tax_classes' ) ) ) ); $tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option( 'woocommerce_tax_classes' ) ) ) );
@ -28,12 +28,12 @@ function woocommerce_tax_rates_setting() {
?><tr valign="top"> ?><tr valign="top">
<th scope="row" class="titledesc"><?php _e( 'Tax Rates', 'woocommerce' ) ?></th> <th scope="row" class="titledesc"><?php _e( 'Tax Rates', 'woocommerce' ) ?></th>
<td class="forminp"> <td class="forminp">
<a class="button export_rates" href="<?php echo add_query_arg( 'wc_export_tax_rates', 1 ); ?>"><?php _e( 'Export rates', 'woocommerce' ); ?></a> <a class="button export_rates" href="<?php echo add_query_arg( 'wc_export_tax_rates', 1 ); ?>"><?php _e( 'Export rates', 'woocommerce' ); ?></a>
<a class="button import_rates" href="<?php echo admin_url( 'admin.php?import=woocommerce_tax_rate_csv' ); ?>"><?php _e( 'Import rates', 'woocommerce' ); ?></a> <a class="button import_rates" href="<?php echo admin_url( 'admin.php?import=woocommerce_tax_rate_csv' ); ?>"><?php _e( 'Import rates', 'woocommerce' ); ?></a>
<p style="margin-top:0;"><?php _e( 'Define tax rates for countries and states below. You can also export and import from CSV files.', 'woocommerce' ); ?></p> <p style="margin-top:0;"><?php _e( 'Define tax rates for countries and states below. You can also export and import from CSV files.', 'woocommerce' ); ?></p>
<table class="taxrows widefat" cellspacing="0"> <table class="taxrows widefat" cellspacing="0">
<thead> <thead>
<tr> <tr>
@ -53,8 +53,8 @@ function woocommerce_tax_rates_setting() {
</th> </th>
<th colspan="6"> <th colspan="6">
<small><?php _e( 'All matching rates will be applied, and non-compound rates will be summed.', 'woocommerce' ); ?></small> <small><?php _e( 'All matching rates will be applied, and non-compound rates will be summed.', 'woocommerce' ); ?></small>
<a href="#" class="dupe button"><?php _e( 'Duplicate selected', 'woocommerce' ); ?></a> <a href="#" class="dupe button"><?php _e( 'Duplicate selected', 'woocommerce' ); ?></a>
<a href="#" class="remove button"><?php _e( 'Delete selected', 'woocommerce' ); ?></a> <a href="#" class="remove button"><?php _e( 'Delete selected', 'woocommerce' ); ?></a>
</th> </th>
</tr> </tr>
@ -102,7 +102,7 @@ function woocommerce_tax_rates_setting() {
</tbody> </tbody>
</table> </table>
<?php if ( empty( $local_tax_rates ) ) : ?> <?php if ( empty( $local_tax_rates ) ) : ?>
<p style="margin: 1em 0 0;"><a href="#" data-tip="<?php _e( 'Add local tax rates to define rules for specific zip codes and cities.', 'woocommerce' ); ?>" class="tips toggle_local_tax_rates">+ <?php _e( 'Local tax rates', 'woocommerce' ); ?></a></p> <p style="margin: 1em 0 0;"><a href="#" data-tip="<?php _e( 'Add local tax rates to define rules for specific zip codes and cities.', 'woocommerce' ); ?>" class="tips toggle_local_tax_rates">+ <?php _e( 'Local tax rates', 'woocommerce' ); ?></a></p>
<?php endif; ?> <?php endif; ?>
@ -113,9 +113,9 @@ function woocommerce_tax_rates_setting() {
<td class="forminp"> <td class="forminp">
<a class="button export_rates" href="<?php echo add_query_arg( 'wc_export_tax_rates', 2 ); ?>"><?php _e( 'Export rates', 'woocommerce' ); ?></a> <a class="button export_rates" href="<?php echo add_query_arg( 'wc_export_tax_rates', 2 ); ?>"><?php _e( 'Export rates', 'woocommerce' ); ?></a>
<a class="button import_rates" href="<?php echo admin_url( 'admin.php?import=woocommerce_tax_rate_csv' ); ?>"><?php _e( 'Import rates', 'woocommerce' ); ?></a> <a class="button import_rates" href="<?php echo admin_url( 'admin.php?import=woocommerce_tax_rate_csv' ); ?>"><?php _e( 'Import rates', 'woocommerce' ); ?></a>
<p style="margin-top:0;"><?php _e( 'Define local tax rates for specific post/zip codes below. You can also export and import from CSV files.', 'woocommerce' ); ?></p> <p style="margin-top:0;"><?php _e( 'Define local tax rates for specific post/zip codes below. You can also export and import from CSV files.', 'woocommerce' ); ?></p>
<table class="taxrows widefat" cellspacing="0"> <table class="taxrows widefat" cellspacing="0">
<thead> <thead>
<tr> <tr>
@ -139,10 +139,10 @@ function woocommerce_tax_rates_setting() {
</tfoot> </tfoot>
<tbody id="local_tax_rates"> <tbody id="local_tax_rates">
<?php <?php
$i = -1; $i = -1;
if ($local_tax_rates && is_array($local_tax_rates)) foreach( $local_tax_rates as $rate ) : if ($local_tax_rates && is_array($local_tax_rates)) foreach( $local_tax_rates as $rate ) :
$i++; $i++;
$rate['locations'] = isset( $rate['locations'] ) ? $rate['locations'] : $rate['postcode']; // Backwards compat $rate['locations'] = isset( $rate['locations'] ) ? $rate['locations'] : $rate['postcode']; // Backwards compat
$rate['location_type'] = isset( $rate['location_type'] ) ? $rate['location_type'] : 'postcode'; $rate['location_type'] = isset( $rate['location_type'] ) ? $rate['location_type'] : 'postcode';
?> ?>
@ -374,7 +374,7 @@ function woocommerce_tax_rates_setting() {
} }
return false; return false;
}); });
// Show local rates // Show local rates
jQuery( 'a.toggle_local_tax_rates' ).click(function(){ jQuery( 'a.toggle_local_tax_rates' ).click(function(){
jQuery(this).closest('p').hide(); jQuery(this).closest('p').hide();
@ -414,7 +414,7 @@ function woocommerce_tax_row_label( $selected ) {
$states_count+=sizeof($value); $states_count+=sizeof($value);
endif; endif;
if ( ! in_array( $country, $counties_array ) ) if ( ! in_array( $country, $counties_array ) )
$counties_array[] = esc_html( $woocommerce->countries->countries[ $country ] ); $counties_array[] = esc_html( $woocommerce->countries->countries[ $country ] );
endforeach; endforeach;
@ -446,33 +446,33 @@ function woocommerce_tax_row_label( $selected ) {
/** /**
* woocommerce_export_tax_rates function. * woocommerce_export_tax_rates function.
* *
* @access public * @access public
* @return void * @return void
*/ */
function woocommerce_export_tax_rates() { function woocommerce_export_tax_rates() {
if ( empty( $_GET['wc_export_tax_rates'] ) ) if ( empty( $_GET['wc_export_tax_rates'] ) )
return; return;
global $woocommerce; global $woocommerce;
if ( ! class_exists('WC_CSV_Exporter') ) if ( ! class_exists('WC_CSV_Exporter') )
include( $woocommerce->plugin_path() . '/admin/includes/class-wc-csv-exporter.php' ); include( $woocommerce->plugin_path() . '/admin/includes/class-wc-csv-exporter.php' );
$export = absint( $_GET['wc_export_tax_rates'] ); $export = absint( $_GET['wc_export_tax_rates'] );
if ( $export == 1 ) { if ( $export == 1 ) {
$tax_rates = get_option('woocommerce_tax_rates'); $tax_rates = get_option('woocommerce_tax_rates');
$csv = new WC_CSV_Exporter( array( 'countries', 'class', 'label', 'rate', 'compound', 'shipping' ), true, 'tax_rates.csv' ); $csv = new WC_CSV_Exporter( array( 'countries', 'class', 'label', 'rate', 'compound', 'shipping' ), true, 'tax_rates.csv' );
if ( $tax_rates ) if ( $tax_rates )
foreach( $tax_rates as $rate ) { foreach( $tax_rates as $rate ) {
$countries = array(); $countries = array();
foreach ( $rate['countries'] as $country => $states ) { foreach ( $rate['countries'] as $country => $states ) {
foreach( $states as $state ) { foreach( $states as $state ) {
if ( $state == '*' ) { if ( $state == '*' ) {
@ -482,8 +482,8 @@ function woocommerce_export_tax_rates() {
} }
} }
} }
$csv->add_row( array( $csv->add_row( array(
implode( ' | ', $countries ), implode( ' | ', $countries ),
$rate['class'], $rate['class'],
$rate['label'], $rate['label'],
@ -492,18 +492,18 @@ function woocommerce_export_tax_rates() {
$rate['shipping'] == 'yes' ? 1 : 0 $rate['shipping'] == 'yes' ? 1 : 0
) ); ) );
} }
$csv->end(); $csv->end();
} else { } else {
$tax_rates = get_option('woocommerce_local_tax_rates'); $tax_rates = get_option('woocommerce_local_tax_rates');
$csv = new WC_CSV_Exporter( array( 'country', 'state', 'postcode', 'class', 'label', 'rate', 'compound', 'shipping' ), true, 'local_tax_rates.csv' ); $csv = new WC_CSV_Exporter( array( 'country', 'state', 'postcode', 'class', 'label', 'rate', 'compound', 'shipping' ), true, 'local_tax_rates.csv' );
if ( $tax_rates ) if ( $tax_rates )
foreach( $tax_rates as $rate ) { foreach( $tax_rates as $rate ) {
$csv->add_row( array( $csv->add_row( array(
$rate['country'], $rate['country'],
$rate['state'], $rate['state'],
implode( ' | ', $rate['postcode'] ), implode( ' | ', $rate['postcode'] ),
@ -514,8 +514,8 @@ function woocommerce_export_tax_rates() {
$rate['shipping'] == 'yes' ? 1 : 0 $rate['shipping'] == 'yes' ? 1 : 0
) ); ) );
} }
$csv->end(); $csv->end();
} }
} }

View File

@ -298,7 +298,7 @@ function woocommerce_add_attribute() {
</td> </td>
<td><?php echo esc_html( $tax->attribute_name ); ?></td> <td><?php echo esc_html( $tax->attribute_name ); ?></td>
<td><?php echo esc_html( ucwords( $tax->attribute_type ) ); ?></td> <td><?php echo esc_html( ucwords( $tax->attribute_type ) ); ?></td>
<td><?php <td><?php
switch ( $tax->attribute_orderby ) { switch ( $tax->attribute_orderby ) {
case 'name' : case 'name' :
_e( 'Name', 'woocommerce' ); _e( 'Name', 'woocommerce' );
@ -306,7 +306,7 @@ function woocommerce_add_attribute() {
case 'id' : case 'id' :
_e( 'Term ID', 'woocommerce' ); _e( 'Term ID', 'woocommerce' );
break; break;
default: default:
_e( 'Custom ordering', 'woocommerce' ); _e( 'Custom ordering', 'woocommerce' );
break; break;
} }
@ -364,7 +364,7 @@ function woocommerce_add_attribute() {
</select> </select>
<p class="description"><?php _e( 'Determines how you select attributes for products. <strong>Text</strong> allows manual entry via the product page, whereas <strong>select</strong> attribute terms can be defined from this section. If you plan on using an attribute for variations use <strong>select</strong>.', 'woocommerce' ); ?></p> <p class="description"><?php _e( 'Determines how you select attributes for products. <strong>Text</strong> allows manual entry via the product page, whereas <strong>select</strong> attribute terms can be defined from this section. If you plan on using an attribute for variations use <strong>select</strong>.', 'woocommerce' ); ?></p>
</div> </div>
<div class="form-field"> <div class="form-field">
<label for="attribute_orderby"><?php _e( 'Default sort order', 'woocommerce' ); ?></label> <label for="attribute_orderby"><?php _e( 'Default sort order', 'woocommerce' ); ?></label>
<select name="attribute_orderby" id="attribute_orderby"> <select name="attribute_orderby" id="attribute_orderby">

View File

@ -44,7 +44,7 @@ function woocommerce_init_dashboard_widgets() {
wp_add_dashboard_widget( 'woocommerce_dashboard_recent_orders', __( 'WooCommerce Recent Orders', 'woocommerce' ), 'woocommerce_dashboard_recent_orders'); wp_add_dashboard_widget( 'woocommerce_dashboard_recent_orders', __( 'WooCommerce Recent Orders', 'woocommerce' ), 'woocommerce_dashboard_recent_orders');
wp_add_dashboard_widget( 'woocommerce_dashboard_recent_reviews', __( 'WooCommerce Recent Reviews', 'woocommerce' ), 'woocommerce_dashboard_recent_reviews' ); wp_add_dashboard_widget( 'woocommerce_dashboard_recent_reviews', __( 'WooCommerce Recent Reviews', 'woocommerce' ), 'woocommerce_dashboard_recent_reviews' );
} }
if ( current_user_can( 'view_woocommerce_reports' ) || current_user_can( 'publish_shop_orders' ) ) { if ( current_user_can( 'view_woocommerce_reports' ) || current_user_can( 'publish_shop_orders' ) ) {
wp_add_dashboard_widget( 'woocommerce_dashboard_sales', $sales_heading, 'woocommerce_dashboard_sales' ); wp_add_dashboard_widget( 'woocommerce_dashboard_sales', $sales_heading, 'woocommerce_dashboard_sales' );
} }

View File

@ -84,7 +84,7 @@ function woocommerce_ms_protect_download_rewite_rules( $rewrite ) {
*/ */
function woocommerce_delete_post( $id ) { function woocommerce_delete_post( $id ) {
global $woocommerce; global $woocommerce;
if ( ! current_user_can( 'delete_posts' ) ) return; if ( ! current_user_can( 'delete_posts' ) ) return;
if ( $id > 0 ) : if ( $id > 0 ) :
@ -104,7 +104,7 @@ function woocommerce_delete_post( $id ) {
endif; endif;
endif; endif;
$woocommerce->clear_product_transients(); $woocommerce->clear_product_transients();
delete_transient( 'woocommerce_processing_order_count' ); delete_transient( 'woocommerce_processing_order_count' );
} }
@ -265,7 +265,7 @@ function woocommerce_add_shortcode_button() {
/** /**
* woocommerce_add_tinymce_lang function. * woocommerce_add_tinymce_lang function.
* *
* @access public * @access public
* @param mixed $arr * @param mixed $arr
* @return void * @return void
@ -330,9 +330,9 @@ function woocommerce_refresh_mce( $ver ) {
*/ */
function woocommerce_create_term( $term_id, $tt_id = '', $taxonomy = '' ) { function woocommerce_create_term( $term_id, $tt_id = '', $taxonomy = '' ) {
if ( ! $taxonomy == 'product_cat' && ! strstr( $taxonomy, 'pa_' ) ) if ( ! $taxonomy == 'product_cat' && ! strstr( $taxonomy, 'pa_' ) )
return; return;
$meta_name = strstr( $taxonomy, 'pa_' ) ? 'order_' . esc_attr( $taxonomy ) : 'order'; $meta_name = strstr( $taxonomy, 'pa_' ) ? 'order_' . esc_attr( $taxonomy ) : 'order';
update_woocommerce_term_meta( $term_id, $meta_name, 0 ); update_woocommerce_term_meta( $term_id, $meta_name, 0 );
@ -350,7 +350,7 @@ function woocommerce_delete_term( $term_id ) {
$term_id = (int) $term_id; $term_id = (int) $term_id;
if ( ! $term_id ) if ( ! $term_id )
return; return;
global $wpdb; global $wpdb;

View File

@ -141,7 +141,7 @@ add_action( 'admin_head', 'woocommerce_admin_menu_highlight' );
/** /**
* woocommerce_admin_notices_styles function. * woocommerce_admin_notices_styles function.
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -151,7 +151,7 @@ function woocommerce_admin_notices_styles() {
wp_enqueue_style( 'woocommerce-activation', plugins_url( '/assets/css/activation.css', dirname( __FILE__ ) ) ); wp_enqueue_style( 'woocommerce-activation', plugins_url( '/assets/css/activation.css', dirname( __FILE__ ) ) );
add_action( 'admin_notices', 'woocommerce_admin_install_notices' ); add_action( 'admin_notices', 'woocommerce_admin_install_notices' );
} }
} }
add_action( 'admin_print_styles', 'woocommerce_admin_notices_styles' ); add_action( 'admin_print_styles', 'woocommerce_admin_notices_styles' );
@ -159,38 +159,38 @@ add_action( 'admin_print_styles', 'woocommerce_admin_notices_styles' );
/** /**
* woocommerce_admin_install_notices function. * woocommerce_admin_install_notices function.
* *
* @access public * @access public
* @return void * @return void
*/ */
function woocommerce_admin_install_notices() { function woocommerce_admin_install_notices() {
global $woocommerce; global $woocommerce;
if ( get_option( 'woocommerce_needs_update' ) == 1 ) { if ( get_option( 'woocommerce_needs_update' ) == 1 ) {
include( 'includes/notice-update.php' ); include( 'includes/notice-update.php' );
} elseif ( get_option( 'woocommerce_updated' ) == 1 ) { } elseif ( get_option( 'woocommerce_updated' ) == 1 ) {
include( 'includes/notice-updated.php' ); include( 'includes/notice-updated.php' );
update_option( 'woocommerce_updated', 0 ); update_option( 'woocommerce_updated', 0 );
update_option( 'woocommerce_installed', 0 ); update_option( 'woocommerce_installed', 0 );
} elseif ( get_option( 'woocommerce_installed' ) == 1 ) { } elseif ( get_option( 'woocommerce_installed' ) == 1 ) {
if ( get_option( 'skip_install_woocommerce_pages' ) != 1 && woocommerce_get_page_id( 'shop' ) < 1 && ! isset( $_GET['install_woocommerce_pages'] ) && !isset( $_GET['skip_install_woocommerce_pages'] ) ) { if ( get_option( 'skip_install_woocommerce_pages' ) != 1 && woocommerce_get_page_id( 'shop' ) < 1 && ! isset( $_GET['install_woocommerce_pages'] ) && !isset( $_GET['skip_install_woocommerce_pages'] ) ) {
include( 'includes/notice-install.php' ); include( 'includes/notice-install.php' );
} elseif ( ! isset( $_GET['page'] ) || $_GET['page'] != 'woocommerce_settings' ) { } elseif ( ! isset( $_GET['page'] ) || $_GET['page'] != 'woocommerce_settings' ) {
include( 'includes/notice-installed.php' ); include( 'includes/notice-installed.php' );
update_option( 'woocommerce_installed', 0 ); update_option( 'woocommerce_installed', 0 );
} }
} }
} }
@ -232,7 +232,7 @@ function woocommerce_admin_init() {
include_once( 'woocommerce-admin-users.php' ); include_once( 'woocommerce-admin-users.php' );
} }
// Register importers // Register importers
if ( defined( 'WP_LOAD_IMPORTERS' ) ) { if ( defined( 'WP_LOAD_IMPORTERS' ) ) {
include_once( 'importers/importers-init.php' ); include_once( 'importers/importers-init.php' );
@ -313,7 +313,7 @@ function install_woocommerce() {
/** /**
* update_woocommerce function. * update_woocommerce function.
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -354,19 +354,19 @@ function woocommerce_admin_scripts() {
// Register scripts // Register scripts
wp_register_script( 'woocommerce_admin', $woocommerce->plugin_url() . '/assets/js/admin/woocommerce_admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui', 'jquery-placeholder', 'jquery-ui-widget', 'jquery-ui-core', 'jquery-tiptip' ), $woocommerce->version ); wp_register_script( 'woocommerce_admin', $woocommerce->plugin_url() . '/assets/js/admin/woocommerce_admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui', 'jquery-placeholder', 'jquery-ui-widget', 'jquery-ui-core', 'jquery-tiptip' ), $woocommerce->version );
wp_register_script( 'jquery-blockui', $woocommerce->plugin_url() . '/assets/js/jquery-blockui/jquery.blockUI' . $suffix . '.js', array( 'jquery' ), $woocommerce->version, true ); wp_register_script( 'jquery-blockui', $woocommerce->plugin_url() . '/assets/js/jquery-blockui/jquery.blockUI' . $suffix . '.js', array( 'jquery' ), $woocommerce->version, true );
wp_register_script( 'jquery-placeholder', $woocommerce->plugin_url() . '/assets/js/jquery-placeholder/jquery.placeholder' . $suffix . '.js', array( 'jquery' ), $woocommerce->version, true ); wp_register_script( 'jquery-placeholder', $woocommerce->plugin_url() . '/assets/js/jquery-placeholder/jquery.placeholder' . $suffix . '.js', array( 'jquery' ), $woocommerce->version, true );
wp_register_script( 'jquery-tiptip', $woocommerce->plugin_url() . '/assets/js/jquery-tiptip/jquery.tipTip' . $suffix . '.js', array( 'jquery' ), $woocommerce->version, true ); wp_register_script( 'jquery-tiptip', $woocommerce->plugin_url() . '/assets/js/jquery-tiptip/jquery.tipTip' . $suffix . '.js', array( 'jquery' ), $woocommerce->version, true );
wp_register_script( 'jquery-ui-datepicker', $woocommerce->plugin_url() . '/assets/js/admin/ui-datepicker.js', array('jquery','jquery-ui-core'), $woocommerce->version ); wp_register_script( 'jquery-ui-datepicker', $woocommerce->plugin_url() . '/assets/js/admin/ui-datepicker.js', array('jquery','jquery-ui-core'), $woocommerce->version );
wp_register_script( 'woocommerce_writepanel', $woocommerce->plugin_url() . '/assets/js/admin/write-panels'.$suffix.'.js', array('jquery', 'jquery-ui-datepicker'), $woocommerce->version ); wp_register_script( 'woocommerce_writepanel', $woocommerce->plugin_url() . '/assets/js/admin/write-panels'.$suffix.'.js', array('jquery', 'jquery-ui-datepicker'), $woocommerce->version );
wp_register_script( 'ajax-chosen', $woocommerce->plugin_url() . '/assets/js/chosen/ajax-chosen.jquery'.$suffix.'.js', array('jquery', 'chosen'), $woocommerce->version ); wp_register_script( 'ajax-chosen', $woocommerce->plugin_url() . '/assets/js/chosen/ajax-chosen.jquery'.$suffix.'.js', array('jquery', 'chosen'), $woocommerce->version );
wp_register_script( 'chosen', $woocommerce->plugin_url() . '/assets/js/chosen/chosen.jquery'.$suffix.'.js', array('jquery'), $woocommerce->version ); wp_register_script( 'chosen', $woocommerce->plugin_url() . '/assets/js/chosen/chosen.jquery'.$suffix.'.js', array('jquery'), $woocommerce->version );
// Get admin screen id // Get admin screen id
@ -433,7 +433,7 @@ function woocommerce_admin_scripts() {
'get_customer_details_nonce' => wp_create_nonce("get-customer-details"), 'get_customer_details_nonce' => wp_create_nonce("get-customer-details"),
'search_products_nonce' => wp_create_nonce("search-products"), 'search_products_nonce' => wp_create_nonce("search-products"),
'calendar_image' => $woocommerce->plugin_url().'/assets/images/calendar.png', 'calendar_image' => $woocommerce->plugin_url().'/assets/images/calendar.png',
'post_id' => $post->ID, 'post_id' => $post->ID,
'currency_format_num_decimals' => absint( get_option( 'woocommerce_price_num_decimals' ) ), 'currency_format_num_decimals' => absint( get_option( 'woocommerce_price_num_decimals' ) ),
'currency_format_symbol' => get_woocommerce_currency_symbol(), 'currency_format_symbol' => get_woocommerce_currency_symbol(),
'currency_format_decimal_sep' => esc_attr( stripslashes( get_option( 'woocommerce_price_decimal_sep' ) ) ), 'currency_format_decimal_sep' => esc_attr( stripslashes( get_option( 'woocommerce_price_decimal_sep' ) ) ),
@ -618,7 +618,7 @@ function woocommerce_exclude_image_from_product_page_field( $fields, $object ) {
$parent = get_post( $object->post_parent ); $parent = get_post( $object->post_parent );
if ( $parent->post_type !== 'product' ) if ( $parent->post_type !== 'product' )
return $fields; return $fields;
$exclude_image = get_post_meta( absint( $object->ID ), '_woocommerce_exclude_image', true ); $exclude_image = get_post_meta( absint( $object->ID ), '_woocommerce_exclude_image', true );
@ -769,7 +769,7 @@ add_filter( 'admin_comment_types_dropdown', 'woocommerce_admin_comment_types_dro
/** /**
* woocommerce_permalink_settings function. * woocommerce_permalink_settings function.
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -779,12 +779,12 @@ function woocommerce_permalink_settings() {
$permalinks = get_option( 'woocommerce_permalinks' ); $permalinks = get_option( 'woocommerce_permalinks' );
$product_permalink = $permalinks['product_base']; $product_permalink = $permalinks['product_base'];
// Get shop page // Get shop page
$shop_page_id = woocommerce_get_page_id( 'shop' ); $shop_page_id = woocommerce_get_page_id( 'shop' );
$base_slug = ( $shop_page_id > 0 && get_page( $shop_page_id ) ) ? get_page_uri( $shop_page_id ) : _x( 'shop', 'default-slug', 'woocommerce' ); $base_slug = ( $shop_page_id > 0 && get_page( $shop_page_id ) ) ? get_page_uri( $shop_page_id ) : _x( 'shop', 'default-slug', 'woocommerce' );
$product_base = _x( 'product', 'default-slug', 'woocommerce' ); $product_base = _x( 'product', 'default-slug', 'woocommerce' );
$structures = array( $structures = array(
0 => '', 0 => '',
1 => '/' . trailingslashit( $product_base ), 1 => '/' . trailingslashit( $product_base ),
@ -826,7 +826,7 @@ function woocommerce_permalink_settings() {
jQuery('input.wctog').change(function() { jQuery('input.wctog').change(function() {
jQuery('#woocommerce_permalink_structure').val( jQuery(this).val() ); jQuery('#woocommerce_permalink_structure').val( jQuery(this).val() );
}); });
jQuery('#woocommerce_permalink_structure').focus(function(){ jQuery('#woocommerce_permalink_structure').focus(function(){
jQuery('#woocommerce_custom_selection').click(); jQuery('#woocommerce_custom_selection').click();
}); });
@ -837,7 +837,7 @@ function woocommerce_permalink_settings() {
/** /**
* woocommerce_permalink_settings_init function. * woocommerce_permalink_settings_init function.
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -845,7 +845,7 @@ function woocommerce_permalink_settings_init() {
// Add a section to the permalinks page // Add a section to the permalinks page
add_settings_section( 'woocommerce-permalink', __( 'Product permalink base', 'woocommerce' ), 'woocommerce_permalink_settings', 'permalink' ); add_settings_section( 'woocommerce-permalink', __( 'Product permalink base', 'woocommerce' ), 'woocommerce_permalink_settings', 'permalink' );
// Add our settings // Add our settings
add_settings_field( add_settings_field(
'woocommerce_product_category_slug', // id 'woocommerce_product_category_slug', // id
@ -874,40 +874,40 @@ add_action( 'admin_init', 'woocommerce_permalink_settings_init' );
/** /**
* woocommerce_permalink_settings_save function. * woocommerce_permalink_settings_save function.
* *
* @access public * @access public
* @return void * @return void
*/ */
function woocommerce_permalink_settings_save() { function woocommerce_permalink_settings_save() {
if ( ! is_admin() ) if ( ! is_admin() )
return; return;
// We need to save the options ourselves; settings api does not trigger save for the permalinks page // We need to save the options ourselves; settings api does not trigger save for the permalinks page
if ( isset( $_POST['permalink_structure'] ) || isset( $_POST['category_base'] ) ) { if ( isset( $_POST['permalink_structure'] ) || isset( $_POST['category_base'] ) ) {
// Cat and tag bases // Cat and tag bases
$woocommerce_product_category_slug = woocommerce_clean( $_POST['woocommerce_product_category_slug'] ); $woocommerce_product_category_slug = woocommerce_clean( $_POST['woocommerce_product_category_slug'] );
$woocommerce_product_tag_slug = woocommerce_clean( $_POST['woocommerce_product_tag_slug'] ); $woocommerce_product_tag_slug = woocommerce_clean( $_POST['woocommerce_product_tag_slug'] );
$woocommerce_product_attribute_slug = woocommerce_clean( $_POST['woocommerce_product_attribute_slug'] ); $woocommerce_product_attribute_slug = woocommerce_clean( $_POST['woocommerce_product_attribute_slug'] );
$permalinks = get_option( 'woocommerce_permalinks' ); $permalinks = get_option( 'woocommerce_permalinks' );
if ( ! $permalinks ) if ( ! $permalinks )
$permalinks = array(); $permalinks = array();
$permalinks['category_base'] = untrailingslashit( $woocommerce_product_category_slug ); $permalinks['category_base'] = untrailingslashit( $woocommerce_product_category_slug );
$permalinks['tag_base'] = untrailingslashit( $woocommerce_product_tag_slug ); $permalinks['tag_base'] = untrailingslashit( $woocommerce_product_tag_slug );
$permalinks['attribute_base'] = untrailingslashit( $woocommerce_product_attribute_slug ); $permalinks['attribute_base'] = untrailingslashit( $woocommerce_product_attribute_slug );
// Product base // Product base
$product_permalink = woocommerce_clean( $_POST['product_permalink'] ); $product_permalink = woocommerce_clean( $_POST['product_permalink'] );
if ( $product_permalink == 'custom' ) { if ( $product_permalink == 'custom' ) {
$product_permalink = woocommerce_clean( $_POST['product_permalink_structure'] ); $product_permalink = woocommerce_clean( $_POST['product_permalink_structure'] );
} elseif ( empty( $product_permalink ) ) { } elseif ( empty( $product_permalink ) ) {
$product_permalink = false; $product_permalink = false;
} }
$permalinks['product_base'] = untrailingslashit( $product_permalink ); $permalinks['product_base'] = untrailingslashit( $product_permalink );
update_option( 'woocommerce_permalinks', $permalinks ); update_option( 'woocommerce_permalinks', $permalinks );
} }
} }
@ -916,7 +916,7 @@ add_action( 'before_woocommerce_init', 'woocommerce_permalink_settings_save' );
/** /**
* woocommerce_product_category_slug_input function. * woocommerce_product_category_slug_input function.
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -929,7 +929,7 @@ function woocommerce_product_category_slug_input() {
/** /**
* woocommerce_product_tag_slug_input function. * woocommerce_product_tag_slug_input function.
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -942,7 +942,7 @@ function woocommerce_product_tag_slug_input() {
/** /**
* woocommerce_product_attribute_slug_input function. * woocommerce_product_attribute_slug_input function.
* *
* @access public * @access public
* @return void * @return void
*/ */

View File

@ -20,12 +20,12 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
*/ */
function do_install_woocommerce() { function do_install_woocommerce() {
global $woocommerce_settings, $woocommerce; global $woocommerce_settings, $woocommerce;
// Do install // Do install
woocommerce_default_options(); woocommerce_default_options();
woocommerce_tables_install(); woocommerce_tables_install();
woocommerce_init_roles(); woocommerce_init_roles();
// Register post types // Register post types
$woocommerce->init_taxonomy(); $woocommerce->init_taxonomy();
@ -34,7 +34,7 @@ function do_install_woocommerce() {
// Install files and folders for uploading files and prevent hotlinking // Install files and folders for uploading files and prevent hotlinking
$upload_dir = wp_upload_dir(); $upload_dir = wp_upload_dir();
$files = array( $files = array(
array( array(
'base' => $upload_dir['basedir'] . '/woocommerce_uploads', 'base' => $upload_dir['basedir'] . '/woocommerce_uploads',
@ -57,7 +57,7 @@ function do_install_woocommerce() {
'content' => '' 'content' => ''
) )
); );
foreach ( $files as $file ) { foreach ( $files as $file ) {
if ( wp_mkdir_p( $file['base'] ) && ! file_exists( trailingslashit( $file['base'] ) . $file['file'] ) ) { if ( wp_mkdir_p( $file['base'] ) && ! file_exists( trailingslashit( $file['base'] ) . $file['file'] ) ) {
if ( $file_handle = @fopen( trailingslashit( $file['base'] ) . $file['file'], 'w' ) ) { if ( $file_handle = @fopen( trailingslashit( $file['base'] ) . $file['file'], 'w' ) ) {
@ -77,19 +77,19 @@ function do_install_woocommerce() {
if ( ( ! empty( $colors['primary'] ) && ! empty( $colors['secondary'] ) && ! empty( $colors['highlight'] ) && ! empty( $colors['content_bg'] ) && ! empty( $colors['subtext'] ) ) && ( $colors['primary'] != '#ad74a2' || $colors['secondary'] != '#f7f6f7' || $colors['highlight'] != '#85ad74' || $colors['content_bg'] != '#ffffff' || $colors['subtext'] != '#777777' ) ) if ( ( ! empty( $colors['primary'] ) && ! empty( $colors['secondary'] ) && ! empty( $colors['highlight'] ) && ! empty( $colors['content_bg'] ) && ! empty( $colors['subtext'] ) ) && ( $colors['primary'] != '#ad74a2' || $colors['secondary'] != '#f7f6f7' || $colors['highlight'] != '#85ad74' || $colors['content_bg'] != '#ffffff' || $colors['subtext'] != '#777777' ) )
woocommerce_compile_less_styles(); woocommerce_compile_less_styles();
} }
// Queue upgrades // Queue upgrades
$current_version = get_option( 'woocommerce_version', null ); $current_version = get_option( 'woocommerce_version', null );
$current_db_version = get_option( 'woocommerce_db_version', null ); $current_db_version = get_option( 'woocommerce_db_version', null );
if ( version_compare( $current_db_version, '1.7', '<' ) && null !== $current_version ) { if ( version_compare( $current_db_version, '1.7', '<' ) && null !== $current_version ) {
update_option( 'woocommerce_needs_update', 1 ); update_option( 'woocommerce_needs_update', 1 );
} else { } else {
update_option( 'woocommerce_db_version', $woocommerce->version ); update_option( 'woocommerce_db_version', $woocommerce->version );
} }
// Update version // Update version
update_option( 'woocommerce_version', $woocommerce->version ); update_option( 'woocommerce_version', $woocommerce->version );
} }
@ -217,9 +217,9 @@ function woocommerce_tables_install() {
$collate = ''; $collate = '';
if ( $wpdb->has_cap( 'collation' ) ) { if ( $wpdb->has_cap( 'collation' ) ) {
if( ! empty($wpdb->charset ) ) if( ! empty($wpdb->charset ) )
$collate .= "DEFAULT CHARACTER SET $wpdb->charset"; $collate .= "DEFAULT CHARACTER SET $wpdb->charset";
if( ! empty($wpdb->collate ) ) if( ! empty($wpdb->collate ) )
$collate .= " COLLATE $wpdb->collate"; $collate .= " COLLATE $wpdb->collate";
} }
@ -249,7 +249,7 @@ CREATE TABLE ". $wpdb->prefix . "woocommerce_termmeta (
) $collate; ) $collate;
"; ";
dbDelta( $sql ); dbDelta( $sql );
// Table for storing user and guest download permissions // Table for storing user and guest download permissions
// KEY(order_id, product_id, download_id) used for organizing downloads on the My Account page // KEY(order_id, product_id, download_id) used for organizing downloads on the My Account page
$sql = " $sql = "
@ -269,19 +269,19 @@ CREATE TABLE ". $wpdb->prefix . "woocommerce_downloadable_product_permissions (
) $collate; ) $collate;
"; ";
dbDelta( $sql ); dbDelta( $sql );
// Order line items are stored in a table to make them easily queryable for reports // Order line items are stored in a table to make them easily queryable for reports
$sql = " $sql = "
CREATE TABLE ". $wpdb->prefix . "woocommerce_order_items ( CREATE TABLE ". $wpdb->prefix . "woocommerce_order_items (
order_item_id bigint(20) NOT NULL auto_increment, order_item_id bigint(20) NOT NULL auto_increment,
order_item_name longtext NOT NULL DEFAULT '', order_item_name longtext NOT NULL DEFAULT '',
order_item_type varchar(200) NOT NULL DEFAULT '', order_item_type varchar(200) NOT NULL DEFAULT '',
order_id bigint(20) NOT NULL, order_id bigint(20) NOT NULL,
PRIMARY KEY (order_item_id) PRIMARY KEY (order_item_id)
) $collate; ) $collate;
"; ";
dbDelta( $sql ); dbDelta( $sql );
// Order line item meta is stored in a table for storing extra data. // Order line item meta is stored in a table for storing extra data.
$sql = " $sql = "
CREATE TABLE ". $wpdb->prefix . "woocommerce_order_itemmeta ( CREATE TABLE ". $wpdb->prefix . "woocommerce_order_itemmeta (

View File

@ -333,9 +333,9 @@ function woocommerce_sales_overview() {
AND tax.taxonomy = 'shop_order_status' AND tax.taxonomy = 'shop_order_status'
AND term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "') AND term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "')
" ); " );
$order_items = absint( $wpdb->get_var( " $order_items = absint( $wpdb->get_var( "
SELECT SUM( order_item_meta.meta_value ) SELECT SUM( order_item_meta.meta_value )
FROM {$wpdb->prefix}woocommerce_order_items as order_items FROM {$wpdb->prefix}woocommerce_order_items as order_items
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id
LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID
@ -401,15 +401,15 @@ function woocommerce_sales_overview() {
$start_date = strtotime( date('Ymd', strtotime( date('Ym', current_time('timestamp') ) . '01' ) ) ); $start_date = strtotime( date('Ymd', strtotime( date('Ym', current_time('timestamp') ) . '01' ) ) );
$end_date = strtotime( date('Ymd', current_time( 'timestamp' ) ) ); $end_date = strtotime( date('Ymd', current_time( 'timestamp' ) ) );
// Blank date ranges to begin // Blank date ranges to begin
$order_counts = $order_amounts = array(); $order_counts = $order_amounts = array();
$count = 0; $count = 0;
$days = ( $end_date - $start_date ) / ( 60 * 60 * 24 ); $days = ( $end_date - $start_date ) / ( 60 * 60 * 24 );
if ( $days == 0 ) if ( $days == 0 )
$days = 1; $days = 1;
while ( $count < $days ) { while ( $count < $days ) {
@ -419,7 +419,7 @@ function woocommerce_sales_overview() {
$count++; $count++;
} }
// Get order ids and dates in range // Get order ids and dates in range
$orders = $wpdb->get_results( " $orders = $wpdb->get_results( "
SELECT posts.ID, posts.post_date FROM {$wpdb->posts} AS posts SELECT posts.ID, posts.post_date FROM {$wpdb->posts} AS posts
@ -456,10 +456,10 @@ function woocommerce_sales_overview() {
} }
$order_counts_array = $order_amounts_array = array(); $order_counts_array = $order_amounts_array = array();
foreach ( $order_counts as $key => $count ) foreach ( $order_counts as $key => $count )
$order_counts_array[] = array( esc_js( $key ), esc_js( $count ) ); $order_counts_array[] = array( esc_js( $key ), esc_js( $count ) );
foreach ( $order_amounts as $key => $amount ) foreach ( $order_amounts as $key => $amount )
$order_amounts_array[] = array( esc_js( $key ), esc_js( $amount ) ); $order_amounts_array[] = array( esc_js( $key ), esc_js( $amount ) );
@ -529,24 +529,24 @@ function woocommerce_daily_sales() {
$start_date = isset( $_POST['start_date'] ) ? $_POST['start_date'] : ''; $start_date = isset( $_POST['start_date'] ) ? $_POST['start_date'] : '';
$end_date = isset( $_POST['end_date'] ) ? $_POST['end_date'] : ''; $end_date = isset( $_POST['end_date'] ) ? $_POST['end_date'] : '';
if ( ! $start_date) if ( ! $start_date)
$start_date = date( 'Ymd', strtotime( date('Ym', current_time( 'timestamp' ) ) . '01' ) ); $start_date = date( 'Ymd', strtotime( date('Ym', current_time( 'timestamp' ) ) . '01' ) );
if ( ! $end_date) if ( ! $end_date)
$end_date = date( 'Ymd', current_time( 'timestamp' ) ); $end_date = date( 'Ymd', current_time( 'timestamp' ) );
$start_date = strtotime( $start_date ); $start_date = strtotime( $start_date );
$end_date = strtotime( $end_date ); $end_date = strtotime( $end_date );
$total_sales = $total_orders = $order_items = 0; $total_sales = $total_orders = $order_items = 0;
// Blank date ranges to begin // Blank date ranges to begin
$order_counts = $order_amounts = array(); $order_counts = $order_amounts = array();
$count = 0; $count = 0;
$days = ( $end_date - $start_date ) / ( 60 * 60 * 24 ); $days = ( $end_date - $start_date ) / ( 60 * 60 * 24 );
if ( $days == 0 ) if ( $days == 0 )
$days = 1; $days = 1;
while ( $count < $days ) { while ( $count < $days ) {
@ -556,16 +556,16 @@ function woocommerce_daily_sales() {
$count++; $count++;
} }
// Get order ids and dates in range // Get order ids and dates in range
$orders = $wpdb->get_results( " $orders = $wpdb->get_results( "
SELECT posts.ID, posts.post_date, meta.meta_value AS total_sales FROM {$wpdb->posts} AS posts SELECT posts.ID, posts.post_date, meta.meta_value AS total_sales FROM {$wpdb->posts} AS posts
LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id
LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID = rel.object_ID LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID = rel.object_ID
LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id ) LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id )
LEFT JOIN {$wpdb->terms} AS term USING( term_id ) LEFT JOIN {$wpdb->terms} AS term USING( term_id )
WHERE meta.meta_key = '_order_total' WHERE meta.meta_key = '_order_total'
AND posts.post_type = 'shop_order' AND posts.post_type = 'shop_order'
AND posts.post_status = 'publish' AND posts.post_status = 'publish'
@ -573,33 +573,33 @@ function woocommerce_daily_sales() {
AND term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "') AND term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "')
AND post_date > '" . date('Y-m-d', $start_date ) . "' AND post_date > '" . date('Y-m-d', $start_date ) . "'
AND post_date < '" . date('Y-m-d', strtotime('+1 day', $end_date ) ) . "' AND post_date < '" . date('Y-m-d', strtotime('+1 day', $end_date ) ) . "'
GROUP BY posts.ID GROUP BY posts.ID
ORDER BY post_date ASC ORDER BY post_date ASC
" ); " );
if ( $orders ) { if ( $orders ) {
$total_orders = sizeof( $orders ); $total_orders = sizeof( $orders );
foreach ( $orders as $order ) { foreach ( $orders as $order ) {
// get order timestamp // get order timestamp
$time = strtotime( date( 'Ymd', strtotime( $order->post_date ) ) ) . '000'; $time = strtotime( date( 'Ymd', strtotime( $order->post_date ) ) ) . '000';
// Add order total // Add order total
$total_sales += $order->total_sales; $total_sales += $order->total_sales;
// Get items // Get items
$order_items += absint( $wpdb->get_var( $wpdb->prepare( " $order_items += absint( $wpdb->get_var( $wpdb->prepare( "
SELECT SUM( order_item_meta.meta_value ) SELECT SUM( order_item_meta.meta_value )
FROM {$wpdb->prefix}woocommerce_order_items as order_items FROM {$wpdb->prefix}woocommerce_order_items as order_items
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id
WHERE order_id = %d WHERE order_id = %d
AND order_items.order_item_type = 'line_item' AND order_items.order_item_type = 'line_item'
AND order_item_meta.meta_key = '_qty' AND order_item_meta.meta_key = '_qty'
", $order->ID ) ) ); ", $order->ID ) ) );
// Set times // Set times
if ( isset( $order_counts[ $time ] ) ) if ( isset( $order_counts[ $time ] ) )
$order_counts[ $time ]++; $order_counts[ $time ]++;
@ -656,7 +656,7 @@ function woocommerce_daily_sales() {
<?php <?php
$order_counts_array = $order_amounts_array = array(); $order_counts_array = $order_amounts_array = array();
foreach ( $order_counts as $key => $count ) foreach ( $order_counts as $key => $count )
$order_counts_array[] = array( esc_js( $key ), esc_js( $count ) ); $order_counts_array[] = array( esc_js( $key ), esc_js( $count ) );
@ -728,7 +728,7 @@ function woocommerce_monthly_sales() {
global $start_date, $end_date, $woocommerce, $wpdb, $wp_locale; global $start_date, $end_date, $woocommerce, $wpdb, $wp_locale;
$first_year = $wpdb->get_var( "SELECT post_date FROM $wpdb->posts WHERE post_date != 0 ORDER BY post_date ASC LIMIT 1;" ); $first_year = $wpdb->get_var( "SELECT post_date FROM $wpdb->posts WHERE post_date != 0 ORDER BY post_date ASC LIMIT 1;" );
$first_year = $first_year ? date( 'Y', strtotime( $first_year ) ) : date('Y'); $first_year = $first_year ? date( 'Y', strtotime( $first_year ) ) : date('Y');
$current_year = isset( $_POST['show_year'] ) ? $_POST['show_year'] : date( 'Y', current_time( 'timestamp' ) ); $current_year = isset( $_POST['show_year'] ) ? $_POST['show_year'] : date( 'Y', current_time( 'timestamp' ) );
@ -769,7 +769,7 @@ function woocommerce_monthly_sales() {
// Count order items // Count order items
$order_items += absint( $wpdb->get_var( " $order_items += absint( $wpdb->get_var( "
SELECT SUM( order_item_meta.meta_value ) SELECT SUM( order_item_meta.meta_value )
FROM {$wpdb->prefix}woocommerce_order_items as order_items FROM {$wpdb->prefix}woocommerce_order_items as order_items
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id
LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID
@ -789,7 +789,7 @@ function woocommerce_monthly_sales() {
<p><label for="show_year"><?php _e( 'Year:', 'woocommerce' ); ?></label> <p><label for="show_year"><?php _e( 'Year:', 'woocommerce' ); ?></label>
<select name="show_year" id="show_year"> <select name="show_year" id="show_year">
<?php <?php
for ( $i = $first_year; $i <= date( 'Y' ); $i++ ) for ( $i = $first_year; $i <= date( 'Y' ); $i++ )
printf('<option value="%s" %s>%s</option>', $i, selected( $current_year, $i, false ), $i ); printf('<option value="%s" %s>%s</option>', $i, selected( $current_year, $i, false ), $i );
?> ?>
</select> <input type="submit" class="button" value="<?php _e( 'Show', 'woocommerce' ); ?>" /></p> </select> <input type="submit" class="button" value="<?php _e( 'Show', 'woocommerce' ); ?>" /></p>
@ -833,10 +833,10 @@ function woocommerce_monthly_sales() {
<?php <?php
$order_counts_array = $order_amounts_array = array(); $order_counts_array = $order_amounts_array = array();
foreach ( $order_counts as $key => $count ) foreach ( $order_counts as $key => $count )
$order_counts_array[] = array( esc_js( $key ), esc_js( $count ) ); $order_counts_array[] = array( esc_js( $key ), esc_js( $count ) );
foreach ( $order_amounts as $key => $amount ) foreach ( $order_amounts as $key => $amount )
$order_amounts_array[] = array( esc_js( $key ), esc_js( $amount ) ); $order_amounts_array[] = array( esc_js( $key ), esc_js( $amount ) );
@ -901,7 +901,7 @@ function woocommerce_top_sellers() {
$start_date = isset( $_POST['start_date'] ) ? $_POST['start_date'] : ''; $start_date = isset( $_POST['start_date'] ) ? $_POST['start_date'] : '';
$end_date = isset( $_POST['end_date'] ) ? $_POST['end_date'] : ''; $end_date = isset( $_POST['end_date'] ) ? $_POST['end_date'] : '';
if ( ! $start_date ) if ( ! $start_date )
$start_date = date( 'Ymd', strtotime( date( 'Ym', current_time( 'timestamp' ) ) . '01' ) ); $start_date = date( 'Ymd', strtotime( date( 'Ym', current_time( 'timestamp' ) ) . '01' ) );
if ( ! $end_date ) if ( ! $end_date )
$end_date = date( 'Ymd', current_time( 'timestamp' ) ); $end_date = date( 'Ymd', current_time( 'timestamp' ) );
@ -912,10 +912,10 @@ function woocommerce_top_sellers() {
// Get order ids and dates in range // Get order ids and dates in range
$order_items = $wpdb->get_results( " $order_items = $wpdb->get_results( "
SELECT order_item_meta_2.meta_value as product_id, SUM( order_item_meta.meta_value ) as item_quantity FROM {$wpdb->prefix}woocommerce_order_items as order_items SELECT order_item_meta_2.meta_value as product_id, SUM( order_item_meta.meta_value ) as item_quantity FROM {$wpdb->prefix}woocommerce_order_items as order_items
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id
LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID
LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID = rel.object_ID LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID = rel.object_ID
LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id ) LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id )
LEFT JOIN {$wpdb->terms} AS term USING( term_id ) LEFT JOIN {$wpdb->terms} AS term USING( term_id )
@ -931,7 +931,7 @@ function woocommerce_top_sellers() {
AND order_item_meta_2.meta_key = '_product_id' AND order_item_meta_2.meta_key = '_product_id'
GROUP BY order_item_meta_2.meta_value GROUP BY order_item_meta_2.meta_value
" ); " );
$found_products = array(); $found_products = array();
if ( $order_items ) { if ( $order_items ) {
@ -961,7 +961,7 @@ function woocommerce_top_sellers() {
foreach ( $found_products as $product_id => $sales ) { foreach ( $found_products as $product_id => $sales ) {
$width = $sales > 0 ? ( $sales / $max_sales ) * 100 : 0; $width = $sales > 0 ? ( $sales / $max_sales ) * 100 : 0;
$product_title = get_the_title( $product_id ); $product_title = get_the_title( $product_id );
if ( $product_title ) { if ( $product_title ) {
$product_name = '<a href="' . get_permalink( $product_id ) . '">'. __( $product_title ) .'</a>'; $product_name = '<a href="' . get_permalink( $product_id ) . '">'. __( $product_title ) .'</a>';
$orders_link = admin_url( 'edit.php?s&post_status=all&post_type=shop_order&action=-1&s=' . urlencode( $product_title ) . '&shop_order_status=completed,processing,on-hold' ); $orders_link = admin_url( 'edit.php?s&post_status=all&post_type=shop_order&action=-1&s=' . urlencode( $product_title ) . '&shop_order_status=completed,processing,on-hold' );
@ -997,21 +997,21 @@ function woocommerce_top_earners() {
$start_date = isset( $_POST['start_date'] ) ? $_POST['start_date'] : ''; $start_date = isset( $_POST['start_date'] ) ? $_POST['start_date'] : '';
$end_date = isset( $_POST['end_date'] ) ? $_POST['end_date'] : ''; $end_date = isset( $_POST['end_date'] ) ? $_POST['end_date'] : '';
if ( ! $start_date ) if ( ! $start_date )
$start_date = date( 'Ymd', strtotime( date('Ym', current_time( 'timestamp' ) ) . '01' ) ); $start_date = date( 'Ymd', strtotime( date('Ym', current_time( 'timestamp' ) ) . '01' ) );
if ( ! $end_date ) if ( ! $end_date )
$end_date = date( 'Ymd', current_time( 'timestamp' ) ); $end_date = date( 'Ymd', current_time( 'timestamp' ) );
$start_date = strtotime( $start_date ); $start_date = strtotime( $start_date );
$end_date = strtotime( $end_date ); $end_date = strtotime( $end_date );
// Get order ids and dates in range // Get order ids and dates in range
$order_items = $wpdb->get_results( " $order_items = $wpdb->get_results( "
SELECT order_item_meta_2.meta_value as product_id, SUM( order_item_meta.meta_value ) as line_total FROM {$wpdb->prefix}woocommerce_order_items as order_items SELECT order_item_meta_2.meta_value as product_id, SUM( order_item_meta.meta_value ) as line_total FROM {$wpdb->prefix}woocommerce_order_items as order_items
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id
LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID
LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID = rel.object_ID LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID = rel.object_ID
LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id ) LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id )
LEFT JOIN {$wpdb->terms} AS term USING( term_id ) LEFT JOIN {$wpdb->terms} AS term USING( term_id )
@ -1035,7 +1035,7 @@ function woocommerce_top_earners() {
$found_products[ $order_item->product_id ] = $order_item->line_total; $found_products[ $order_item->product_id ] = $order_item->line_total;
} }
} }
asort( $found_products ); asort( $found_products );
$found_products = array_reverse( $found_products, true ); $found_products = array_reverse( $found_products, true );
$found_products = array_slice( $found_products, 0, 25, true ); $found_products = array_slice( $found_products, 0, 25, true );
@ -1058,7 +1058,7 @@ function woocommerce_top_earners() {
$width = $sales > 0 ? ( round( $sales ) / round( $max_sales ) ) * 100 : 0; $width = $sales > 0 ? ( round( $sales ) / round( $max_sales ) ) * 100 : 0;
$product_title = get_the_title( $product_id ); $product_title = get_the_title( $product_id );
if ( $product_title ) { if ( $product_title ) {
$product_name = '<a href="'.get_permalink( $product_id ).'">'. __( $product_title ) .'</a>'; $product_name = '<a href="'.get_permalink( $product_id ).'">'. __( $product_title ) .'</a>';
$orders_link = admin_url( 'edit.php?s&post_status=all&post_type=shop_order&action=-1&s=' . urlencode( $product_title ) . '&shop_order_status=completed,processing,on-hold' ); $orders_link = admin_url( 'edit.php?s&post_status=all&post_type=shop_order&action=-1&s=' . urlencode( $product_title ) . '&shop_order_status=completed,processing,on-hold' );
@ -1113,22 +1113,22 @@ function woocommerce_product_sales() {
// Get order items // Get order items
$order_items = $wpdb->get_results( " $order_items = $wpdb->get_results( "
SELECT order_item_meta_2.meta_value as product_id, posts.post_date, SUM( order_item_meta.meta_value ) as item_quantity, SUM( order_item_meta_3.meta_value ) as line_total SELECT order_item_meta_2.meta_value as product_id, posts.post_date, SUM( order_item_meta.meta_value ) as item_quantity, SUM( order_item_meta_3.meta_value ) as line_total
FROM {$wpdb->prefix}woocommerce_order_items as order_items FROM {$wpdb->prefix}woocommerce_order_items as order_items
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta_3 ON order_items.order_item_id = order_item_meta_3.order_item_id LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta_3 ON order_items.order_item_id = order_item_meta_3.order_item_id
LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID
LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID = rel.object_ID LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID = rel.object_ID
LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id ) LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id )
LEFT JOIN {$wpdb->terms} AS term USING( term_id ) LEFT JOIN {$wpdb->terms} AS term USING( term_id )
WHERE posts.post_type = 'shop_order' WHERE posts.post_type = 'shop_order'
AND order_item_meta_2.meta_value IN ('" . implode( "','", array_merge( $chosen_product_ids, $children_ids ) ) . "') AND order_item_meta_2.meta_value IN ('" . implode( "','", array_merge( $chosen_product_ids, $children_ids ) ) . "')
AND posts.post_status = 'publish' AND posts.post_status = 'publish'
AND tax.taxonomy = 'shop_order_status' AND tax.taxonomy = 'shop_order_status'
AND term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "') AND term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "')
AND order_items.order_item_type = 'line_item' AND order_items.order_item_type = 'line_item'
AND order_item_meta.meta_key = '_qty' AND order_item_meta.meta_key = '_qty'
AND order_item_meta_2.meta_key = '_product_id' AND order_item_meta_2.meta_key = '_product_id'
@ -1138,27 +1138,27 @@ function woocommerce_product_sales() {
" ); " );
$found_products = array(); $found_products = array();
if ( $order_items ) { if ( $order_items ) {
foreach ( $order_items as $order_item ) { foreach ( $order_items as $order_item ) {
if ( $order_item->line_total == 0 && $order_item->item_quantity == 0 ) if ( $order_item->line_total == 0 && $order_item->item_quantity == 0 )
continue; continue;
// Get date // Get date
$date = date( 'Ym', strtotime( $order_item->post_date ) ); $date = date( 'Ym', strtotime( $order_item->post_date ) );
// Set values // Set values
$product_sales[ $date ] = isset( $product_sales[ $date ] ) ? $product_sales[ $date ] + $order_item->item_quantity : $order_item->item_quantity; $product_sales[ $date ] = isset( $product_sales[ $date ] ) ? $product_sales[ $date ] + $order_item->item_quantity : $order_item->item_quantity;
$product_totals[ $date ] = isset( $product_totals[ $date ] ) ? $product_totals[ $date ] + $order_item->line_total : $order_item->line_total; $product_totals[ $date ] = isset( $product_totals[ $date ] ) ? $product_totals[ $date ] + $order_item->line_total : $order_item->line_total;
if ( $product_sales[ $date ] > $max_sales ) if ( $product_sales[ $date ] > $max_sales )
$max_sales = $product_sales[ $date ]; $max_sales = $product_sales[ $date ];
if ( $product_totals[ $date ] > $max_totals ) if ( $product_totals[ $date ] > $max_totals )
$max_totals = $product_totals[ $date ]; $max_totals = $product_totals[ $date ];
} }
} }
?> ?>
<h4><?php printf( __( 'Sales for %s:', 'woocommerce' ), implode( ', ', $chosen_product_titles ) ); ?></h4> <h4><?php printf( __( 'Sales for %s:', 'woocommerce' ), implode( ', ', $chosen_product_titles ) ); ?></h4>
<table class="bar_chart"> <table class="bar_chart">
@ -1174,9 +1174,9 @@ function woocommerce_product_sales() {
foreach ( $product_sales as $date => $sales ) { foreach ( $product_sales as $date => $sales ) {
$width = ($sales>0) ? (round($sales) / round($max_sales)) * 100 : 0; $width = ($sales>0) ? (round($sales) / round($max_sales)) * 100 : 0;
$width2 = ($product_totals[$date]>0) ? (round($product_totals[$date]) / round($max_totals)) * 100 : 0; $width2 = ($product_totals[$date]>0) ? (round($product_totals[$date]) / round($max_totals)) * 100 : 0;
$orders_link = admin_url( 'edit.php?s&post_status=all&post_type=shop_order&action=-1&s=' . urlencode( implode( ' ', $chosen_product_titles ) ) . '&m=' . date( 'Ym', strtotime( $date . '01' ) ) . '&shop_order_status=completed,processing,on-hold' ); $orders_link = admin_url( 'edit.php?s&post_status=all&post_type=shop_order&action=-1&s=' . urlencode( implode( ' ', $chosen_product_titles ) ) . '&m=' . date( 'Ym', strtotime( $date . '01' ) ) . '&shop_order_status=completed,processing,on-hold' );
echo '<tr><th><a href="' . esc_url( $orders_link ) . '">' . date_i18n( 'F', strtotime( $date . '01' ) ) . '</a></th> echo '<tr><th><a href="' . esc_url( $orders_link ) . '">' . date_i18n( 'F', strtotime( $date . '01' ) ) . '</a></th>
<td width="1%"><span>' . esc_html( $sales ) . '</span><span class="alt">' . woocommerce_price( $product_totals[ $date ] ) . '</span></td> <td width="1%"><span>' . esc_html( $sales ) . '</span><span class="alt">' . woocommerce_price( $product_totals[ $date ] ) . '</span></td>
<td class="bars"> <td class="bars">
@ -1198,7 +1198,7 @@ function woocommerce_product_sales() {
<p><select id="product_ids" name="product_ids[]" class="ajax_chosen_select_products" multiple="multiple" data-placeholder="<?php _e( 'Search for a product&hellip;', 'woocommerce' ); ?>" style="width: 400px;"></select> <input type="submit" style="vertical-align: top;" class="button" value="<?php _e( 'Show', 'woocommerce' ); ?>" /></p> <p><select id="product_ids" name="product_ids[]" class="ajax_chosen_select_products" multiple="multiple" data-placeholder="<?php _e( 'Search for a product&hellip;', 'woocommerce' ); ?>" style="width: 400px;"></select> <input type="submit" style="vertical-align: top;" class="button" value="<?php _e( 'Show', 'woocommerce' ); ?>" /></p>
<script type="text/javascript"> <script type="text/javascript">
jQuery(function(){ jQuery(function(){
// Ajax Chosen Product Selectors // Ajax Chosen Product Selectors
jQuery("select.ajax_chosen_select_products").ajaxChosen({ jQuery("select.ajax_chosen_select_products").ajaxChosen({
method: 'GET', method: 'GET',
@ -1219,7 +1219,7 @@ function woocommerce_product_sales() {
return terms; return terms;
}); });
}); });
</script> </script>
</form> </form>
@ -1700,22 +1700,22 @@ function woocommerce_monthly_taxes() {
" ); " );
$tax_rows = $wpdb->get_results( " $tax_rows = $wpdb->get_results( "
SELECT SELECT
order_items.order_item_name as name, order_items.order_item_name as name,
SUM( order_item_meta.meta_value ) as tax_amount, SUM( order_item_meta.meta_value ) as tax_amount,
SUM( order_item_meta_2.meta_value ) as shipping_tax_amount, SUM( order_item_meta_2.meta_value ) as shipping_tax_amount,
SUM( order_item_meta.meta_value + order_item_meta_2.meta_value ) as total_tax_amount SUM( order_item_meta.meta_value + order_item_meta_2.meta_value ) as total_tax_amount
FROM {$wpdb->prefix}woocommerce_order_items as order_items FROM {$wpdb->prefix}woocommerce_order_items as order_items
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id
LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID
LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID = rel.object_ID LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID = rel.object_ID
LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id ) LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id )
LEFT JOIN {$wpdb->terms} AS term USING( term_id ) LEFT JOIN {$wpdb->terms} AS term USING( term_id )
WHERE order_items.order_item_type = 'tax' WHERE order_items.order_item_type = 'tax'
AND posts.post_type = 'shop_order' AND posts.post_type = 'shop_order'
AND posts.post_status = 'publish' AND posts.post_status = 'publish'
@ -1724,10 +1724,10 @@ function woocommerce_monthly_taxes() {
AND '{$month}' = date_format( posts.post_date,'%%Y%%m' ) AND '{$month}' = date_format( posts.post_date,'%%Y%%m' )
AND order_item_meta.meta_key = 'tax_amount' AND order_item_meta.meta_key = 'tax_amount'
AND order_item_meta_2.meta_key = 'shipping_tax_amount' AND order_item_meta_2.meta_key = 'shipping_tax_amount'
GROUP BY order_items.order_item_name GROUP BY order_items.order_item_name
" ); " );
if ( $tax_rows ) { if ( $tax_rows ) {
foreach ( $tax_rows as $tax_row ) { foreach ( $tax_rows as $tax_row ) {
$tax_row_labels[] = $tax_row->name; $tax_row_labels[] = $tax_row->name;
@ -1864,19 +1864,19 @@ function woocommerce_monthly_taxes() {
<td class="total_row">' . woocommerce_price( $tax['total_tax'] ) . '</td> <td class="total_row">' . woocommerce_price( $tax['total_tax'] ) . '</td>
<td class="total_row">' . woocommerce_price( $tax['gross'] - $tax['shipping'] - $tax['total_tax'] ) . '</td>'; <td class="total_row">' . woocommerce_price( $tax['gross'] - $tax['shipping'] - $tax['total_tax'] ) . '</td>';
foreach ( $tax_row_labels as $label ) { foreach ( $tax_row_labels as $label ) {
$row_total = 0; $row_total = 0;
foreach ( $tax['tax_rows'] as $tax_row ) { foreach ( $tax['tax_rows'] as $tax_row ) {
if ( $tax_row->name == $label ) { if ( $tax_row->name == $label ) {
$row_total = $tax_row->total_tax_amount; $row_total = $tax_row->total_tax_amount;
} }
} }
echo '<td class="tax_row">' . woocommerce_price( $row_total ) . '</td>'; echo '<td class="tax_row">' . woocommerce_price( $row_total ) . '</td>';
} }
echo '</tr>'; echo '</tr>';
@ -1899,7 +1899,7 @@ function woocommerce_monthly_taxes() {
/** /**
* woocommerce_category_sales function. * woocommerce_category_sales function.
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -1911,7 +1911,7 @@ function woocommerce_category_sales() {
$current_year = isset( $_POST['show_year'] ) ? $_POST['show_year'] : date( 'Y', current_time( 'timestamp' ) ); $current_year = isset( $_POST['show_year'] ) ? $_POST['show_year'] : date( 'Y', current_time( 'timestamp' ) );
$start_date = strtotime( $current_year . '0101' ); $start_date = strtotime( $current_year . '0101' );
$categories = get_terms( 'product_cat', array( 'parent' => 0 ) ); $categories = get_terms( 'product_cat', array( 'parent' => 0 ) );
?> ?>
<form method="post" action="" class="report_filters"> <form method="post" action="" class="report_filters">
@ -1919,11 +1919,11 @@ function woocommerce_category_sales() {
<label for="show_year"><?php _e( 'Show:', 'woocommerce' ); ?></label> <label for="show_year"><?php _e( 'Show:', 'woocommerce' ); ?></label>
<select name="show_year" id="show_year"> <select name="show_year" id="show_year">
<?php <?php
for ( $i = $first_year; $i <= date( 'Y' ); $i++ ) for ( $i = $first_year; $i <= date( 'Y' ); $i++ )
printf( '<option value="%s" %s>%s</option>', $i, selected( $current_year, $i, false ), $i ); printf( '<option value="%s" %s>%s</option>', $i, selected( $current_year, $i, false ), $i );
?> ?>
</select> </select>
<select multiple="multiple" class="chosen_select" id="show_categories" name="show_categories[]" style="width: 300px;"> <select multiple="multiple" class="chosen_select" id="show_categories" name="show_categories[]" style="width: 300px;">
<?php <?php
foreach ( $categories as $category ) { foreach ( $categories as $category ) {
@ -1931,7 +1931,7 @@ function woocommerce_category_sales() {
$prepend = '&mdash; '; $prepend = '&mdash; ';
else else
$prepend = ''; $prepend = '';
echo '<option value="' . $category->term_id . '" ' . selected( ! empty( $_POST['show_categories'] ) && in_array( $category->term_id, $_POST['show_categories'] ), true ) . '>' . $prepend . $category->name . '</option>'; echo '<option value="' . $category->term_id . '" ' . selected( ! empty( $_POST['show_categories'] ) && in_array( $category->term_id, $_POST['show_categories'] ), true ) . '>' . $prepend . $category->name . '</option>';
} }
?> ?>
@ -1946,14 +1946,14 @@ function woocommerce_category_sales() {
// Get order items // Get order items
$start_date = date( 'Ym', strtotime( date( 'Ym', strtotime( '-1 year', $start_date ) ) . '01' ) ); $start_date = date( 'Ym', strtotime( date( 'Ym', strtotime( '-1 year', $start_date ) ) . '01' ) );
$order_items = $wpdb->get_results( " $order_items = $wpdb->get_results( "
SELECT order_item_meta_2.meta_value as product_id, posts.post_date, SUM( order_item_meta.meta_value ) as line_total SELECT order_item_meta_2.meta_value as product_id, posts.post_date, SUM( order_item_meta.meta_value ) as line_total
FROM {$wpdb->prefix}woocommerce_order_items as order_items FROM {$wpdb->prefix}woocommerce_order_items as order_items
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id
LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID
LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID = rel.object_ID LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID = rel.object_ID
LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id ) LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id )
LEFT JOIN {$wpdb->terms} AS term USING( term_id ) LEFT JOIN {$wpdb->terms} AS term USING( term_id )
@ -1961,7 +1961,7 @@ function woocommerce_category_sales() {
WHERE posts.post_type = 'shop_order' WHERE posts.post_type = 'shop_order'
AND posts.post_status = 'publish' AND posts.post_status = 'publish'
AND tax.taxonomy = 'shop_order_status' AND tax.taxonomy = 'shop_order_status'
AND term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "') AND term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "')
AND date_format(posts.post_date,'%%Y%%m') >= '{$start_date}' AND date_format(posts.post_date,'%%Y%%m') >= '{$start_date}'
AND order_items.order_item_type = 'line_item' AND order_items.order_item_type = 'line_item'
AND order_item_meta.meta_key = '_line_total' AND order_item_meta.meta_key = '_line_total'
@ -1969,23 +1969,23 @@ function woocommerce_category_sales() {
GROUP BY order_items.order_id GROUP BY order_items.order_id
ORDER BY posts.post_date ASC ORDER BY posts.post_date ASC
" ); " );
if ( $order_items ) { if ( $order_items ) {
foreach ( $order_items as $order_item ) { foreach ( $order_items as $order_item ) {
$month = date( 'm', strtotime( $order_item->post_date ) ) - 1; $month = date( 'm', strtotime( $order_item->post_date ) ) - 1;
$item_sales[ $month ][ $order_item->product_id ] = isset( $item_sales[ $month ][ $order_item->product_id ] ) ? $item_sales[ $month ][ $order_item->product_id ] + $order_item->line_total : $order_item->line_total; $item_sales[ $month ][ $order_item->product_id ] = isset( $item_sales[ $month ][ $order_item->product_id ] ) ? $item_sales[ $month ][ $order_item->product_id ] + $order_item->line_total : $order_item->line_total;
} }
} }
if ( ! empty( $_POST['show_categories'] ) && sizeof( $_POST['show_categories'] ) > 0 ) { if ( ! empty( $_POST['show_categories'] ) && sizeof( $_POST['show_categories'] ) > 0 ) {
$show_categories = $include_categories = array_map( 'absint', $_POST['show_categories'] ); $show_categories = $include_categories = array_map( 'absint', $_POST['show_categories'] );
foreach( $show_categories as $cat ) foreach( $show_categories as $cat )
$include_categories = array_merge( $include_categories, get_term_children( $cat, 'product_cat' ) ); $include_categories = array_merge( $include_categories, get_term_children( $cat, 'product_cat' ) );
$categories = get_terms( 'product_cat', array( 'include' => array_unique( $include_categories ) ) ); $categories = get_terms( 'product_cat', array( 'include' => array_unique( $include_categories ) ) );
?> ?>
<div class="woocommerce-wide-reports-wrap"> <div class="woocommerce-wide-reports-wrap">
@ -1993,10 +1993,10 @@ function woocommerce_category_sales() {
<thead> <thead>
<tr> <tr>
<th><?php _e( 'Category', 'woocommerce' ); ?></th> <th><?php _e( 'Category', 'woocommerce' ); ?></th>
<?php <?php
$column_count = 0; $column_count = 0;
for ( $count = 0; $count < 12; $count++ ) : for ( $count = 0; $count < 12; $count++ ) :
if ( $count >= date ( 'm' ) && $current_year == date( 'Y' ) ) if ( $count >= date ( 'm' ) && $current_year == date( 'Y' ) )
continue; continue;
$column_count++; $column_count++;
?> ?>
@ -2009,34 +2009,34 @@ function woocommerce_category_sales() {
// While outputting, lets store them for the chart // While outputting, lets store them for the chart
$chart_data = $month_totals = $category_totals = array(); $chart_data = $month_totals = $category_totals = array();
$top_cat = $bottom_cat = $top_cat_name = $bottom_cat_name = ''; $top_cat = $bottom_cat = $top_cat_name = $bottom_cat_name = '';
for ( $count = 0; $count < 12; $count++ ) for ( $count = 0; $count < 12; $count++ )
if ( $count >= date( 'm' ) && $current_year == date( 'Y' ) ) if ( $count >= date( 'm' ) && $current_year == date( 'Y' ) )
break; break;
else else
$month_totals[ $count ] = 0; $month_totals[ $count ] = 0;
foreach ( $categories as $category ) { foreach ( $categories as $category ) {
$cat_total = 0; $cat_total = 0;
$category_chart_data = $term_ids = array(); $category_chart_data = $term_ids = array();
$term_ids = get_term_children( $category->term_id, 'product_cat' ); $term_ids = get_term_children( $category->term_id, 'product_cat' );
$term_ids[] = $category->term_id; $term_ids[] = $category->term_id;
$product_ids = get_objects_in_term( $term_ids, 'product_cat' ); $product_ids = get_objects_in_term( $term_ids, 'product_cat' );
if ( $category->parent > 0 ) if ( $category->parent > 0 )
$prepend = '&mdash; '; $prepend = '&mdash; ';
else else
$prepend = ''; $prepend = '';
$category_sales_html = '<tr><th>' . $prepend . $category->name . '</th>'; $category_sales_html = '<tr><th>' . $prepend . $category->name . '</th>';
for ( $count = 0; $count < 12; $count++ ) { for ( $count = 0; $count < 12; $count++ ) {
if ( $count >= date( 'm' ) && $current_year == date( 'Y' ) ) if ( $count >= date( 'm' ) && $current_year == date( 'Y' ) )
continue; continue;
if ( ! empty( $item_sales[ $count ] ) ) { if ( ! empty( $item_sales[ $count ] ) ) {
$matches = array_intersect_key( $item_sales[ $count ], array_flip( $product_ids ) ); $matches = array_intersect_key( $item_sales[ $count ], array_flip( $product_ids ) );
$total = array_sum( $matches ); $total = array_sum( $matches );
@ -2044,41 +2044,41 @@ function woocommerce_category_sales() {
} else { } else {
$total = 0; $total = 0;
} }
$month_totals[ $count ] += $total; $month_totals[ $count ] += $total;
$category_sales_html .= '<td>' . woocommerce_price( $total ) . '</td>'; $category_sales_html .= '<td>' . woocommerce_price( $total ) . '</td>';
$category_chart_data[] = array( strtotime( date( 'Ymd', strtotime( '2012-' . ( $count + 1 ) . '-01' ) ) ) . '000', $total ); $category_chart_data[] = array( strtotime( date( 'Ymd', strtotime( '2012-' . ( $count + 1 ) . '-01' ) ) ) . '000', $total );
} }
if ( $cat_total == 0 ) if ( $cat_total == 0 )
continue; continue;
$category_totals[] = $cat_total; $category_totals[] = $cat_total;
$category_sales_html .= '<td><strong>' . woocommerce_price( $cat_total ) . '</strong></td>'; $category_sales_html .= '<td><strong>' . woocommerce_price( $cat_total ) . '</strong></td>';
$category_sales_html .= '</tr>'; $category_sales_html .= '</tr>';
echo $category_sales_html; echo $category_sales_html;
$chart_data[ $category->name ] = $category_chart_data; $chart_data[ $category->name ] = $category_chart_data;
if ( $cat_total > $top_cat ) { if ( $cat_total > $top_cat ) {
$top_cat = $cat_total; $top_cat = $cat_total;
$top_cat_name = $category->name; $top_cat_name = $category->name;
} }
if ( $cat_total < $bottom_cat || $bottom_cat === '' ) { if ( $cat_total < $bottom_cat || $bottom_cat === '' ) {
$bottom_cat = $cat_total; $bottom_cat = $cat_total;
$bottom_cat_name = $category->name; $bottom_cat_name = $category->name;
} }
} }
sort( $category_totals ); sort( $category_totals );
echo '<tr><th><strong>' . __( 'Total', 'woocommerce' ) . '</strong></th>'; echo '<tr><th><strong>' . __( 'Total', 'woocommerce' ) . '</strong></th>';
for ( $count = 0; $count < 12; $count++ ) for ( $count = 0; $count < 12; $count++ )
if ( $count >= date( 'm' ) && $current_year == date( 'Y' ) ) if ( $count >= date( 'm' ) && $current_year == date( 'Y' ) )
@ -2086,11 +2086,11 @@ function woocommerce_category_sales() {
else else
echo '<td><strong>' . woocommerce_price( $month_totals[ $count ] ) . '</strong></td>'; echo '<td><strong>' . woocommerce_price( $month_totals[ $count ] ) . '</strong></td>';
echo '<td><strong>' . woocommerce_price( array_sum( $month_totals ) ) . '</strong></td></tr>'; echo '<td><strong>' . woocommerce_price( array_sum( $month_totals ) ) . '</strong></td></tr>';
?></tbody> ?></tbody>
</table> </table>
</div> </div>
<div id="poststuff" class="woocommerce-reports-wrap"> <div id="poststuff" class="woocommerce-reports-wrap">
<div class="woocommerce-reports-sidebar"> <div class="woocommerce-reports-sidebar">
<div class="postbox"> <div class="postbox">
@ -2128,10 +2128,10 @@ function woocommerce_category_sales() {
if ( sizeof( $category_totals ) == 0 ) if ( sizeof( $category_totals ) == 0 )
echo __( 'N/A', 'woocommerce' ); echo __( 'N/A', 'woocommerce' );
elseif ( sizeof( $category_totals ) % 2 ) elseif ( sizeof( $category_totals ) % 2 )
echo woocommerce_price( echo woocommerce_price(
( (
$category_totals[ floor( sizeof( $category_totals ) / 2 ) ] + $category_totals[ ceil( sizeof( $category_totals ) / 2 ) ] $category_totals[ floor( sizeof( $category_totals ) / 2 ) ] + $category_totals[ ceil( sizeof( $category_totals ) / 2 ) ]
) / 2 ) / 2
); );
else else
echo woocommerce_price( $category_totals[ sizeof( $category_totals ) / 2 ] ); echo woocommerce_price( $category_totals[ sizeof( $category_totals ) / 2 ] );
@ -2151,7 +2151,7 @@ function woocommerce_category_sales() {
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
jQuery(function(){ jQuery(function(){
<?php <?php
// Variables // Variables
foreach ( $chart_data as $name => $data ) { foreach ( $chart_data as $name => $data ) {
@ -2159,17 +2159,17 @@ function woocommerce_category_sales() {
echo 'var ' . $varname . ' = jQuery.parseJSON( \'' . json_encode( $data ) . '\' );'; echo 'var ' . $varname . ' = jQuery.parseJSON( \'' . json_encode( $data ) . '\' );';
} }
?> ?>
var placeholder = jQuery("#placeholder"); var placeholder = jQuery("#placeholder");
var plot = jQuery.plot(placeholder, [ var plot = jQuery.plot(placeholder, [
<?php <?php
$labels = array(); $labels = array();
foreach ( $chart_data as $name => $data ) { foreach ( $chart_data as $name => $data ) {
$labels[] = '{ label: "' . esc_js( $name ) . '", data: ' . 'cat_' . str_replace( '-', '_', sanitize_title( $name ) ) . '_data }'; $labels[] = '{ label: "' . esc_js( $name ) . '", data: ' . 'cat_' . str_replace( '-', '_', sanitize_title( $name ) ) . '_data }';
} }
echo implode( ',', $labels ); echo implode( ',', $labels );
?> ?>
], { ], {
@ -2196,9 +2196,9 @@ function woocommerce_category_sales() {
}, },
yaxes: [ { min: 0, tickDecimals: 2 } ] yaxes: [ { min: 0, tickDecimals: 2 } ]
}); });
placeholder.resize(); placeholder.resize();
<?php woocommerce_tooltip_js(); ?> <?php woocommerce_tooltip_js(); ?>
}); });
</script> </script>
@ -2215,7 +2215,7 @@ function woocommerce_category_sales() {
/** /**
* woocommerce_coupon_sales function. * woocommerce_coupon_sales function.
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -2227,42 +2227,42 @@ function woocommerce_coupon_sales() {
$current_year = isset( $_POST['show_year'] ) ? $_POST['show_year'] : date( 'Y', current_time( 'timestamp' ) ); $current_year = isset( $_POST['show_year'] ) ? $_POST['show_year'] : date( 'Y', current_time( 'timestamp' ) );
$start_date = strtotime( $current_year . '0101' ); $start_date = strtotime( $current_year . '0101' );
$order_statuses = implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ); $order_statuses = implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) );
$coupons = $wpdb->get_col( " $coupons = $wpdb->get_col( "
SELECT DISTINCT meta.meta_value FROM {$wpdb->postmeta} AS meta SELECT DISTINCT meta.meta_value FROM {$wpdb->postmeta} AS meta
LEFT JOIN {$wpdb->posts} AS posts ON posts.ID = meta.post_id LEFT JOIN {$wpdb->posts} AS posts ON posts.ID = meta.post_id
LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID
LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id ) LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id )
LEFT JOIN {$wpdb->terms} AS term USING( term_id ) LEFT JOIN {$wpdb->terms} AS term USING( term_id )
WHERE meta.meta_key = 'coupons' WHERE meta.meta_key = 'coupons'
AND posts.post_type = 'shop_order' AND posts.post_type = 'shop_order'
AND posts.post_status = 'publish' AND posts.post_status = 'publish'
AND tax.taxonomy = 'shop_order_status' AND tax.taxonomy = 'shop_order_status'
AND term.slug IN ('{$order_statuses}') AND term.slug IN ('{$order_statuses}')
" ); " );
?> ?>
<form method="post" action="" class="report_filters"> <form method="post" action="" class="report_filters">
<p> <p>
<label for="show_year"><?php _e( 'Show:', 'woocommerce' ); ?></label> <label for="show_year"><?php _e( 'Show:', 'woocommerce' ); ?></label>
<select name="show_year" id="show_year"> <select name="show_year" id="show_year">
<?php <?php
for ( $i = $first_year; $i <= date( 'Y' ); $i++ ) for ( $i = $first_year; $i <= date( 'Y' ); $i++ )
printf( '<option value="%s" %s>%s</option>', $i, selected( $current_year, $i, false ), $i ); printf( '<option value="%s" %s>%s</option>', $i, selected( $current_year, $i, false ), $i );
?> ?>
</select> </select>
<select multiple="multiple" class="chosen_select" id="show_coupons" name="show_coupons[]" style="width: 300px;"> <select multiple="multiple" class="chosen_select" id="show_coupons" name="show_coupons[]" style="width: 300px;">
<?php <?php
foreach ( $coupons as $coupon ) { foreach ( $coupons as $coupon ) {
echo '<option value="' . $coupon . '" ' . selected( ! empty( $_POST['show_coupons'] ) && in_array( $coupon, $_POST['show_coupons'] ), true ) . '>' . $coupon . '</option>'; echo '<option value="' . $coupon . '" ' . selected( ! empty( $_POST['show_coupons'] ) && in_array( $coupon, $_POST['show_coupons'] ), true ) . '>' . $coupon . '</option>';
} }
?> ?>
@ -2271,25 +2271,25 @@ function woocommerce_coupon_sales() {
<input type="submit" class="button" value="<?php _e( 'Show', 'woocommerce' ); ?>" /> <input type="submit" class="button" value="<?php _e( 'Show', 'woocommerce' ); ?>" />
</p> </p>
</form> </form>
<?php <?php
if ( ! empty( $_POST['show_coupons'] ) && count( $_POST['show_coupons'] ) > 0 ) : if ( ! empty( $_POST['show_coupons'] ) && count( $_POST['show_coupons'] ) > 0 ) :
$coupons = $_POST['show_coupons']; $coupons = $_POST['show_coupons'];
$coupon_sales = $monthly_totals = array(); $coupon_sales = $monthly_totals = array();
foreach( $coupons as $coupon ) : foreach( $coupons as $coupon ) :
$monthly_sales = $wpdb->get_results( $wpdb->prepare( " $monthly_sales = $wpdb->get_results( $wpdb->prepare( "
SELECT SUM(postmeta.meta_value) AS order_total, date_format(posts.post_date, '%%Y%%m') as month FROM {$wpdb->posts} AS posts SELECT SUM(postmeta.meta_value) AS order_total, date_format(posts.post_date, '%%Y%%m') as month FROM {$wpdb->posts} AS posts
INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID=postmeta.post_ID INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID=postmeta.post_ID
INNER JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID INNER JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID
INNER JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id ) INNER JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id )
INNER JOIN {$wpdb->terms} AS term USING( term_id ) INNER JOIN {$wpdb->terms} AS term USING( term_id )
WHERE postmeta.meta_key = '_order_total' WHERE postmeta.meta_key = '_order_total'
AND tax.taxonomy = 'shop_order_status' AND tax.taxonomy = 'shop_order_status'
AND term.slug IN ('{$order_statuses}') AND term.slug IN ('{$order_statuses}')
@ -2298,18 +2298,18 @@ function woocommerce_coupon_sales() {
AND '{$current_year}' = date_format(posts.post_date,'%%Y') AND '{$current_year}' = date_format(posts.post_date,'%%Y')
AND posts.ID IN ( AND posts.ID IN (
SELECT post_id FROM {$wpdb->postmeta} AS meta SELECT post_id FROM {$wpdb->postmeta} AS meta
WHERE meta.meta_key = 'coupons' WHERE meta.meta_key = 'coupons'
AND meta.meta_value = '%s' AND meta.meta_value = '%s'
) )
GROUP BY month", $coupon ), OBJECT ); GROUP BY month", $coupon ), OBJECT );
foreach( $monthly_sales as $sales ) { foreach( $monthly_sales as $sales ) {
$month = $sales->month; $month = $sales->month;
$coupon_sales[$coupon][$month] = $sales->order_total; $coupon_sales[$coupon][$month] = $sales->order_total;
} }
endforeach; endforeach;
?> ?>
<div class="woocommerce-wide-reports-wrap"> <div class="woocommerce-wide-reports-wrap">
@ -2317,16 +2317,16 @@ function woocommerce_coupon_sales() {
<thead> <thead>
<tr> <tr>
<th><?php _e( 'Coupon', 'woocommerce' ); ?></th> <th><?php _e( 'Coupon', 'woocommerce' ); ?></th>
<?php <?php
$column_count = 0; $column_count = 0;
for ( $count = 0; $count < 12; $count++ ) : for ( $count = 0; $count < 12; $count++ ) :
if ( $count >= date ( 'm' ) && $current_year == date( 'Y' ) ) if ( $count >= date ( 'm' ) && $current_year == date( 'Y' ) )
continue; continue;
$month = date( 'Ym', strtotime( date( 'Ym', strtotime( '+ '. $count . ' MONTH', $start_date ) ) . '01' ) ); $month = date( 'Ym', strtotime( date( 'Ym', strtotime( '+ '. $count . ' MONTH', $start_date ) ) . '01' ) );
// set elements before += them below // set elements before += them below
$monthly_totals[$month] = 0; $monthly_totals[$month] = 0;
$column_count++; $column_count++;
?> ?>
<th><?php echo date( 'F', strtotime( '2012-' . ( $count + 1 ) . '-01' ) ); ?></th> <th><?php echo date( 'F', strtotime( '2012-' . ( $count + 1 ) . '-01' ) ); ?></th>
@ -2334,61 +2334,61 @@ function woocommerce_coupon_sales() {
<th><strong><?php _e( 'Total', 'woocommerce' ); ?></strong></th> <th><strong><?php _e( 'Total', 'woocommerce' ); ?></strong></th>
</tr> </tr>
</thead> </thead>
<tbody><?php <tbody><?php
// save data for chart while outputting // save data for chart while outputting
$chart_data = $coupon_totals = array(); $chart_data = $coupon_totals = array();
foreach( $coupon_sales as $coupon_code => $sales ) { foreach( $coupon_sales as $coupon_code => $sales ) {
echo '<tr><th>' . esc_html( $coupon_code ) . '</th>'; echo '<tr><th>' . esc_html( $coupon_code ) . '</th>';
for ( $count = 0; $count < 12; $count ++ ) { for ( $count = 0; $count < 12; $count ++ ) {
if ( $count >= date ( 'm' ) && $current_year == date( 'Y' ) ) if ( $count >= date ( 'm' ) && $current_year == date( 'Y' ) )
continue; continue;
$month = date( 'Ym', strtotime( date( 'Ym', strtotime( '+ '. $count . ' MONTH', $start_date ) ) . '01' ) ); $month = date( 'Ym', strtotime( date( 'Ym', strtotime( '+ '. $count . ' MONTH', $start_date ) ) . '01' ) );
$amount = isset( $sales[$month] ) ? $sales[$month] : 0; $amount = isset( $sales[$month] ) ? $sales[$month] : 0;
echo '<td>' . woocommerce_price( $amount ) . '</td>'; echo '<td>' . woocommerce_price( $amount ) . '</td>';
$monthly_totals[$month] += $amount; $monthly_totals[$month] += $amount;
$chart_data[$coupon_code][] = array( strtotime( date( 'Ymd', strtotime( $month . '01' ) ) ) . '000', $amount ); $chart_data[$coupon_code][] = array( strtotime( date( 'Ymd', strtotime( $month . '01' ) ) ) . '000', $amount );
} }
echo '<td><strong>' . woocommerce_price( array_sum( $sales ) ) . '</strong></td>'; echo '<td><strong>' . woocommerce_price( array_sum( $sales ) ) . '</strong></td>';
// total sales across all months // total sales across all months
$coupon_totals[$coupon_code] = array_sum( $sales ); $coupon_totals[$coupon_code] = array_sum( $sales );
echo '</tr>'; echo '</tr>';
} }
$top_coupon_name = current( array_keys( $coupon_totals, max( $coupon_totals ) ) ); $top_coupon_name = current( array_keys( $coupon_totals, max( $coupon_totals ) ) );
$top_coupon_sales = $coupon_totals[$top_coupon_name]; $top_coupon_sales = $coupon_totals[$top_coupon_name];
$worst_coupon_name = current( array_keys( $coupon_totals, min( $coupon_totals ) ) ); $worst_coupon_name = current( array_keys( $coupon_totals, min( $coupon_totals ) ) );
$worst_coupon_sales = $coupon_totals[$worst_coupon_name]; $worst_coupon_sales = $coupon_totals[$worst_coupon_name];
$median_coupon_sales = array_values( $coupon_totals ); $median_coupon_sales = array_values( $coupon_totals );
sort($median_coupon_sales); sort($median_coupon_sales);
echo '<tr><th><strong>' . __( 'Total', 'woocommerce' ) . '</strong></th>'; echo '<tr><th><strong>' . __( 'Total', 'woocommerce' ) . '</strong></th>';
foreach( $monthly_totals as $month => $totals ) foreach( $monthly_totals as $month => $totals )
echo '<td><strong>' . woocommerce_price( $totals ) . '</strong></td>'; echo '<td><strong>' . woocommerce_price( $totals ) . '</strong></td>';
echo '<td><strong>' . woocommerce_price( array_sum( $monthly_totals ) ) . '</strong></td></tr>'; echo '<td><strong>' . woocommerce_price( array_sum( $monthly_totals ) ) . '</strong></td></tr>';
?></tbody> ?></tbody>
</table> </table>
</div> </div>
<div id="poststuff" class="woocommerce-reports-wrap"> <div id="poststuff" class="woocommerce-reports-wrap">
<div class="woocommerce-reports-sidebar"> <div class="woocommerce-reports-sidebar">
<div class="postbox"> <div class="postbox">
@ -2423,13 +2423,13 @@ function woocommerce_coupon_sales() {
if ( count( $median_coupon_sales ) == 2 ) if ( count( $median_coupon_sales ) == 2 )
echo __( 'N/A', 'woocommerce' ); echo __( 'N/A', 'woocommerce' );
elseif ( count( $median_coupon_sales ) % 2 ) elseif ( count( $median_coupon_sales ) % 2 )
echo woocommerce_price( echo woocommerce_price(
( (
$median_coupon_sales[ floor( count( $median_coupon_sales ) / 2 ) ] + $median_coupon_sales[ ceil( count( $median_coupon_sales ) / 2 ) ] $median_coupon_sales[ floor( count( $median_coupon_sales ) / 2 ) ] + $median_coupon_sales[ ceil( count( $median_coupon_sales ) / 2 ) ]
) / 2 ) / 2
); );
else else
echo woocommerce_price( $median_coupon_sales[ count( $median_coupon_sales ) / 2 ] ); echo woocommerce_price( $median_coupon_sales[ count( $median_coupon_sales ) / 2 ] );
?></p> ?></p>
</div> </div>
@ -2447,7 +2447,7 @@ function woocommerce_coupon_sales() {
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
jQuery(function(){ jQuery(function(){
<?php <?php
// Variables // Variables
foreach ( $chart_data as $name => $data ) { foreach ( $chart_data as $name => $data ) {
@ -2458,14 +2458,14 @@ function woocommerce_coupon_sales() {
var placeholder = jQuery("#placeholder"); var placeholder = jQuery("#placeholder");
var plot = jQuery.plot(placeholder, [ var plot = jQuery.plot(placeholder, [
<?php <?php
$labels = array(); $labels = array();
foreach ( $chart_data as $name => $data ) { foreach ( $chart_data as $name => $data ) {
$labels[] = '{ label: "' . esc_js( $name ) . '", data: ' . 'coupon_' . str_replace( '-', '_', sanitize_title( $name ) ) . '_data }'; $labels[] = '{ label: "' . esc_js( $name ) . '", data: ' . 'coupon_' . str_replace( '-', '_', sanitize_title( $name ) ) . '_data }';
} }
echo implode( ',', $labels ); echo implode( ',', $labels );
?> ?>
], { ], {

View File

@ -31,7 +31,7 @@ if ( ! function_exists( 'woocommerce_settings' ) ) {
*/ */
function woocommerce_settings() { function woocommerce_settings() {
global $woocommerce, $woocommerce_settings; global $woocommerce, $woocommerce_settings;
do_action( 'woocommerce_settings_start' ); do_action( 'woocommerce_settings_start' );
// Get current tab/section // Get current tab/section
@ -96,23 +96,23 @@ if ( ! function_exists( 'woocommerce_settings' ) ) {
// If saving a shipping methods options, load 'er up // If saving a shipping methods options, load 'er up
if ( $current_tab == 'shipping' && class_exists( $current_section ) ) { if ( $current_tab == 'shipping' && class_exists( $current_section ) ) {
$current_section_class = new $current_section(); $current_section_class = new $current_section();
do_action( 'woocommerce_update_options_' . $current_tab . '_' . $current_section_class->id ); do_action( 'woocommerce_update_options_' . $current_tab . '_' . $current_section_class->id );
// If saving an email's options, load theme // If saving an email's options, load theme
} elseif ( $current_tab == 'email' ) { } elseif ( $current_tab == 'email' ) {
// Load mailer // Load mailer
$mailer = $woocommerce->mailer(); $mailer = $woocommerce->mailer();
if ( class_exists( $current_section ) ) { if ( class_exists( $current_section ) ) {
$current_section_class = new $current_section(); $current_section_class = new $current_section();
do_action( 'woocommerce_update_options_' . $current_tab . '_' . $current_section_class->id ); do_action( 'woocommerce_update_options_' . $current_tab . '_' . $current_section_class->id );
} else { } else {
do_action( 'woocommerce_update_options_' . $current_tab . '_' . $current_section ); do_action( 'woocommerce_update_options_' . $current_tab . '_' . $current_section );
} }
} else { } else {
// Save section only // Save section only
@ -247,7 +247,7 @@ if ( ! function_exists( 'woocommerce_settings' ) ) {
woocommerce_admin_fields( $woocommerce_settings[$current_tab] ); woocommerce_admin_fields( $woocommerce_settings[$current_tab] );
break; break;
case "email" : case "email" :
$current = $current_section ? '' : 'class="current"'; $current = $current_section ? '' : 'class="current"';
$links = array( '<a href="' . admin_url( 'admin.php?page=woocommerce_settings&tab=email' ) . '" ' . $current . '>' . __( 'Email Options', 'woocommerce' ) . '</a>' ); $links = array( '<a href="' . admin_url( 'admin.php?page=woocommerce_settings&tab=email' ) . '" ' . $current . '>' . __( 'Email Options', 'woocommerce' ) . '</a>' );
@ -267,7 +267,7 @@ if ( ! function_exists( 'woocommerce_settings' ) ) {
} }
echo '<ul class="subsubsub"><li>' . implode( ' | </li><li>', $links ) . '</li></ul><br class="clear" />'; echo '<ul class="subsubsub"><li>' . implode( ' | </li><li>', $links ) . '</li></ul><br class="clear" />';
// Specific email options // Specific email options
if ( $current_section ) { if ( $current_section ) {
foreach ( $email_templates as $email ) { foreach ( $email_templates as $email ) {
@ -492,7 +492,7 @@ if ( ! function_exists( 'woocommerce_settings' ) ) {
/** /**
* Get a setting from the settings API. * Get a setting from the settings API.
* *
* @access public * @access public
* @param mixed $option * @param mixed $option
* @return void * @return void
@ -500,27 +500,27 @@ if ( ! function_exists( 'woocommerce_settings' ) ) {
function woocommerce_settings_get_option( $option_name, $default = '' ) { function woocommerce_settings_get_option( $option_name, $default = '' ) {
// Array value // Array value
if ( strstr( $option_name, '[' ) ) { if ( strstr( $option_name, '[' ) ) {
parse_str( $option_name, $option_array ); parse_str( $option_name, $option_array );
// Option name is first key // Option name is first key
$option_name = current( array_keys( $option_array ) ); $option_name = current( array_keys( $option_array ) );
// Get value // Get value
$option_values = get_option( $option_name, '' ); $option_values = get_option( $option_name, '' );
$key = key( $option_array[ $option_name ] ); $key = key( $option_array[ $option_name ] );
if ( isset( $option_values[ $key ] ) ) if ( isset( $option_values[ $key ] ) )
$option_value = $option_values[ $key ]; $option_value = $option_values[ $key ];
else else
$option_value = null; $option_value = null;
// Single value // Single value
} else { } else {
$option_value = get_option( $option_name, null ); $option_value = get_option( $option_name, null );
} }
if ( is_array( $option_value ) ) if ( is_array( $option_value ) )
$option_value = array_map( 'stripslashes', $option_value ); $option_value = array_map( 'stripslashes', $option_value );
elseif ( $option_value ) elseif ( $option_value )
@ -550,10 +550,10 @@ function woocommerce_admin_fields( $options ) {
if ( ! isset( $value['default'] ) ) $value['default'] = ''; if ( ! isset( $value['default'] ) ) $value['default'] = '';
if ( ! isset( $value['desc'] ) ) $value['desc'] = ''; if ( ! isset( $value['desc'] ) ) $value['desc'] = '';
if ( ! isset( $value['desc_tip'] ) ) $value['desc_tip'] = false; if ( ! isset( $value['desc_tip'] ) ) $value['desc_tip'] = false;
// Custom attribute handling // Custom attribute handling
$custom_attributes = array(); $custom_attributes = array();
if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) )
foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) foreach ( $value['custom_attributes'] as $attribute => $attribute_value )
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"'; $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
@ -571,13 +571,13 @@ function woocommerce_admin_fields( $options ) {
} else { } else {
$description = $tip = ''; $description = $tip = '';
} }
if ( $description && in_array( $value['type'], array( 'textarea', 'radio' ) ) ) { if ( $description && in_array( $value['type'], array( 'textarea', 'radio' ) ) ) {
$description = '<p style="margin-top:0">' . wp_kses_post( $description ) . '</p>'; $description = '<p style="margin-top:0">' . wp_kses_post( $description ) . '</p>';
} elseif ( $description ) { } elseif ( $description ) {
$description = '<span class="description">' . wp_kses_post( $description ) . '</span>'; $description = '<span class="description">' . wp_kses_post( $description ) . '</span>';
} }
if ( $tip && in_array( $value['type'], array( 'checkbox' ) ) ) { if ( $tip && in_array( $value['type'], array( 'checkbox' ) ) ) {
$tip = '<span class="help_tip" data-tip="' . esc_attr( $tip ) . '">[?]</span>'; $tip = '<span class="help_tip" data-tip="' . esc_attr( $tip ) . '">[?]</span>';
} elseif ( $tip ) { } elseif ( $tip ) {
@ -586,7 +586,7 @@ function woocommerce_admin_fields( $options ) {
// Switch based on type // Switch based on type
switch( $value['type'] ) { switch( $value['type'] ) {
// Section Titles // Section Titles
case 'title': case 'title':
if ( ! empty( $value['title'] ) ) echo '<h3>' . esc_html( $value['title'] ) . '</h3>'; if ( ! empty( $value['title'] ) ) echo '<h3>' . esc_html( $value['title'] ) . '</h3>';
@ -594,54 +594,54 @@ function woocommerce_admin_fields( $options ) {
echo '<table class="form-table">'. "\n\n"; echo '<table class="form-table">'. "\n\n";
if ( ! empty( $value['id'] ) ) do_action( 'woocommerce_settings_' . sanitize_title( $value['id'] ) ); if ( ! empty( $value['id'] ) ) do_action( 'woocommerce_settings_' . sanitize_title( $value['id'] ) );
break; break;
// Section Ends // Section Ends
case 'sectionend': case 'sectionend':
if ( ! empty( $value['id'] ) ) do_action( 'woocommerce_settings_' . sanitize_title( $value['id'] ) . '_end' ); if ( ! empty( $value['id'] ) ) do_action( 'woocommerce_settings_' . sanitize_title( $value['id'] ) . '_end' );
echo '</table>'; echo '</table>';
if ( ! empty( $value['id'] ) ) do_action( 'woocommerce_settings_' . sanitize_title( $value['id'] ) . '_after' ); if ( ! empty( $value['id'] ) ) do_action( 'woocommerce_settings_' . sanitize_title( $value['id'] ) . '_after' );
break; break;
// Standard text inputs and subtypes like 'number' // Standard text inputs and subtypes like 'number'
case 'text': case 'text':
case 'email': case 'email':
case 'number': case 'number':
case 'color' : case 'color' :
$type = $value['type']; $type = $value['type'];
$class = ''; $class = '';
$option_value = woocommerce_settings_get_option( $value['id'], $value['default'] ); $option_value = woocommerce_settings_get_option( $value['id'], $value['default'] );
if ( $value['type'] == 'color' ) { if ( $value['type'] == 'color' ) {
$type = 'text'; $type = 'text';
$value['class'] .= 'colorpick'; $value['class'] .= 'colorpick';
$description .= '<div id="colorPickerDiv_' . esc_attr( $value['id'] ) . '" class="colorpickdiv" style="z-index: 100;background:#eee;border:1px solid #ccc;position:absolute;display:none;"></div>'; $description .= '<div id="colorPickerDiv_' . esc_attr( $value['id'] ) . '" class="colorpickdiv" style="z-index: 100;background:#eee;border:1px solid #ccc;position:absolute;display:none;"></div>';
} }
?><tr valign="top"> ?><tr valign="top">
<th scope="row" class="titledesc"> <th scope="row" class="titledesc">
<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label> <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
<?php echo $tip; ?> <?php echo $tip; ?>
</th> </th>
<td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>"> <td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>">
<input <input
name="<?php echo esc_attr( $value['id'] ); ?>" name="<?php echo esc_attr( $value['id'] ); ?>"
id="<?php echo esc_attr( $value['id'] ); ?>" id="<?php echo esc_attr( $value['id'] ); ?>"
type="<?php echo esc_attr( $type ); ?>" type="<?php echo esc_attr( $type ); ?>"
style="<?php echo esc_attr( $value['css'] ); ?>" style="<?php echo esc_attr( $value['css'] ); ?>"
value="<?php echo esc_attr( $option_value ); ?>" value="<?php echo esc_attr( $option_value ); ?>"
class="<?php echo esc_attr( $value['class'] ); ?>" class="<?php echo esc_attr( $value['class'] ); ?>"
<?php echo implode( ' ', $custom_attributes ); ?> <?php echo implode( ' ', $custom_attributes ); ?>
/> <?php echo $description; ?> /> <?php echo $description; ?>
</td> </td>
</tr><?php </tr><?php
break; break;
// Textarea // Textarea
case 'textarea': case 'textarea':
$option_value = woocommerce_settings_get_option( $value['id'], $value['default'] ); $option_value = woocommerce_settings_get_option( $value['id'], $value['default'] );
?><tr valign="top"> ?><tr valign="top">
<th scope="row" class="titledesc"> <th scope="row" class="titledesc">
<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label> <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
@ -649,34 +649,34 @@ function woocommerce_admin_fields( $options ) {
</th> </th>
<td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>"> <td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>">
<?php echo $description; ?> <?php echo $description; ?>
<textarea <textarea
name="<?php echo esc_attr( $value['id'] ); ?>" name="<?php echo esc_attr( $value['id'] ); ?>"
id="<?php echo esc_attr( $value['id'] ); ?>" id="<?php echo esc_attr( $value['id'] ); ?>"
style="<?php echo esc_attr( $value['css'] ); ?>" style="<?php echo esc_attr( $value['css'] ); ?>"
class="<?php echo esc_attr( $value['class'] ); ?>" class="<?php echo esc_attr( $value['class'] ); ?>"
<?php echo implode( ' ', $custom_attributes ); ?> <?php echo implode( ' ', $custom_attributes ); ?>
><?php echo esc_textarea( $option_value ); ?></textarea> ><?php echo esc_textarea( $option_value ); ?></textarea>
</td> </td>
</tr><?php </tr><?php
break; break;
// Select boxes // Select boxes
case 'select' : case 'select' :
case 'multiselect' : case 'multiselect' :
$option_value = woocommerce_settings_get_option( $value['id'], $value['default'] ); $option_value = woocommerce_settings_get_option( $value['id'], $value['default'] );
?><tr valign="top"> ?><tr valign="top">
<th scope="row" class="titledesc"> <th scope="row" class="titledesc">
<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label> <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
<?php echo $tip; ?> <?php echo $tip; ?>
</th> </th>
<td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>"> <td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>">
<select <select
name="<?php echo esc_attr( $value['id'] ); ?>" name="<?php echo esc_attr( $value['id'] ); ?>"
id="<?php echo esc_attr( $value['id'] ); ?>" id="<?php echo esc_attr( $value['id'] ); ?>"
style="<?php echo esc_attr( $value['css'] ); ?>" style="<?php echo esc_attr( $value['css'] ); ?>"
class="<?php echo esc_attr( $value['class'] ); ?>" class="<?php echo esc_attr( $value['class'] ); ?>"
<?php echo implode( ' ', $custom_attributes ); ?> <?php echo implode( ' ', $custom_attributes ); ?>
<?php if ( $value['type'] == 'multiselect' ) echo 'multiple="multiple"'; ?> <?php if ( $value['type'] == 'multiselect' ) echo 'multiple="multiple"'; ?>
@ -684,13 +684,13 @@ function woocommerce_admin_fields( $options ) {
<?php <?php
foreach ( $value['options'] as $key => $val ) { foreach ( $value['options'] as $key => $val ) {
?> ?>
<option value="<?php echo esc_attr( $key ); ?>" <?php <option value="<?php echo esc_attr( $key ); ?>" <?php
if ( is_array( $option_value ) ) if ( is_array( $option_value ) )
selected( in_array( $key, $option_value ), true ); selected( in_array( $key, $option_value ), true );
else else
selected( $option_value, $key ); selected( $option_value, $key );
?>><?php echo $val ?></option> ?>><?php echo $val ?></option>
<?php <?php
} }
@ -699,12 +699,12 @@ function woocommerce_admin_fields( $options ) {
</td> </td>
</tr><?php </tr><?php
break; break;
// Radio inputs // Radio inputs
case 'radio' : case 'radio' :
$option_value = woocommerce_settings_get_option( $value['id'], $value['default'] ); $option_value = woocommerce_settings_get_option( $value['id'], $value['default'] );
?><tr valign="top"> ?><tr valign="top">
<th scope="row" class="titledesc"> <th scope="row" class="titledesc">
<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label> <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
@ -718,11 +718,11 @@ function woocommerce_admin_fields( $options ) {
foreach ( $value['options'] as $key => $val ) { foreach ( $value['options'] as $key => $val ) {
?> ?>
<li> <li>
<label><input <label><input
name="<?php echo esc_attr( $value['id'] ); ?>" name="<?php echo esc_attr( $value['id'] ); ?>"
value="<?php echo $key; ?>" value="<?php echo $key; ?>"
type="radio" type="radio"
style="<?php echo esc_attr( $value['css'] ); ?>" style="<?php echo esc_attr( $value['css'] ); ?>"
class="<?php echo esc_attr( $value['class'] ); ?>" class="<?php echo esc_attr( $value['class'] ); ?>"
<?php echo implode( ' ', $custom_attributes ); ?> <?php echo implode( ' ', $custom_attributes ); ?>
<?php checked( $key, $option_value ); ?> <?php checked( $key, $option_value ); ?>
@ -736,10 +736,10 @@ function woocommerce_admin_fields( $options ) {
</td> </td>
</tr><?php </tr><?php
break; break;
// Checkbox input // Checkbox input
case 'checkbox' : case 'checkbox' :
$option_value = woocommerce_settings_get_option( $value['id'], $value['default'] ); $option_value = woocommerce_settings_get_option( $value['id'], $value['default'] );
if ( ! isset( $value['hide_if_checked'] ) ) $value['hide_if_checked'] = false; if ( ! isset( $value['hide_if_checked'] ) ) $value['hide_if_checked'] = false;
@ -768,15 +768,15 @@ function woocommerce_admin_fields( $options ) {
?> ?>
<legend class="screen-reader-text"><span><?php echo esc_html( $value['title'] ) ?></span></legend> <legend class="screen-reader-text"><span><?php echo esc_html( $value['title'] ) ?></span></legend>
<label for="<?php echo $value['id'] ?>"> <label for="<?php echo $value['id'] ?>">
<input <input
name="<?php echo esc_attr( $value['id'] ); ?>" name="<?php echo esc_attr( $value['id'] ); ?>"
id="<?php echo esc_attr( $value['id'] ); ?>" id="<?php echo esc_attr( $value['id'] ); ?>"
type="checkbox" type="checkbox"
value="1" value="1"
<?php checked( $option_value, 'yes'); ?> <?php checked( $option_value, 'yes'); ?>
<?php echo implode( ' ', $custom_attributes ); ?> <?php echo implode( ' ', $custom_attributes ); ?>
/> <?php echo wp_kses_post( $value['desc'] ) ?></label> <?php echo $tip; ?><br /> /> <?php echo wp_kses_post( $value['desc'] ) ?></label> <?php echo $tip; ?><br />
<?php <?php
@ -793,14 +793,14 @@ function woocommerce_admin_fields( $options ) {
} }
break; break;
// Image width settings // Image width settings
case 'image_width' : case 'image_width' :
$width = woocommerce_settings_get_option( $value['id'] . '[width]', $value['default']['width'] ); $width = woocommerce_settings_get_option( $value['id'] . '[width]', $value['default']['width'] );
$height = woocommerce_settings_get_option( $value['id'] . '[height]', $value['default']['height'] ); $height = woocommerce_settings_get_option( $value['id'] . '[height]', $value['default']['height'] );
$crop = checked( 1, woocommerce_settings_get_option( $value['id'] . '[crop]', $value['default']['crop'] ), false ); $crop = checked( 1, woocommerce_settings_get_option( $value['id'] . '[crop]', $value['default']['crop'] ), false );
?><tr valign="top"> ?><tr valign="top">
<th scope="row" class="titledesc"><?php echo esc_html( $value['title'] ) ?></th> <th scope="row" class="titledesc"><?php echo esc_html( $value['title'] ) ?></th>
<td class="forminp"> <td class="forminp">
@ -814,10 +814,10 @@ function woocommerce_admin_fields( $options ) {
<?php echo $description; ?></td> <?php echo $description; ?></td>
</tr><?php </tr><?php
break; break;
// Single page selects // Single page selects
case 'single_select_page' : case 'single_select_page' :
$args = array( 'title' => $value['id'], $args = array( 'title' => $value['id'],
'id' => $value['id'], 'id' => $value['id'],
'sort_column' => 'menu_order', 'sort_column' => 'menu_order',
@ -828,7 +828,7 @@ function woocommerce_admin_fields( $options ) {
'selected' => absint( woocommerce_settings_get_option( $value['id'] ) ) 'selected' => absint( woocommerce_settings_get_option( $value['id'] ) )
); );
if( isset( $value['args'] ) ) if( isset( $value['args'] ) )
$args = wp_parse_args( $value['args'], $args ); $args = wp_parse_args( $value['args'], $args );
?><tr valign="top" class="single_select_page"> ?><tr valign="top" class="single_select_page">
@ -838,12 +838,12 @@ function woocommerce_admin_fields( $options ) {
</td> </td>
</tr><?php </tr><?php
break; break;
// Single country selects // Single country selects
case 'single_select_country' : case 'single_select_country' :
$country_setting = (string) woocommerce_settings_get_option( $value['id'] ); $country_setting = (string) woocommerce_settings_get_option( $value['id'] );
$countries = $woocommerce->countries->countries; $countries = $woocommerce->countries->countries;
if (strstr($country_setting, ':')) : if (strstr($country_setting, ':')) :
$country = current(explode(':', $country_setting)); $country = current(explode(':', $country_setting));
@ -863,12 +863,12 @@ function woocommerce_admin_fields( $options ) {
</td> </td>
</tr><?php </tr><?php
break; break;
// Country multiselects // Country multiselects
case 'multi_select_countries' : case 'multi_select_countries' :
$selections = (array) woocommerce_settings_get_option( $value['id'] ); $selections = (array) woocommerce_settings_get_option( $value['id'] );
$countries = $woocommerce->countries->countries; $countries = $woocommerce->countries->countries;
asort( $countries ); asort( $countries );
?><tr valign="top"> ?><tr valign="top">
@ -879,7 +879,7 @@ function woocommerce_admin_fields( $options ) {
<td class="forminp"> <td class="forminp">
<select multiple="multiple" name="<?php echo esc_attr( $value['id'] ); ?>[]" style="width:450px;" data-placeholder="<?php _e( 'Choose countries&hellip;', 'woocommerce' ); ?>" title="Country" class="chosen_select"> <select multiple="multiple" name="<?php echo esc_attr( $value['id'] ); ?>[]" style="width:450px;" data-placeholder="<?php _e( 'Choose countries&hellip;', 'woocommerce' ); ?>" title="Country" class="chosen_select">
<?php <?php
if ( $countries ) if ( $countries )
foreach ( $countries as $key => $val ) foreach ( $countries as $key => $val )
echo '<option value="'.$key.'" ' . selected( in_array( $key, $selections ), true, false ).'>' . $val . '</option>'; echo '<option value="'.$key.'" ' . selected( in_array( $key, $selections ), true, false ).'>' . $val . '</option>';
?> ?>
@ -887,7 +887,7 @@ function woocommerce_admin_fields( $options ) {
</td> </td>
</tr><?php </tr><?php
break; break;
// Default: run an action // Default: run an action
default: default:
do_action( 'woocommerce_admin_field_' . $value['type'], $value ); do_action( 'woocommerce_admin_field_' . $value['type'], $value );

View File

@ -46,7 +46,7 @@ function woocommerce_status() {
break; break;
case "reset_roles" : case "reset_roles" :
// Remove then re-add caps and roles // Remove then re-add caps and roles
woocommerce_remove_roles(); woocommerce_remove_roles();
woocommerce_init_roles(); woocommerce_init_roles();
echo '<div class="updated"><p>' . __( 'Roles successfully reset', 'woocommerce' ) . '</p></div>'; echo '<div class="updated"><p>' . __( 'Roles successfully reset', 'woocommerce' ) . '</p></div>';
@ -253,7 +253,7 @@ function woocommerce_status() {
<tr> <tr>
<td><?php _e('PHP Version','woocommerce')?></td> <td><?php _e('PHP Version','woocommerce')?></td>
<td><?php <td><?php
if ( function_exists( 'phpversion' ) ) if ( function_exists( 'phpversion' ) )
echo esc_html( phpversion() ); echo esc_html( phpversion() );
?></td> ?></td>
</tr> </tr>
@ -334,7 +334,7 @@ function woocommerce_status() {
$posting['fsockopen_curl']['note'] = __( 'Your server does not have fsockopen or cURL enabled - PayPal IPN and other scripts which communicate with other servers will not work. Contact your hosting provider.', 'woocommerce' ). '</mark>'; $posting['fsockopen_curl']['note'] = __( 'Your server does not have fsockopen or cURL enabled - PayPal IPN and other scripts which communicate with other servers will not work. Contact your hosting provider.', 'woocommerce' ). '</mark>';
$posting['fsockopen_curl']['success'] = false; $posting['fsockopen_curl']['success'] = false;
} }
// SOAP // SOAP
$posting['soap_client']['name'] = __( 'SOAP Client','woocommerce' ); $posting['soap_client']['name'] = __( 'SOAP Client','woocommerce' );
if ( class_exists( 'SoapClient' ) ) { if ( class_exists( 'SoapClient' ) ) {

View File

@ -39,7 +39,7 @@ function woocommerce_add_category_fields() {
<button type="submit" class="remove_image_button button"><?php _e( 'Remove image', 'woocommerce' ); ?></button> <button type="submit" class="remove_image_button button"><?php _e( 'Remove image', 'woocommerce' ); ?></button>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
// Only show the "remove image" button when needed // Only show the "remove image" button when needed
if ( ! jQuery('#product_cat_thumbnail_id').val() ) if ( ! jQuery('#product_cat_thumbnail_id').val() )
jQuery('.remove_image_button').hide(); jQuery('.remove_image_button').hide();
@ -100,7 +100,7 @@ add_action( 'product_cat_add_form_fields', 'woocommerce_add_category_fields' );
*/ */
function woocommerce_edit_category_fields( $term, $taxonomy ) { function woocommerce_edit_category_fields( $term, $taxonomy ) {
global $woocommerce; global $woocommerce;
$display_type = get_woocommerce_term_meta( $term->term_id, 'display_type', true ); $display_type = get_woocommerce_term_meta( $term->term_id, 'display_type', true );
$image = ''; $image = '';
$thumbnail_id = absint( get_woocommerce_term_meta( $term->term_id, 'thumbnail_id', true ) ); $thumbnail_id = absint( get_woocommerce_term_meta( $term->term_id, 'thumbnail_id', true ) );
@ -186,7 +186,7 @@ add_action( 'product_cat_edit_form_fields', 'woocommerce_edit_category_fields',
function woocommerce_category_fields_save( $term_id, $tt_id, $taxonomy ) { function woocommerce_category_fields_save( $term_id, $tt_id, $taxonomy ) {
if ( isset( $_POST['display_type'] ) ) if ( isset( $_POST['display_type'] ) )
update_woocommerce_term_meta( $term_id, 'display_type', esc_attr( $_POST['display_type'] ) ); update_woocommerce_term_meta( $term_id, 'display_type', esc_attr( $_POST['display_type'] ) );
if ( isset( $_POST['product_cat_thumbnail_id'] ) ) if ( isset( $_POST['product_cat_thumbnail_id'] ) )
update_woocommerce_term_meta( $term_id, 'thumbnail_id', absint( $_POST['product_cat_thumbnail_id'] ) ); update_woocommerce_term_meta( $term_id, 'thumbnail_id', absint( $_POST['product_cat_thumbnail_id'] ) );
} }

View File

@ -20,24 +20,24 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
*/ */
function do_update_woocommerce() { function do_update_woocommerce() {
global $woocommerce; global $woocommerce;
// Do updates // Do updates
$current_db_version = get_option( 'woocommerce_db_version' ); $current_db_version = get_option( 'woocommerce_db_version' );
if ( version_compare( $current_db_version, '1.4', '<' ) ) { if ( version_compare( $current_db_version, '1.4', '<' ) ) {
include( 'includes/updates/woocommerce-update-1.4.php' ); include( 'includes/updates/woocommerce-update-1.4.php' );
update_option( 'woocommerce_db_version', '1.4' ); update_option( 'woocommerce_db_version', '1.4' );
} }
if ( version_compare( $current_db_version, '1.5', '<' ) ) { if ( version_compare( $current_db_version, '1.5', '<' ) ) {
include( 'includes/updates/woocommerce-update-1.5.php' ); include( 'includes/updates/woocommerce-update-1.5.php' );
update_option( 'woocommerce_db_version', '1.5' ); update_option( 'woocommerce_db_version', '1.5' );
} }
if ( version_compare( $current_db_version, '1.7', '<' ) ) { if ( version_compare( $current_db_version, '1.7', '<' ) ) {
include( 'includes/updates/woocommerce-update-1.7.php' ); include( 'includes/updates/woocommerce-update-1.7.php' );
update_option( 'woocommerce_db_version', '1.7' ); update_option( 'woocommerce_db_version', '1.7' );
} }
update_option( 'woocommerce_db_version', $woocommerce->version ); update_option( 'woocommerce_db_version', $woocommerce->version );
} }

View File

@ -73,9 +73,9 @@ function woocommerce_user_column_values( $value, $column_name, $user_id ) {
$formatted_address = $woocommerce->countries->get_formatted_address( $address ); $formatted_address = $woocommerce->countries->get_formatted_address( $address );
if ( ! $formatted_address ) if ( ! $formatted_address )
$value = __( 'N/A', 'woocommerce' ); $value = __( 'N/A', 'woocommerce' );
else else
$value = $formatted_address; $value = $formatted_address;
$value = wpautop( $value ); $value = wpautop( $value );
@ -95,9 +95,9 @@ function woocommerce_user_column_values( $value, $column_name, $user_id ) {
$formatted_address = $woocommerce->countries->get_formatted_address( $address ); $formatted_address = $woocommerce->countries->get_formatted_address( $address );
if ( ! $formatted_address ) if ( ! $formatted_address )
$value = __( 'N/A', 'woocommerce' ); $value = __( 'N/A', 'woocommerce' );
else else
$value = $formatted_address; $value = $formatted_address;
$value = wpautop( $value ); $value = wpautop( $value );
@ -106,9 +106,9 @@ function woocommerce_user_column_values( $value, $column_name, $user_id ) {
$paying_customer = get_user_meta( $user_id, 'paying_customer', true ); $paying_customer = get_user_meta( $user_id, 'paying_customer', true );
if ( $paying_customer ) if ( $paying_customer )
$value = '<img src="' . $woocommerce->plugin_url() . '/assets/images/success.png" alt="yes" />'; $value = '<img src="' . $woocommerce->plugin_url() . '/assets/images/success.png" alt="yes" />';
else else
$value = '<img src="' . $woocommerce->plugin_url() . '/assets/images/success-off.png" alt="no" />'; $value = '<img src="' . $woocommerce->plugin_url() . '/assets/images/success-off.png" alt="no" />';
break; break;

View File

@ -3,10 +3,10 @@
* Simple and fancy lightbox alternative * Simple and fancy lightbox alternative
* *
* Examples and documentation at: http://fancybox.net * Examples and documentation at: http://fancybox.net
* *
* Copyright (c) 2008 - 2010 Janis Skarnelis * Copyright (c) 2008 - 2010 Janis Skarnelis
* That said, it is hardly a one-person project. Many people have submitted bugs, code, and offered their advice freely. Their support is greatly appreciated. * That said, it is hardly a one-person project. Many people have submitted bugs, code, and offered their advice freely. Their support is greatly appreciated.
* *
* Version: 1.3.4 (11/11/2010) * Version: 1.3.4 (11/11/2010)
* Requires: jQuery v1.3+ * Requires: jQuery v1.3+
* *

View File

@ -1,5 +1,5 @@
<?php <?php
$strings = 'tinyMCE.addI18n({' . _WP_Editors::$mce_locale . ':{ $strings = 'tinyMCE.addI18n({' . _WP_Editors::$mce_locale . ':{
woocommerce:{ woocommerce:{
insert: "' . esc_js( __( 'Insert Shortcode', 'woocommerce' ) ) . '", insert: "' . esc_js( __( 'Insert Shortcode', 'woocommerce' ) ) . '",

View File

@ -1,5 +1,5 @@
jQuery( function($){ jQuery( function($){
// Scroll to first checked category - https://github.com/scribu/wp-category-checklist-tree/blob/d1c3c1f449e1144542efa17dde84a9f52ade1739/category-checklist-tree.php // Scroll to first checked category - https://github.com/scribu/wp-category-checklist-tree/blob/d1c3c1f449e1144542efa17dde84a9f52ade1739/category-checklist-tree.php
$(function(){ $(function(){
$('[id$="-all"] > ul.categorychecklist').each(function() { $('[id$="-all"] > ul.categorychecklist').each(function() {
@ -15,7 +15,7 @@ jQuery( function($){
$list.closest('.tabs-panel').scrollTop(pos_checked - pos_first + 5); $list.closest('.tabs-panel').scrollTop(pos_checked - pos_first + 5);
}); });
}); });
// Prevent enter submitting post form // Prevent enter submitting post form
$("#upsell_product_data").bind("keypress", function(e) { $("#upsell_product_data").bind("keypress", function(e) {
if (e.keyCode == 13) return false; if (e.keyCode == 13) return false;
@ -177,17 +177,17 @@ jQuery( function($){
$(this).closest('.order_data').find('div.edit_address').show(); $(this).closest('.order_data').find('div.edit_address').show();
event.preventDefault(); event.preventDefault();
}); });
$('#order_items_list').on( 'init_row', 'tr.item', function() { $('#order_items_list').on( 'init_row', 'tr.item', function() {
var $row = $(this); var $row = $(this);
var $qty = $row.find('input.quantity'); var $qty = $row.find('input.quantity');
var qty = $qty.val(); var qty = $qty.val();
var line_subtotal = $row.find('input.line_subtotal').val(); var line_subtotal = $row.find('input.line_subtotal').val();
var line_total = $row.find('input.line_total').val(); var line_total = $row.find('input.line_total').val();
var line_tax = $row.find('input.line_tax').val(); var line_tax = $row.find('input.line_tax').val();
var line_subtotal_tax = $row.find('input.line_subtotal_tax').val(); var line_subtotal_tax = $row.find('input.line_subtotal_tax').val();
if ( qty ) { if ( qty ) {
unit_subtotal = accounting.toFixed( ( line_subtotal / qty ), 2 ); unit_subtotal = accounting.toFixed( ( line_subtotal / qty ), 2 );
unit_subtotal_tax = accounting.toFixed( ( line_subtotal_tax / qty ), 2 ); unit_subtotal_tax = accounting.toFixed( ( line_subtotal_tax / qty ), 2 );
@ -196,58 +196,58 @@ jQuery( function($){
} else { } else {
unit_subtotal = unit_subtotal_tax = unit_total = unit_total_tax = 0; unit_subtotal = unit_subtotal_tax = unit_total = unit_total_tax = 0;
} }
$qty.attr( 'data-o_qty', qty ); $qty.attr( 'data-o_qty', qty );
$row.attr( 'data-unit_subtotal', unit_subtotal ); $row.attr( 'data-unit_subtotal', unit_subtotal );
$row.attr( 'data-unit_subtotal_tax', unit_subtotal_tax ); $row.attr( 'data-unit_subtotal_tax', unit_subtotal_tax );
$row.attr( 'data-unit_total', unit_total ); $row.attr( 'data-unit_total', unit_total );
$row.attr( 'data-unit_total_tax', unit_total_tax ); $row.attr( 'data-unit_total_tax', unit_total_tax );
}); });
// When the page is loaded, store the unit costs // When the page is loaded, store the unit costs
$('#order_items_list tr.item').each( function() { $('#order_items_list tr.item').each( function() {
$(this).trigger('init_row'); $(this).trigger('init_row');
} ); } );
// When the qty is changed, increase or decrease costs // When the qty is changed, increase or decrease costs
$('#order_items_list').on( 'change', 'input.quantity', function() { $('#order_items_list').on( 'change', 'input.quantity', function() {
var $row = $(this).closest('tr.item'); var $row = $(this).closest('tr.item');
var qty = $(this).val(); var qty = $(this).val();
var unit_subtotal = $row.attr('data-unit_subtotal'); var unit_subtotal = $row.attr('data-unit_subtotal');
var unit_subtotal_tax = $row.attr('data-unit_subtotal_tax'); var unit_subtotal_tax = $row.attr('data-unit_subtotal_tax');
var unit_total = $row.attr('data-unit_total'); var unit_total = $row.attr('data-unit_total');
var unit_total_tax = $row.attr('data-unit_total_tax'); var unit_total_tax = $row.attr('data-unit_total_tax');
var o_qty = $(this).attr('data-o_qty'); var o_qty = $(this).attr('data-o_qty');
var subtotal = accounting.formatNumber( unit_subtotal * qty, 2, '' ); var subtotal = accounting.formatNumber( unit_subtotal * qty, 2, '' );
var tax = accounting.formatNumber( unit_subtotal_tax * qty, 2, '' ); var tax = accounting.formatNumber( unit_subtotal_tax * qty, 2, '' );
var total = accounting.formatNumber( unit_total * qty, 2, '' ); var total = accounting.formatNumber( unit_total * qty, 2, '' );
var total_tax = accounting.formatNumber( unit_total_tax * qty, 2, '' ); var total_tax = accounting.formatNumber( unit_total_tax * qty, 2, '' );
$row.find('input.line_subtotal').val( subtotal ); $row.find('input.line_subtotal').val( subtotal );
$row.find('input.line_total').val( total ); $row.find('input.line_total').val( total );
$row.find('input.line_subtotal_tax').val( tax ); $row.find('input.line_subtotal_tax').val( tax );
$row.find('input.line_tax').val( total_tax ); $row.find('input.line_tax').val( total_tax );
}); });
// When subtotal is changed, update the unit costs // When subtotal is changed, update the unit costs
$('#order_items_list').on( 'change', 'input.line_subtotal', function() { $('#order_items_list').on( 'change', 'input.line_subtotal', function() {
var $row = $(this).closest('tr.item'); var $row = $(this).closest('tr.item');
var $qty = $row.find('input.quantity'); var $qty = $row.find('input.quantity');
var qty = $qty.val(); var qty = $qty.val();
var value = ( qty ) ? accounting.toFixed( ( $(this).val() / qty ), 2 ) : 0; var value = ( qty ) ? accounting.toFixed( ( $(this).val() / qty ), 2 ) : 0;
$row.attr( 'data-unit_subtotal', value ); $row.attr( 'data-unit_subtotal', value );
}); });
// When total is changed, update the unit costs + discount amount // When total is changed, update the unit costs + discount amount
$('#order_items_list').on( 'change', 'input.line_total', function() { $('#order_items_list').on( 'change', 'input.line_total', function() {
var $row = $(this).closest('tr.item'); var $row = $(this).closest('tr.item');
var $qty = $row.find('input.quantity'); var $qty = $row.find('input.quantity');
var qty = $qty.val(); var qty = $qty.val();
var value = ( qty ) ? accounting.toFixed( ( $(this).val() / qty ), 2 ) : 0; var value = ( qty ) ? accounting.toFixed( ( $(this).val() / qty ), 2 ) : 0;
$row.attr( 'data-unit_total', value ); $row.attr( 'data-unit_total', value );
}); });
@ -257,27 +257,27 @@ jQuery( function($){
var $qty = $row.find('input.quantity'); var $qty = $row.find('input.quantity');
var qty = $qty.val(); var qty = $qty.val();
var value = ( qty ) ? accounting.toFixed( ( $(this).val() / qty ), 2 ) : 0; var value = ( qty ) ? accounting.toFixed( ( $(this).val() / qty ), 2 ) : 0;
$row.attr( 'data-unit_subtotal_tax', value ); $row.attr( 'data-unit_subtotal_tax', value );
}); });
// When total is changed, update the unit costs + discount amount // When total is changed, update the unit costs + discount amount
$('#order_items_list').on( 'change', 'input.line_tax', function() { $('#order_items_list').on( 'change', 'input.line_tax', function() {
var $row = $(this).closest('tr.item'); var $row = $(this).closest('tr.item');
var $qty = $row.find('input.quantity'); var $qty = $row.find('input.quantity');
var qty = $qty.val(); var qty = $qty.val();
var value = ( qty ) ? accounting.toFixed( ( $(this).val() / qty ), 2 ) : 0; var value = ( qty ) ? accounting.toFixed( ( $(this).val() / qty ), 2 ) : 0;
$row.attr( 'data-unit_total_tax', value ); $row.attr( 'data-unit_total_tax', value );
}); });
// Display a total for taxes // Display a total for taxes
$('#woocommerce-order-totals').on( 'change', '#_order_tax, #_order_shipping_tax, #_cart_discount, #_order_discount', function() { $('#woocommerce-order-totals').on( 'change', '#_order_tax, #_order_shipping_tax, #_cart_discount, #_order_discount', function() {
var $this = $(this); var $this = $(this);
var fields = $this.closest('.totals').find('input'); var fields = $this.closest('.totals').find('input');
var total = 0; var total = 0;
fields.each(function(){ fields.each(function(){
if ( $(this).val() ) if ( $(this).val() )
total = total + parseFloat( $(this).val() ); total = total + parseFloat( $(this).val() );
@ -290,12 +290,12 @@ jQuery( function($){
precision : woocommerce_writepanel_params.currency_format_num_decimals, precision : woocommerce_writepanel_params.currency_format_num_decimals,
format : woocommerce_writepanel_params.currency_format format : woocommerce_writepanel_params.currency_format
} ); } );
$this.closest('.totals_group').find('span.inline_total').text( formatted_total ); $this.closest('.totals_group').find('span.inline_total').text( formatted_total );
} ); } );
$('span.inline_total').closest('.totals_group').find('input').change(); $('span.inline_total').closest('.totals_group').find('input').change();
// Calculate totals // Calculate totals
$('button.calc_line_taxes').live('click', function(){ $('button.calc_line_taxes').live('click', function(){
// Block write panel // Block write panel
@ -318,25 +318,25 @@ jQuery( function($){
var postcode = $('#_billing_postcode').val(); var postcode = $('#_billing_postcode').val();
var city = $('#_billing_city').val(); var city = $('#_billing_city').val();
} }
// Get items and values // Get items and values
var calculate_items = {}; var calculate_items = {};
$items.each( function() { $items.each( function() {
var $row = $(this); var $row = $(this);
var item_id = $row.find('input.order_item_id').val(); var item_id = $row.find('input.order_item_id').val();
var line_subtotal = $row.find('input.line_subtotal').val(); var line_subtotal = $row.find('input.line_subtotal').val();
var line_total = $row.find('input.line_total').val(); var line_total = $row.find('input.line_total').val();
var tax_class = $row.find('select.tax_class').val(); var tax_class = $row.find('select.tax_class').val();
calculate_items[ item_id ] = {}; calculate_items[ item_id ] = {};
calculate_items[ item_id ].line_subtotal = line_subtotal; calculate_items[ item_id ].line_subtotal = line_subtotal;
calculate_items[ item_id ].line_total = line_total; calculate_items[ item_id ].line_total = line_total;
calculate_items[ item_id ].tax_class = tax_class; calculate_items[ item_id ].tax_class = tax_class;
} ); } );
var data = { var data = {
action: 'woocommerce_calc_line_taxes', action: 'woocommerce_calc_line_taxes',
order_id: woocommerce_writepanel_params.post_id, order_id: woocommerce_writepanel_params.post_id,
@ -350,21 +350,21 @@ jQuery( function($){
}; };
$.post( woocommerce_writepanel_params.ajax_url, data, function( response ) { $.post( woocommerce_writepanel_params.ajax_url, data, function( response ) {
result = jQuery.parseJSON( response ); result = jQuery.parseJSON( response );
$items.each( function() { $items.each( function() {
var $row = $(this); var $row = $(this);
var item_id = $row.find('input.order_item_id').val(); var item_id = $row.find('input.order_item_id').val();
$row.find('input.line_tax').val( result['item_taxes'][ item_id ]['line_tax'] ).change(); $row.find('input.line_tax').val( result['item_taxes'][ item_id ]['line_tax'] ).change();
$row.find('input.line_subtotal_tax').val( result['item_taxes'][ item_id ]['line_subtotal_tax'] ).change(); $row.find('input.line_subtotal_tax').val( result['item_taxes'][ item_id ]['line_subtotal_tax'] ).change();
$('#tax_rows').empty().append( result['tax_row_html'] ); $('#tax_rows').empty().append( result['tax_row_html'] );
} ); } );
$('#_order_tax').val( result['item_tax'] ).change(); $('#_order_tax').val( result['item_tax'] ).change();
$('#_order_shipping_tax').val( result['shipping_tax'] ).change(); $('#_order_shipping_tax').val( result['shipping_tax'] ).change();
$('.woocommerce_order_items_wrapper').unblock(); $('.woocommerce_order_items_wrapper').unblock();
}); });
@ -423,7 +423,7 @@ jQuery( function($){
cart_tax = cart_tax + parseFloat( line_tax ); cart_tax = cart_tax + parseFloat( line_tax );
}); });
// Tax // Tax
if (woocommerce_writepanel_params.round_at_subtotal=='yes') { if (woocommerce_writepanel_params.round_at_subtotal=='yes') {
cart_tax = accounting.toFixed( cart_tax, 2 ); cart_tax = accounting.toFixed( cart_tax, 2 );
@ -433,7 +433,7 @@ jQuery( function($){
var cart_discount = ( line_subtotals + line_subtotal_taxes ) - ( line_totals + cart_tax ); var cart_discount = ( line_subtotals + line_subtotal_taxes ) - ( line_totals + cart_tax );
if ( cart_discount < 0 ) cart_discount = 0; if ( cart_discount < 0 ) cart_discount = 0;
cart_discount = accounting.toFixed( cart_discount, 2 ); cart_discount = accounting.toFixed( cart_discount, 2 );
$('#order_items_list tr.fee').each(function(){ $('#order_items_list tr.fee').each(function(){
var line_total = accounting.unformat( $(this).find('input.line_total').val() ); var line_total = accounting.unformat( $(this).find('input.line_total').val() );
var line_tax = accounting.unformat( $(this).find('input.line_tax').val() ); var line_tax = accounting.unformat( $(this).find('input.line_tax').val() );
@ -459,7 +459,7 @@ jQuery( function($){
var order_total = line_totals + cart_tax + order_shipping + order_shipping_tax - order_discount; var order_total = line_totals + cart_tax + order_shipping + order_shipping_tax - order_discount;
order_total = accounting.toFixed( order_total, 2 ); order_total = accounting.toFixed( order_total, 2 );
cart_tax = accounting.toFixed( cart_tax, 2 ); cart_tax = accounting.toFixed( cart_tax, 2 );
// Set fields // Set fields
$('#_cart_discount').val( cart_discount ).change(); $('#_cart_discount').val( cart_discount ).change();
$('#_order_tax').val( cart_tax ).change(); $('#_order_tax').val( cart_tax ).change();
@ -476,10 +476,10 @@ jQuery( function($){
}, function() { }, function() {
$('#woocommerce-order-totals .calculated').css('background-color', ''); $('#woocommerce-order-totals .calculated').css('background-color', '');
}); });
// Add a line item // Add a line item
$('#woocommerce-order-items button.add_order_item').click(function(){ $('#woocommerce-order-items button.add_order_item').click(function(){
var add_item_ids = $('select#add_item_id').val(); var add_item_ids = $('select#add_item_id').val();
if ( add_item_ids ) { if ( add_item_ids ) {
@ -512,7 +512,7 @@ jQuery( function($){
$('select#add_item_id').trigger("liszt:updated"); $('select#add_item_id').trigger("liszt:updated");
$('table.woocommerce_order_items').unblock(); $('table.woocommerce_order_items').unblock();
} }
$('#order_items_list tr.new_row').trigger('init_row').removeClass('new_row'); $('#order_items_list tr.new_row').trigger('init_row').removeClass('new_row');
}); });
@ -523,10 +523,10 @@ jQuery( function($){
} }
return false; return false;
}); });
// Add a fee // Add a fee
$('#woocommerce-order-items button.add_order_fee').click(function(){ $('#woocommerce-order-items button.add_order_fee').click(function(){
$('table.woocommerce_order_items').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_writepanel_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } }); $('table.woocommerce_order_items').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_writepanel_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
var data = { var data = {
@ -544,18 +544,18 @@ jQuery( function($){
// Add some meta to a line item // Add some meta to a line item
$('#order_items_list button.add_order_item_meta').live('click', function(){ $('#order_items_list button.add_order_item_meta').live('click', function(){
var $button = $(this); var $button = $(this);
var $item = $button.closest('tr.item'); var $item = $button.closest('tr.item');
var data = { var data = {
order_item_id: $item.attr( 'data-order_item_id' ), order_item_id: $item.attr( 'data-order_item_id' ),
action: 'woocommerce_add_order_item_meta', action: 'woocommerce_add_order_item_meta',
security: woocommerce_writepanel_params.order_item_nonce security: woocommerce_writepanel_params.order_item_nonce
}; };
$('table.woocommerce_order_items').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_writepanel_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } }); $('table.woocommerce_order_items').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_writepanel_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
$.ajax( { $.ajax( {
url: woocommerce_writepanel_params.ajax_url, url: woocommerce_writepanel_params.ajax_url,
data: data, data: data,
@ -573,15 +573,15 @@ jQuery( function($){
var answer = confirm( woocommerce_writepanel_params.remove_item_meta ) var answer = confirm( woocommerce_writepanel_params.remove_item_meta )
if ( answer ) { if ( answer ) {
var $row = $(this).closest('tr'); var $row = $(this).closest('tr');
var data = { var data = {
meta_id: $row.attr( 'data-meta_id' ), meta_id: $row.attr( 'data-meta_id' ),
action: 'woocommerce_remove_order_item_meta', action: 'woocommerce_remove_order_item_meta',
security: woocommerce_writepanel_params.order_item_nonce security: woocommerce_writepanel_params.order_item_nonce
}; };
$('table.woocommerce_order_items').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_writepanel_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } }); $('table.woocommerce_order_items').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_writepanel_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
$.ajax( { $.ajax( {
url: woocommerce_writepanel_params.ajax_url, url: woocommerce_writepanel_params.ajax_url,
data: data, data: data,
@ -594,7 +594,7 @@ jQuery( function($){
} }
return false; return false;
}); });
// Bulk actions for line items // Bulk actions for line items
$('#woocommerce-order-items').on( 'click', 'input.check-column', function() { $('#woocommerce-order-items').on( 'click', 'input.check-column', function() {
if ( $(this).is(':checked') ) if ( $(this).is(':checked') )
@ -602,35 +602,35 @@ jQuery( function($){
else else
$('#woocommerce-order-items').find('.check-column input').removeAttr('checked'); $('#woocommerce-order-items').find('.check-column input').removeAttr('checked');
} ); } );
$('#woocommerce-order-items').on( 'click', '.do_bulk_action', function() { $('#woocommerce-order-items').on( 'click', '.do_bulk_action', function() {
var action = $(this).closest('.bulk_actions').find('select').val(); var action = $(this).closest('.bulk_actions').find('select').val();
var selected_rows = $('#woocommerce-order-items').find('.check-column input:checked'); var selected_rows = $('#woocommerce-order-items').find('.check-column input:checked');
var item_ids = []; var item_ids = [];
$(selected_rows).each( function() { $(selected_rows).each( function() {
var $item = $(this).closest('tr.item, tr.fee'); var $item = $(this).closest('tr.item, tr.fee');
item_ids.push( $item.attr( 'data-order_item_id' ) ); item_ids.push( $item.attr( 'data-order_item_id' ) );
} ); } );
if ( action == 'delete' ) { if ( action == 'delete' ) {
var answer = confirm( woocommerce_writepanel_params.remove_item_notice ); var answer = confirm( woocommerce_writepanel_params.remove_item_notice );
if ( answer ) { if ( answer ) {
$('table.woocommerce_order_items').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_writepanel_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } }); $('table.woocommerce_order_items').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_writepanel_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
var data = { var data = {
order_item_ids: item_ids, order_item_ids: item_ids,
action: 'woocommerce_remove_order_item', action: 'woocommerce_remove_order_item',
security: woocommerce_writepanel_params.order_item_nonce security: woocommerce_writepanel_params.order_item_nonce
}; };
$.ajax( { $.ajax( {
url: woocommerce_writepanel_params.ajax_url, url: woocommerce_writepanel_params.ajax_url,
data: data, data: data,
@ -642,26 +642,26 @@ jQuery( function($){
$('table.woocommerce_order_items').unblock(); $('table.woocommerce_order_items').unblock();
} }
} ); } );
} }
} else if ( action == 'refund' ) { } else if ( action == 'refund' ) {
var order_id = $('#post_ID').val(); var order_id = $('#post_ID').val();
var answer = confirm( woocommerce_writepanel_params.refund_item_notice ); var answer = confirm( woocommerce_writepanel_params.refund_item_notice );
if ( answer ) { if ( answer ) {
$('table.woocommerce_order_items').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_writepanel_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } }); $('table.woocommerce_order_items').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_writepanel_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
var data = { var data = {
order_id: order_id, order_id: order_id,
order_item_ids: item_ids, order_item_ids: item_ids,
action: 'woocommerce_refund_order_item', action: 'woocommerce_refund_order_item',
security: woocommerce_writepanel_params.order_item_nonce security: woocommerce_writepanel_params.order_item_nonce
}; };
$.ajax( { $.ajax( {
url: woocommerce_writepanel_params.ajax_url, url: woocommerce_writepanel_params.ajax_url,
data: data, data: data,
@ -670,23 +670,23 @@ jQuery( function($){
$('table.woocommerce_order_items').unblock(); $('table.woocommerce_order_items').unblock();
} }
} ); } );
} }
} else if ( action == 'reduce_stock' ) { } else if ( action == 'reduce_stock' ) {
$('table.woocommerce_order_items').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_writepanel_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } }); $('table.woocommerce_order_items').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_writepanel_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
var quantities = {}; var quantities = {};
$(selected_rows).each( function() { $(selected_rows).each( function() {
var $item = $(this).closest('tr.item, tr.fee'); var $item = $(this).closest('tr.item, tr.fee');
var $qty = $item.find('input.quantity'); var $qty = $item.find('input.quantity');
quantities[ $item.attr( 'data-order_item_id' ) ] = $qty.val(); quantities[ $item.attr( 'data-order_item_id' ) ] = $qty.val();
} ); } );
var data = { var data = {
order_id: woocommerce_writepanel_params.post_id, order_id: woocommerce_writepanel_params.post_id,
order_item_ids: item_ids, order_item_ids: item_ids,
@ -694,7 +694,7 @@ jQuery( function($){
action: 'woocommerce_reduce_order_item_stock', action: 'woocommerce_reduce_order_item_stock',
security: woocommerce_writepanel_params.order_item_nonce security: woocommerce_writepanel_params.order_item_nonce
}; };
$.ajax( { $.ajax( {
url: woocommerce_writepanel_params.ajax_url, url: woocommerce_writepanel_params.ajax_url,
data: data, data: data,
@ -703,22 +703,22 @@ jQuery( function($){
alert( response ); alert( response );
$('table.woocommerce_order_items').unblock(); $('table.woocommerce_order_items').unblock();
} }
} ); } );
} else if ( action == 'increase_stock' ) { } else if ( action == 'increase_stock' ) {
$('table.woocommerce_order_items').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_writepanel_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } }); $('table.woocommerce_order_items').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_writepanel_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
var quantities = {}; var quantities = {};
$(selected_rows).each( function() { $(selected_rows).each( function() {
var $item = $(this).closest('tr.item, tr.fee'); var $item = $(this).closest('tr.item, tr.fee');
var $qty = $item.find('input.quantity'); var $qty = $item.find('input.quantity');
quantities[ $item.attr( 'data-order_item_id' ) ] = $qty.val(); quantities[ $item.attr( 'data-order_item_id' ) ] = $qty.val();
} ); } );
var data = { var data = {
order_id: woocommerce_writepanel_params.post_id, order_id: woocommerce_writepanel_params.post_id,
order_item_ids: item_ids, order_item_ids: item_ids,
@ -726,7 +726,7 @@ jQuery( function($){
action: 'woocommerce_increase_order_item_stock', action: 'woocommerce_increase_order_item_stock',
security: woocommerce_writepanel_params.order_item_nonce security: woocommerce_writepanel_params.order_item_nonce
}; };
$.ajax( { $.ajax( {
url: woocommerce_writepanel_params.ajax_url, url: woocommerce_writepanel_params.ajax_url,
data: data, data: data,
@ -735,12 +735,12 @@ jQuery( function($){
alert( response ); alert( response );
$('table.woocommerce_order_items').unblock(); $('table.woocommerce_order_items').unblock();
} }
} ); } );
} }
return false; return false;
} ); } );
$('button.load_customer_billing').live('click', function(){ $('button.load_customer_billing').live('click', function(){
@ -878,13 +878,13 @@ jQuery( function($){
return false; return false;
}); });
// Delete a tax row // Delete a tax row
$('a.delete_tax_row').live('click', function(){ $('a.delete_tax_row').live('click', function(){
$tax_row = $(this).closest('.tax_row'); $tax_row = $(this).closest('.tax_row');
var tax_row_id = $tax_row.attr( 'data-order_item_id' ) var tax_row_id = $tax_row.attr( 'data-order_item_id' )
var data = { var data = {
tax_row_id: tax_row_id, tax_row_id: tax_row_id,
action: 'woocommerce_remove_line_tax', action: 'woocommerce_remove_line_tax',
@ -902,7 +902,7 @@ jQuery( function($){
$('#tax_rows').closest('.totals_group').unblock(); $('#tax_rows').closest('.totals_group').unblock();
} }
}); });
return false; return false;
}); });
@ -974,50 +974,50 @@ jQuery( function($){
// Sale price schedule // Sale price schedule
$('.sale_price_dates_fields').each(function() { $('.sale_price_dates_fields').each(function() {
var $these_sale_dates = $(this); var $these_sale_dates = $(this);
var sale_schedule_set = false; var sale_schedule_set = false;
var $wrap = $these_sale_dates.closest( 'div, table' ); var $wrap = $these_sale_dates.closest( 'div, table' );
$these_sale_dates.find('input').each(function(){ $these_sale_dates.find('input').each(function(){
if ( $(this).val() != '' ) if ( $(this).val() != '' )
sale_schedule_set = true; sale_schedule_set = true;
}); });
if ( sale_schedule_set ) { if ( sale_schedule_set ) {
$wrap.find('.sale_schedule').hide(); $wrap.find('.sale_schedule').hide();
$wrap.find('.sale_price_dates_fields').show(); $wrap.find('.sale_price_dates_fields').show();
} else { } else {
$wrap.find('.sale_schedule').show(); $wrap.find('.sale_schedule').show();
$wrap.find('.sale_price_dates_fields').hide(); $wrap.find('.sale_price_dates_fields').hide();
} }
}); });
$('#woocommerce-product-data').on( 'click', '.sale_schedule', function() { $('#woocommerce-product-data').on( 'click', '.sale_schedule', function() {
var $wrap = $(this).closest( 'div, table' ); var $wrap = $(this).closest( 'div, table' );
$(this).hide(); $(this).hide();
$wrap.find('.cancel_sale_schedule').show(); $wrap.find('.cancel_sale_schedule').show();
$wrap.find('.sale_price_dates_fields').show(); $wrap.find('.sale_price_dates_fields').show();
return false; return false;
}); });
$('#woocommerce-product-data').on( 'click', '.cancel_sale_schedule', function() { $('#woocommerce-product-data').on( 'click', '.cancel_sale_schedule', function() {
var $wrap = $(this).closest( 'div, table' ); var $wrap = $(this).closest( 'div, table' );
$(this).hide(); $(this).hide();
$wrap.find('.sale_schedule').show(); $wrap.find('.sale_schedule').show();
$wrap.find('.sale_price_dates_fields').hide(); $wrap.find('.sale_price_dates_fields').hide();
$wrap.find('.sale_price_dates_fields').find('input').val(''); $wrap.find('.sale_price_dates_fields').find('input').val('');
return false; return false;
}); });
// STOCK OPTIONS // STOCK OPTIONS
$('input#_manage_stock').change(function(){ $('input#_manage_stock').change(function(){
@ -1264,12 +1264,12 @@ jQuery( function($){
return false; return false;
}); });
// Save attributes and update variations // Save attributes and update variations
$('.save_attributes').on('click', function(){ $('.save_attributes').on('click', function(){
$('.woocommerce_attributes').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_writepanel_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } }); $('.woocommerce_attributes').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_writepanel_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
var data = { var data = {
post_id: woocommerce_writepanel_params.post_id, post_id: woocommerce_writepanel_params.post_id,
data: $('.woocommerce_attributes').find('input, select').serialize(), data: $('.woocommerce_attributes').find('input, select').serialize(),
@ -1280,9 +1280,9 @@ jQuery( function($){
$.post( woocommerce_writepanel_params.ajax_url, data, function( response ) { $.post( woocommerce_writepanel_params.ajax_url, data, function( response ) {
var this_page = window.location.toString(); var this_page = window.location.toString();
this_page = this_page.replace( 'post-new.php?', 'post.php?post=' + woocommerce_writepanel_params.post_id + '&action=edit&' ); this_page = this_page.replace( 'post-new.php?', 'post.php?post=' + woocommerce_writepanel_params.post_id + '&action=edit&' );
// Load variations panel // Load variations panel
$('#variable_product_options').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_writepanel_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } }); $('#variable_product_options').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_writepanel_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
$('#variable_product_options').load( this_page + ' #variable_product_options_inner', function() { $('#variable_product_options').load( this_page + ' #variable_product_options_inner', function() {
@ -1292,7 +1292,7 @@ jQuery( function($){
$('.woocommerce_attributes').unblock(); $('.woocommerce_attributes').unblock();
}); });
}); });
// Uploading files // Uploading files

View File

@ -28,7 +28,7 @@
isIE6 = $.browser.msie && $.browser.version < 7 && !window.XMLHttpRequest, isIE6 = $.browser.msie && $.browser.version < 7 && !window.XMLHttpRequest,
/* /*
* Private methods * Private methods
*/ */
_abort = function() { _abort = function() {
@ -62,8 +62,8 @@
_start = function() { _start = function() {
var obj = selectedArray[ selectedIndex ], var obj = selectedArray[ selectedIndex ],
href, href,
type, type,
title, title,
str, str,
emb, emb,
@ -145,7 +145,7 @@
selectedOpts.width = 'auto'; selectedOpts.width = 'auto';
selectedOpts.height = 'auto'; selectedOpts.height = 'auto';
} else { } else {
selectedOpts.autoDimensions = false; selectedOpts.autoDimensions = false;
} }
} }
@ -163,7 +163,7 @@
tmp.css('padding', (selectedOpts.padding + selectedOpts.margin)); tmp.css('padding', (selectedOpts.padding + selectedOpts.margin));
$('.fancybox-inline-tmp').unbind('fancybox-cancel').bind('fancybox-change', function() { $('.fancybox-inline-tmp').unbind('fancybox-cancel').bind('fancybox-change', function() {
$(this).replaceWith(content.children()); $(this).replaceWith(content.children());
}); });
switch (type) { switch (type) {
@ -284,14 +284,14 @@
w = parseInt( ($(window).width() - (selectedOpts.margin * 2)) * parseFloat(w) / 100, 10) + 'px'; w = parseInt( ($(window).width() - (selectedOpts.margin * 2)) * parseFloat(w) / 100, 10) + 'px';
} else { } else {
w = w == 'auto' ? 'auto' : w + 'px'; w = w == 'auto' ? 'auto' : w + 'px';
} }
if (h.toString().indexOf('%') > -1) { if (h.toString().indexOf('%') > -1) {
h = parseInt( ($(window).height() - (selectedOpts.margin * 2)) * parseFloat(h) / 100, 10) + 'px'; h = parseInt( ($(window).height() - (selectedOpts.margin * 2)) * parseFloat(h) / 100, 10) + 'px';
} else { } else {
h = h == 'auto' ? 'auto' : h + 'px'; h = h == 'auto' ? 'auto' : h + 'px';
} }
tmp.wrapInner('<div style="width:' + w + ';height:' + h + ';overflow: ' + (selectedOpts.scrolling == 'auto' ? 'auto' : (selectedOpts.scrolling == 'yes' ? 'scroll' : 'hidden')) + ';position:relative;"></div>'); tmp.wrapInner('<div style="width:' + w + ';height:' + h + ';overflow: ' + (selectedOpts.scrolling == 'auto' ? 'auto' : (selectedOpts.scrolling == 'yes' ? 'scroll' : 'hidden')) + ';position:relative;"></div>');
@ -444,8 +444,8 @@
return; return;
} }
if (currentOpts.titlePosition == 'inside' && titleHeight > 0) { if (currentOpts.titlePosition == 'inside' && titleHeight > 0) {
title.show(); title.show();
} }
content content
@ -555,7 +555,7 @@
}); });
} }
if (!currentOpts.showNavArrows) { if (!currentOpts.showNavArrows) {
nav_left.hide(); nav_left.hide();
nav_right.hide(); nav_right.hide();
return; return;
@ -591,7 +591,7 @@
} }
_set_navigation(); _set_navigation();
if (currentOpts.hideOnContentClick) { if (currentOpts.hideOnContentClick) {
content.bind('click', $.fancybox.close); content.bind('click', $.fancybox.close);
} }
@ -622,7 +622,7 @@
}, },
_preload_images = function() { _preload_images = function() {
var href, var href,
objNext; objNext;
if ((currentArray.length -1) > currentIndex) { if ((currentArray.length -1) > currentIndex) {
@ -776,7 +776,7 @@
}; };
/* /*
* Public methods * Public methods
*/ */
$.fn.fancybox = function(options) { $.fn.fancybox = function(options) {
@ -1009,14 +1009,14 @@
var view, align; var view, align;
if (busy) { if (busy) {
return; return;
} }
align = arguments[0] === true ? 1 : 0; align = arguments[0] === true ? 1 : 0;
view = _get_viewport(); view = _get_viewport();
if (!align && (wrap.width() > view[0] || wrap.height() > view[1])) { if (!align && (wrap.width() > view[0] || wrap.height() > view[1])) {
return; return;
} }
wrap wrap
@ -1145,21 +1145,21 @@
}; };
$(document).ready(function() { $(document).ready(function() {
$.fancybox.init(); $.fancybox.init();
// Hide review form - it will be in a lightbox // Hide review form - it will be in a lightbox
$('#review_form_wrapper').hide(); $('#review_form_wrapper').hide();
// Lightbox // Lightbox
$('a.zoom, a.show_review_form').fancybox({ $('a.zoom, a.show_review_form').fancybox({
'transitionIn' : 'elastic', 'transitionIn' : 'elastic',
'transitionOut' : 'elastic', 'transitionOut' : 'elastic',
'speedIn' : 600, 'speedIn' : 600,
'speedOut' : 200, 'speedOut' : 200,
'overlayShow' : true 'overlayShow' : true
}); });
}); });
})(jQuery); })(jQuery);

View File

@ -269,7 +269,7 @@
s = '<div class="blockUI ' + opts.blockMsgClass + ' blockElement ui-dialog ui-widget ui-corner-all" style="z-index:'+(z+10)+';display:none;position:absolute">'; s = '<div class="blockUI ' + opts.blockMsgClass + ' blockElement ui-dialog ui-widget ui-corner-all" style="z-index:'+(z+10)+';display:none;position:absolute">';
if ( opts.title ) { if ( opts.title ) {
s += '<div class="ui-widget-header ui-dialog-titlebar ui-corner-all blockTitle">'+(opts.title || '&nbsp;')+'</div>'; s += '<div class="ui-widget-header ui-dialog-titlebar ui-corner-all blockTitle">'+(opts.title || '&nbsp;')+'</div>';
} }
s += '<div class="ui-widget-content ui-dialog-content"></div>'; s += '<div class="ui-widget-content ui-dialog-content"></div>';
s += '</div>'; s += '</div>';
} }

View File

@ -10,7 +10,7 @@
* browser tooltip. It is extremely lightweight and very smart in * browser tooltip. It is extremely lightweight and very smart in
* that it detects the edges of the browser window and will make sure * that it detects the edges of the browser window and will make sure
* the tooltip stays within the current window size. As a result the * the tooltip stays within the current window size. As a result the
* tooltip will adjust itself to be displayed above, below, to the left * tooltip will adjust itself to be displayed above, below, to the left
* or to the right depending on what is necessary to stay within the * or to the right depending on what is necessary to stay within the
* browser window. It is completely customizable as well via CSS. * browser window. It is completely customizable as well via CSS.
* *
@ -21,7 +21,7 @@
(function($){ (function($){
$.fn.tipTip = function(options) { $.fn.tipTip = function(options) {
var defaults = { var defaults = {
activation: "hover", activation: "hover",
keepAlive: false, keepAlive: false,
maxWidth: "200px", maxWidth: "200px",
@ -36,7 +36,7 @@
exit: function(){} exit: function(){}
}; };
var opts = $.extend(defaults, options); var opts = $.extend(defaults, options);
// Setup tip tip elements and render them to the DOM // Setup tip tip elements and render them to the DOM
if($("#tiptip_holder").length <= 0){ if($("#tiptip_holder").length <= 0){
var tiptip_holder = $('<div id="tiptip_holder" style="max-width:'+ opts.maxWidth +';"></div>'); var tiptip_holder = $('<div id="tiptip_holder" style="max-width:'+ opts.maxWidth +';"></div>');
@ -48,7 +48,7 @@
var tiptip_content = $("#tiptip_content"); var tiptip_content = $("#tiptip_content");
var tiptip_arrow = $("#tiptip_arrow"); var tiptip_arrow = $("#tiptip_arrow");
} }
return this.each(function(){ return this.each(function(){
var org_elem = $(this); var org_elem = $(this);
if(opts.content){ if(opts.content){
@ -61,7 +61,7 @@
org_elem.removeAttr(opts.attribute); //remove original Attribute org_elem.removeAttr(opts.attribute); //remove original Attribute
} }
var timeout = false; var timeout = false;
if(opts.activation == "hover"){ if(opts.activation == "hover"){
org_elem.hover(function(){ org_elem.hover(function(){
active_tiptip(); active_tiptip();
@ -96,13 +96,13 @@
}); });
} }
} }
function active_tiptip(){ function active_tiptip(){
opts.enter.call(this); opts.enter.call(this);
tiptip_content.html(org_title); tiptip_content.html(org_title);
tiptip_holder.hide().removeAttr("class").css("margin","0"); tiptip_holder.hide().removeAttr("class").css("margin","0");
tiptip_arrow.removeAttr("style"); tiptip_arrow.removeAttr("style");
var top = parseInt(org_elem.offset()['top']); var top = parseInt(org_elem.offset()['top']);
var left = parseInt(org_elem.offset()['left']); var left = parseInt(org_elem.offset()['left']);
var org_width = parseInt(org_elem.outerWidth()); var org_width = parseInt(org_elem.outerWidth());
@ -119,17 +119,17 @@
if(opts.defaultPosition == "bottom"){ if(opts.defaultPosition == "bottom"){
t_class = "_bottom"; t_class = "_bottom";
} else if(opts.defaultPosition == "top"){ } else if(opts.defaultPosition == "top"){
t_class = "_top"; t_class = "_top";
} else if(opts.defaultPosition == "left"){ } else if(opts.defaultPosition == "left"){
t_class = "_left"; t_class = "_left";
} else if(opts.defaultPosition == "right"){ } else if(opts.defaultPosition == "right"){
t_class = "_right"; t_class = "_right";
} }
var right_compare = (w_compare + left) < parseInt($(window).scrollLeft()); var right_compare = (w_compare + left) < parseInt($(window).scrollLeft());
var left_compare = (tip_w + left) > parseInt($(window).width()); var left_compare = (tip_w + left) > parseInt($(window).width());
if((right_compare && w_compare < 0) || (t_class == "_right" && !left_compare) || (t_class == "_left" && left < (tip_w + opts.edgeOffset + 5))){ if((right_compare && w_compare < 0) || (t_class == "_right" && !left_compare) || (t_class == "_left" && left < (tip_w + opts.edgeOffset + 5))){
t_class = "_right"; t_class = "_right";
arrow_top = Math.round(tip_h - 13) / 2; arrow_top = Math.round(tip_h - 13) / 2;
@ -146,7 +146,7 @@
var top_compare = (top + org_height + opts.edgeOffset + tip_h + 8) > parseInt($(window).height() + $(window).scrollTop()); var top_compare = (top + org_height + opts.edgeOffset + tip_h + 8) > parseInt($(window).height() + $(window).scrollTop());
var bottom_compare = ((top + org_height) - (opts.edgeOffset + tip_h + 8)) < 0; var bottom_compare = ((top + org_height) - (opts.edgeOffset + tip_h + 8)) < 0;
if(top_compare || (t_class == "_bottom" && top_compare) || (t_class == "_top" && !bottom_compare)){ if(top_compare || (t_class == "_bottom" && top_compare) || (t_class == "_top" && !bottom_compare)){
if(t_class == "_top" || t_class == "_bottom"){ if(t_class == "_top" || t_class == "_bottom"){
t_class = "_top"; t_class = "_top";
@ -161,31 +161,31 @@
} else { } else {
t_class = t_class+"_bottom"; t_class = t_class+"_bottom";
} }
arrow_top = -12; arrow_top = -12;
marg_top = Math.round(top + org_height + opts.edgeOffset); marg_top = Math.round(top + org_height + opts.edgeOffset);
} }
if(t_class == "_right_top" || t_class == "_left_top"){ if(t_class == "_right_top" || t_class == "_left_top"){
marg_top = marg_top + 5; marg_top = marg_top + 5;
} else if(t_class == "_right_bottom" || t_class == "_left_bottom"){ } else if(t_class == "_right_bottom" || t_class == "_left_bottom"){
marg_top = marg_top - 5; marg_top = marg_top - 5;
} }
if(t_class == "_left_top" || t_class == "_left_bottom"){ if(t_class == "_left_top" || t_class == "_left_bottom"){
marg_left = marg_left + 5; marg_left = marg_left + 5;
} }
tiptip_arrow.css({"margin-left": arrow_left+"px", "margin-top": arrow_top+"px"}); tiptip_arrow.css({"margin-left": arrow_left+"px", "margin-top": arrow_top+"px"});
tiptip_holder.css({"margin-left": marg_left+"px", "margin-top": marg_top+"px"}).attr("class","tip"+t_class); tiptip_holder.css({"margin-left": marg_left+"px", "margin-top": marg_top+"px"}).attr("class","tip"+t_class);
if (timeout){ clearTimeout(timeout); } if (timeout){ clearTimeout(timeout); }
timeout = setTimeout(function(){ tiptip_holder.stop(true,true).fadeIn(opts.fadeIn); }, opts.delay); timeout = setTimeout(function(){ tiptip_holder.stop(true,true).fadeIn(opts.fadeIn); }, opts.delay);
} }
function deactive_tiptip(){ function deactive_tiptip(){
opts.exit.call(this); opts.exit.call(this);
if (timeout){ clearTimeout(timeout); } if (timeout){ clearTimeout(timeout); }
tiptip_holder.fadeOut(opts.fadeOut); tiptip_holder.fadeOut(opts.fadeOut);
} }
} }
}); });
} }
})(jQuery); })(jQuery);

View File

@ -10,7 +10,7 @@
* browser tooltip. It is extremely lightweight and very smart in * browser tooltip. It is extremely lightweight and very smart in
* that it detects the edges of the browser window and will make sure * that it detects the edges of the browser window and will make sure
* the tooltip stays within the current window size. As a result the * the tooltip stays within the current window size. As a result the
* tooltip will adjust itself to be displayed above, below, to the left * tooltip will adjust itself to be displayed above, below, to the left
* or to the right depending on what is necessary to stay within the * or to the right depending on what is necessary to stay within the
* browser window. It is completely customizable as well via CSS. * browser window. It is completely customizable as well via CSS.
* *

View File

@ -106,7 +106,7 @@ abstract class WC_Product {
/** /**
* __construct function. * __construct function.
* *
* @access public * @access public
* @param mixed $product * @param mixed $product
*/ */
@ -118,22 +118,22 @@ abstract class WC_Product {
$this->id = absint( $product ); $this->id = absint( $product );
} }
} }
/** /**
* Load the data from the custom fields * Load the data from the custom fields
* *
* @access public * @access public
* @param mixed $fields * @param mixed $fields
* @return void * @return void
*/ */
function load_product_data( $fields ) { function load_product_data( $fields ) {
if ( $fields ) if ( $fields )
foreach ( $fields as $key => $default ) foreach ( $fields as $key => $default )
$this->$key = isset( $this->product_custom_fields[ '_' . $key ][0] ) && $this->product_custom_fields[ '_' . $key ][0] !== '' ? $this->product_custom_fields[ '_' . $key ][0] : $default; $this->$key = isset( $this->product_custom_fields[ '_' . $key ][0] ) && $this->product_custom_fields[ '_' . $key ][0] !== '' ? $this->product_custom_fields[ '_' . $key ][0] : $default;
} }
/** /**
* Get SKU (Stock-keeping unit) - product unique ID. * Get SKU (Stock-keeping unit) - product unique ID.
* *
@ -156,8 +156,8 @@ abstract class WC_Product {
return apply_filters( 'woocommerce_stock_amount', $this->stock ); return apply_filters( 'woocommerce_stock_amount', $this->stock );
} }
/** /**
* Get total stock. * Get total stock.
* *
@ -263,17 +263,17 @@ abstract class WC_Product {
return false; return false;
} }
/** /**
* Get file download path identified by $download_id * Get file download path identified by $download_id
* *
* @access public * @access public
* @param string $download_id file identifier * @param string $download_id file identifier
* @return array * @return array
*/ */
function get_file_download_path( $download_id ) { function get_file_download_path( $download_id ) {
$file_paths = isset( $this->product_custom_fields['_file_paths'][0] ) ? $this->product_custom_fields['_file_paths'][0] : ''; $file_paths = isset( $this->product_custom_fields['_file_paths'][0] ) ? $this->product_custom_fields['_file_paths'][0] : '';
$file_paths = apply_filters( 'woocommerce_file_download_paths', $file_paths, $this->id, null, null ); $file_paths = apply_filters( 'woocommerce_file_download_paths', $file_paths, $this->id, null, null );
@ -311,8 +311,8 @@ abstract class WC_Product {
function needs_shipping() { function needs_shipping() {
return $this->is_virtual() ? false : true; return $this->is_virtual() ? false : true;
} }
/** /**
* Check if a product is sold individually (no quantities) * Check if a product is sold individually (no quantities)
* *
@ -332,15 +332,15 @@ abstract class WC_Product {
/** /**
* get_children function. * get_children function.
* *
* @access public * @access public
* @return bool * @return bool
*/ */
function get_children() { function get_children() {
return array(); return array();
} }
/** /**
* Returns whether or not the product has any child product. * Returns whether or not the product has any child product.
* *
@ -360,7 +360,7 @@ abstract class WC_Product {
*/ */
function exists() { function exists() {
global $wpdb; global $wpdb;
return ! empty( $this->post ) || $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE ID = %d LIMIT 1;", $this->id ) ) > 0 ? true : false; return ! empty( $this->post ) || $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE ID = %d LIMIT 1;", $this->id ) ) > 0 ? true : false;
} }
@ -836,9 +836,9 @@ abstract class WC_Product {
*/ */
function get_rating_html( $location = '' ) { function get_rating_html( $location = '' ) {
if ( $location ) if ( $location )
$location = '_' . $location; $location = '_' . $location;
$star_size = apply_filters( 'woocommerce_star_rating_size' . $location, 16 ); $star_size = apply_filters( 'woocommerce_star_rating_size' . $location, 16 );
if ( false === ( $average_rating = get_transient( 'wc_average_rating_' . $this->id ) ) ) { if ( false === ( $average_rating = get_transient( 'wc_average_rating_' . $this->id ) ) ) {
@ -938,9 +938,9 @@ abstract class WC_Product {
function get_shipping_class() { function get_shipping_class() {
if ( ! $this->shipping_class ) { if ( ! $this->shipping_class ) {
$classes = get_the_terms( $this->id, 'product_shipping_class' ); $classes = get_the_terms( $this->id, 'product_shipping_class' );
if ( $classes && ! is_wp_error( $classes ) ) if ( $classes && ! is_wp_error( $classes ) )
$this->shipping_class = current( $classes )->slug; $this->shipping_class = current( $classes )->slug;
else else
$this->shipping_class = ''; $this->shipping_class = '';
} }
return $this->shipping_class; return $this->shipping_class;
@ -1084,7 +1084,7 @@ abstract class WC_Product {
function has_attributes() { function has_attributes() {
if ( sizeof( $this->get_attributes() ) > 0 ) { if ( sizeof( $this->get_attributes() ) > 0 ) {
foreach ( $this->get_attributes() as $attribute ) { foreach ( $this->get_attributes() as $attribute ) {
if ( isset( $attribute['is_visible'] ) && $attribute['is_visible'] ) if ( isset( $attribute['is_visible'] ) && $attribute['is_visible'] )
return true; return true;
} }
} }
@ -1198,11 +1198,11 @@ abstract class WC_Product {
* @return void * @return void
*/ */
function check_sale_price() { function check_sale_price() {
if ( $this->sale_price_dates_from && $this->sale_price_dates_from < current_time('timestamp') ) { if ( $this->sale_price_dates_from && $this->sale_price_dates_from < current_time('timestamp') ) {
if ( $this->sale_price && $this->price !== $this->sale_price ) { if ( $this->sale_price && $this->price !== $this->sale_price ) {
// Update price // Update price
$this->price = $this->sale_price; $this->price = $this->sale_price;
update_post_meta( $this->id, '_price', $this->price ); update_post_meta( $this->id, '_price', $this->price );

View File

@ -13,7 +13,7 @@ abstract class WC_Session {
/** /**
* save_data function to be implemented * save_data function to be implemented
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -29,10 +29,10 @@ abstract class WC_Session {
// When leaving or ending page load, store data // When leaving or ending page load, store data
add_action( 'shutdown', array( &$this, 'save_data' ), 20 ); add_action( 'shutdown', array( &$this, 'save_data' ), 20 );
} }
/** /**
* __get function. * __get function.
* *
* @access public * @access public
* @param mixed $property * @param mixed $property
* @return mixed * @return mixed
@ -40,10 +40,10 @@ abstract class WC_Session {
public function __get( $property ) { public function __get( $property ) {
return isset( $this->_data[ $property ] ) ? $this->_data[ $property ] : null; return isset( $this->_data[ $property ] ) ? $this->_data[ $property ] : null;
} }
/** /**
* __set function. * __set function.
* *
* @access public * @access public
* @param mixed $property * @param mixed $property
* @param mixed $value * @param mixed $value
@ -52,10 +52,10 @@ abstract class WC_Session {
public function __set( $property, $value ) { public function __set( $property, $value ) {
$this->_data[ $property ] = $value; $this->_data[ $property ] = $value;
} }
/** /**
* __isset function. * __isset function.
* *
* @access public * @access public
* @param mixed $property * @param mixed $property
* @return bool * @return bool
@ -63,10 +63,10 @@ abstract class WC_Session {
public function __isset( $property ) { public function __isset( $property ) {
return isset( $this->_data[ $property ] ); return isset( $this->_data[ $property ] );
} }
/** /**
* __unset function. * __unset function.
* *
* @access public * @access public
* @param mixed $property * @param mixed $property
* @return void * @return void

View File

@ -53,7 +53,7 @@ class WC_Cart {
/** @var float Discounts after tax. */ /** @var float Discounts after tax. */
var $discount_total; var $discount_total;
/** @var float Total for additonal fees. */ /** @var float Total for additonal fees. */
var $fee_total; var $fee_total;
@ -68,7 +68,7 @@ class WC_Cart {
/** @var WC_Tax */ /** @var WC_Tax */
var $tax; var $tax;
/** @var array An array of fees. */ /** @var array An array of fees. */
var $fees; var $fees;
@ -240,7 +240,7 @@ class WC_Cart {
$this->cart_contents = array(); $this->cart_contents = array();
$this->reset(); $this->reset();
unset( $woocommerce->session->order_awaiting_payment, $woocommerce->session->coupons, $woocommerce->session->cart ); unset( $woocommerce->session->order_awaiting_payment, $woocommerce->session->coupons, $woocommerce->session->cart );
if ( $clear_persistent_cart && get_current_user_id() ) if ( $clear_persistent_cart && get_current_user_id() )
@ -749,17 +749,17 @@ class WC_Cart {
// Stock check - only check if we're managing stock and backorders are not allowed // Stock check - only check if we're managing stock and backorders are not allowed
if ( ! $product_data->is_in_stock() ) { if ( ! $product_data->is_in_stock() ) {
$woocommerce->add_error( sprintf( __( 'You cannot add &quot;%s&quot; to the cart because the product is out of stock.', 'woocommerce' ), $product_data->get_title() ) ); $woocommerce->add_error( sprintf( __( 'You cannot add &quot;%s&quot; to the cart because the product is out of stock.', 'woocommerce' ), $product_data->get_title() ) );
return false; return false;
} elseif ( ! $product_data->has_enough_stock( $quantity ) ) { } elseif ( ! $product_data->has_enough_stock( $quantity ) ) {
$woocommerce->add_error( sprintf(__( 'You cannot add that amount of &quot;%s&quot; to the cart because there is not enough stock (%s remaining).', 'woocommerce' ), $product_data->get_title(), $product_data->get_stock_quantity() )); $woocommerce->add_error( sprintf(__( 'You cannot add that amount of &quot;%s&quot; to the cart because there is not enough stock (%s remaining).', 'woocommerce' ), $product_data->get_title(), $product_data->get_stock_quantity() ));
return false; return false;
} }
// Downloadable/virtual qty check // Downloadable/virtual qty check
if ( $product_data->is_sold_individually() ) { if ( $product_data->is_sold_individually() ) {
@ -1380,19 +1380,19 @@ class WC_Cart {
} }
} }
} }
// Add fees // Add fees
foreach ( $this->get_fees() as $fee ) { foreach ( $this->get_fees() as $fee ) {
$this->fee_total += $fee->amount; $this->fee_total += $fee->amount;
if ( $fee->taxable ) { if ( $fee->taxable ) {
// Get tax rates // Get tax rates
$tax_rates = $this->tax->get_rates(); $tax_rates = $this->tax->get_rates();
$fee_taxes = $this->tax->calc_tax( $fee->amount, $tax_rates, false ); $fee_taxes = $this->tax->calc_tax( $fee->amount, $tax_rates, false );
// Store // Store
$fee->tax = array_sum( $fee_taxes ); $fee->tax = array_sum( $fee_taxes );
// Tax rows - merge the totals we just got // Tax rows - merge the totals we just got
foreach ( array_keys( $this->taxes + $fee_taxes ) as $key ) { foreach ( array_keys( $this->taxes + $fee_taxes ) as $key ) {
$this->taxes[ $key ] = ( isset( $fee_taxes[ $key ] ) ? $fee_taxes[ $key ] : 0 ) + ( isset( $this->taxes[ $key ] ) ? $this->taxes[ $key ] : 0 ); $this->taxes[ $key ] = ( isset( $fee_taxes[ $key ] ) ? $fee_taxes[ $key ] : 0 ) + ( isset( $this->taxes[ $key ] ) ? $this->taxes[ $key ] : 0 );
@ -1407,7 +1407,7 @@ class WC_Cart {
if ( $woocommerce->customer->is_vat_exempt() ) { if ( $woocommerce->customer->is_vat_exempt() ) {
$this->shipping_tax_total = $this->tax_total = 0; $this->shipping_tax_total = $this->tax_total = 0;
$this->taxes = $this->shipping_taxes = array(); $this->taxes = $this->shipping_taxes = array();
foreach ( $this->cart_contents as $cart_item_key => $item ) foreach ( $this->cart_contents as $cart_item_key => $item )
$this->cart_contents[ $cart_item_key ]['line_subtotal_tax'] = $this->cart_contents[ $cart_item_key ]['line_tax'] = 0; $this->cart_contents[ $cart_item_key ]['line_subtotal_tax'] = $this->cart_contents[ $cart_item_key ]['line_tax'] = 0;
} }
@ -1440,8 +1440,8 @@ class WC_Cart {
* Based on discounted product prices, discounted tax, shipping cost + tax, and any discounts to be added after tax (e.g. store credit) * Based on discounted product prices, discounted tax, shipping cost + tax, and any discounts to be added after tax (e.g. store credit)
*/ */
$this->total = apply_filters( 'woocommerce_calculated_total', number_format( $this->cart_contents_total + $this->tax_total + $this->shipping_tax_total + $this->shipping_total - $this->discount_total + $this->fee_total, $this->dp, '.', '' ), $this ); $this->total = apply_filters( 'woocommerce_calculated_total', number_format( $this->cart_contents_total + $this->tax_total + $this->shipping_tax_total + $this->shipping_total - $this->discount_total + $this->fee_total, $this->dp, '.', '' ), $this );
if ( $this->total < 0 ) if ( $this->total < 0 )
$this->total = 0; $this->total = 0;
} }
@ -1673,7 +1673,7 @@ class WC_Cart {
} }
$this->applied_coupons[] = $coupon_code; $this->applied_coupons[] = $coupon_code;
// Choose free shipping // Choose free shipping
if ( $the_coupon->enable_free_shipping() ) { if ( $the_coupon->enable_free_shipping() ) {
$woocommerce->session->chosen_shipping_method = 'free_shipping'; $woocommerce->session->chosen_shipping_method = 'free_shipping';
@ -1741,7 +1741,7 @@ class WC_Cart {
/** /**
* add_fee function. * add_fee function.
* *
* @access public * @access public
* @param mixed $name * @param mixed $name
* @param mixed $amount * @param mixed $amount
@ -1750,10 +1750,10 @@ class WC_Cart {
* @return void * @return void
*/ */
function add_fee( $name, $amount, $taxable = false, $tax_class = '' ) { function add_fee( $name, $amount, $taxable = false, $tax_class = '' ) {
if ( empty( $this->fees ) ) if ( empty( $this->fees ) )
$this->fees = array(); $this->fees = array();
$new_fee = new stdClass(); $new_fee = new stdClass();
$new_fee->id = sanitize_title( $name ); $new_fee->id = sanitize_title( $name );
$new_fee->name = esc_attr( $name ); $new_fee->name = esc_attr( $name );
@ -1761,13 +1761,13 @@ class WC_Cart {
$new_fee->tax_class = $tax_class; $new_fee->tax_class = $tax_class;
$new_fee->taxable = $taxable ? true : false; $new_fee->taxable = $taxable ? true : false;
$new_fee->tax = 0; $new_fee->tax = 0;
$this->fees[] = $new_fee; $this->fees[] = $new_fee;
} }
/** /**
* get_fees function. * get_fees function.
* *
* @access public * @access public
* @return void * @return void
*/ */

View File

@ -122,7 +122,7 @@ class WC_Checkout {
function process_checkout() { function process_checkout() {
global $wpdb, $woocommerce; global $wpdb, $woocommerce;
if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) )
define( 'WOOCOMMERCE_CHECKOUT', true ); define( 'WOOCOMMERCE_CHECKOUT', true );
$woocommerce->verify_nonce( 'process_checkout' ); $woocommerce->verify_nonce( 'process_checkout' );
@ -142,7 +142,7 @@ class WC_Checkout {
$this->posted['shipping_method'] = isset( $_POST['shipping_method'] ) ? woocommerce_clean( $_POST['shipping_method'] ) : ''; $this->posted['shipping_method'] = isset( $_POST['shipping_method'] ) ? woocommerce_clean( $_POST['shipping_method'] ) : '';
// Ship to billing only option // Ship to billing only option
if ( $woocommerce->cart->ship_to_billing_address_only() ) if ( $woocommerce->cart->ship_to_billing_address_only() )
$this->posted['shiptobilling'] = 1; $this->posted['shiptobilling'] = 1;
// Update customer shipping and payment method to posted method // Update customer shipping and payment method to posted method
@ -398,7 +398,7 @@ class WC_Checkout {
'post_password' => uniqid( 'order_' ) // Protects the post just in case 'post_password' => uniqid( 'order_' ) // Protects the post just in case
) ); ) );
if ( $woocommerce->error_count() > 0 ) if ( $woocommerce->error_count() > 0 )
throw new MyException(); throw new MyException();
// Insert or update the post data // Insert or update the post data
@ -431,15 +431,15 @@ class WC_Checkout {
else else
do_action( 'woocommerce_new_order', $order_id ); // Inserted successfully do_action( 'woocommerce_new_order', $order_id ); // Inserted successfully
} }
// DELETE ANY ITEMS IN CURRENT ORDER // DELETE ANY ITEMS IN CURRENT ORDER
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}woocommerce_order_itemmeta WHERE order_item_id IN ( SELECT order_item_id FROM {$wpdb->prefix}woocommerce_order_items WHERE order_id = %d )", $order_id ) ); $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}woocommerce_order_itemmeta WHERE order_item_id IN ( SELECT order_item_id FROM {$wpdb->prefix}woocommerce_order_items WHERE order_id = %d )", $order_id ) );
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}woocommerce_order_items WHERE order_id = %d", $order_id ) ); $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}woocommerce_order_items WHERE order_id = %d", $order_id ) );
// SAVE LINE ITEMS // SAVE LINE ITEMS
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) { foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data']; $_product = $values['data'];
@ -449,7 +449,7 @@ class WC_Checkout {
'order_item_name' => $_product->get_title(), 'order_item_name' => $_product->get_title(),
'order_item_type' => 'line_item' 'order_item_type' => 'line_item'
) ); ) );
// Add line item meta // Add line item meta
if ( $item_id ) { if ( $item_id ) {
woocommerce_add_order_item_meta( $item_id, '_qty', apply_filters( 'woocommerce_stock_amount', $values['quantity'] ) ); woocommerce_add_order_item_meta( $item_id, '_qty', apply_filters( 'woocommerce_stock_amount', $values['quantity'] ) );
@ -460,39 +460,39 @@ class WC_Checkout {
woocommerce_add_order_item_meta( $item_id, '_line_subtotal_tax', woocommerce_format_decimal( $values['line_subtotal_tax'] ) ); woocommerce_add_order_item_meta( $item_id, '_line_subtotal_tax', woocommerce_format_decimal( $values['line_subtotal_tax'] ) );
woocommerce_add_order_item_meta( $item_id, '_line_total', woocommerce_format_decimal( $values['line_total'] ) ); woocommerce_add_order_item_meta( $item_id, '_line_total', woocommerce_format_decimal( $values['line_total'] ) );
woocommerce_add_order_item_meta( $item_id, '_line_tax', woocommerce_format_decimal( $values['line_tax'] ) ); woocommerce_add_order_item_meta( $item_id, '_line_tax', woocommerce_format_decimal( $values['line_tax'] ) );
// Store variation data in meta so admin can view it // Store variation data in meta so admin can view it
if ( $values['variation'] && is_array( $values['variation'] ) ) if ( $values['variation'] && is_array( $values['variation'] ) )
foreach ( $values['variation'] as $key => $value ) foreach ( $values['variation'] as $key => $value )
woocommerce_add_order_item_meta( $item_id, esc_attr( str_replace( 'attribute_', '', $key ) ), $value ); woocommerce_add_order_item_meta( $item_id, esc_attr( str_replace( 'attribute_', '', $key ) ), $value );
// Add line item meta for backorder status // Add line item meta for backorder status
if ( $_product->backorders_require_notification() && $_product->is_on_backorder( $values['quantity'] ) ) if ( $_product->backorders_require_notification() && $_product->is_on_backorder( $values['quantity'] ) )
woocommerce_add_order_item_meta( $item_id, __( 'Backordered', 'woocommerce' ), $values['quantity'] - max( 0, $_product->get_total_stock() ) ); woocommerce_add_order_item_meta( $item_id, __( 'Backordered', 'woocommerce' ), $values['quantity'] - max( 0, $_product->get_total_stock() ) );
//allow plugins to add order item meta //allow plugins to add order item meta
do_action( 'woocommerce_add_order_item_meta', $item_id, $values ); do_action( 'woocommerce_add_order_item_meta', $item_id, $values );
} }
} }
// Store fees // Store fees
foreach ( $woocommerce->cart->get_fees() as $fee ) { foreach ( $woocommerce->cart->get_fees() as $fee ) {
$item_id = woocommerce_add_order_item( $order_id, array( $item_id = woocommerce_add_order_item( $order_id, array(
'order_item_name' => $fee->name, 'order_item_name' => $fee->name,
'order_item_type' => 'fee' 'order_item_type' => 'fee'
) ); ) );
if ( $fee->taxable ) if ( $fee->taxable )
woocommerce_add_order_item_meta( $item_id, '_tax_class', $fee->tax_class ); woocommerce_add_order_item_meta( $item_id, '_tax_class', $fee->tax_class );
else else
woocommerce_add_order_item_meta( $item_id, '_tax_class', '0' ); woocommerce_add_order_item_meta( $item_id, '_tax_class', '0' );
woocommerce_add_order_item_meta( $item_id, '_line_total', woocommerce_format_decimal( $fee->amount ) ); woocommerce_add_order_item_meta( $item_id, '_line_total', woocommerce_format_decimal( $fee->amount ) );
woocommerce_add_order_item_meta( $item_id, '_line_tax', woocommerce_format_decimal( $fee->tax ) ); woocommerce_add_order_item_meta( $item_id, '_line_tax', woocommerce_format_decimal( $fee->tax ) );
} }
// UPDATE USER META // UPDATE USER META
// Save billing and shipping first, also save to user meta if logged in // Save billing and shipping first, also save to user meta if logged in
if ( $this->checkout_fields['billing'] ) { if ( $this->checkout_fields['billing'] ) {
foreach ( $this->checkout_fields['billing'] as $key => $field ) { foreach ( $this->checkout_fields['billing'] as $key => $field ) {
@ -507,7 +507,7 @@ class WC_Checkout {
// Special fields // Special fields
switch ( $key ) { switch ( $key ) {
case "billing_email" : case "billing_email" :
if ( ! email_exists( $this->posted[ $key ] ) ) if ( ! email_exists( $this->posted[ $key ] ) )
wp_update_user( array ( 'ID' => $user_id, 'user_email' => $this->posted[ $key ] ) ) ; wp_update_user( array ( 'ID' => $user_id, 'user_email' => $this->posted[ $key ] ) ) ;
break; break;
case "billing_first_name" : case "billing_first_name" :
@ -541,11 +541,11 @@ class WC_Checkout {
} }
// Save any other user meta // Save any other user meta
if ( $user_id ) if ( $user_id )
do_action( 'woocommerce_checkout_update_user_meta', $user_id, $this->posted ); do_action( 'woocommerce_checkout_update_user_meta', $user_id, $this->posted );
// UPDATE ORDER META // UPDATE ORDER META
// Get better formatted shipping method (title) // Get better formatted shipping method (title)
$shipping_method = $this->posted['shipping_method']; $shipping_method = $this->posted['shipping_method'];
if ( isset( $available_methods[ $this->posted['shipping_method'] ] ) ) if ( isset( $available_methods[ $this->posted['shipping_method'] ] ) )
@ -555,15 +555,15 @@ class WC_Checkout {
$payment_method = $this->posted['payment_method']; $payment_method = $this->posted['payment_method'];
if ( isset( $available_gateways[ $this->posted['payment_method'] ] ) ) if ( isset( $available_gateways[ $this->posted['payment_method'] ] ) )
$payment_method = $available_gateways[ $this->posted['payment_method'] ]->get_title(); $payment_method = $available_gateways[ $this->posted['payment_method'] ]->get_title();
// Store tax rows // Store tax rows
foreach ( array_keys( $woocommerce->cart->taxes + $woocommerce->cart->shipping_taxes ) as $key ) { foreach ( array_keys( $woocommerce->cart->taxes + $woocommerce->cart->shipping_taxes ) as $key ) {
$item_id = woocommerce_add_order_item( $order_id, array( $item_id = woocommerce_add_order_item( $order_id, array(
'order_item_name' => $woocommerce->cart->tax->get_rate_label( $key ), 'order_item_name' => $woocommerce->cart->tax->get_rate_label( $key ),
'order_item_type' => 'tax' 'order_item_type' => 'tax'
) ); ) );
// Add line item meta // Add line item meta
if ( $item_id ) { if ( $item_id ) {
woocommerce_add_order_item_meta( $item_id, 'compound', absint( $woocommerce->cart->tax->is_compound( $key ) ? 1 : 0 ) ); woocommerce_add_order_item_meta( $item_id, 'compound', absint( $woocommerce->cart->tax->is_compound( $key ) ? 1 : 0 ) );
@ -677,10 +677,10 @@ class WC_Checkout {
} }
} catch ( Exception $e ) { } catch ( Exception $e ) {
if ( ! empty( $e ) ) if ( ! empty( $e ) )
$woocommerce->add_error( $e ); $woocommerce->add_error( $e );
} }
} // endif } // endif
@ -722,7 +722,7 @@ class WC_Checkout {
} elseif ( is_user_logged_in() ) { } elseif ( is_user_logged_in() ) {
if ( $meta = get_user_meta( get_current_user_id(), $input, true ) ) if ( $meta = get_user_meta( get_current_user_id(), $input, true ) )
return $meta; return $meta;
$current_user = wp_get_current_user(); $current_user = wp_get_current_user();

View File

@ -480,7 +480,7 @@ class WC_Countries {
asort( $this->countries ); asort( $this->countries );
if ( get_option('woocommerce_allowed_countries') !== 'specific' ) if ( get_option('woocommerce_allowed_countries') !== 'specific' )
return $this->countries; return $this->countries;
$allowed_countries = array(); $allowed_countries = array();
@ -492,17 +492,17 @@ class WC_Countries {
return $allowed_countries; return $allowed_countries;
} }
/** /**
* get_allowed_country_states function. * get_allowed_country_states function.
* *
* @access public * @access public
* @return array * @return array
*/ */
function get_allowed_country_states() { function get_allowed_country_states() {
if ( get_option('woocommerce_allowed_countries') !== 'specific' ) if ( get_option('woocommerce_allowed_countries') !== 'specific' )
return $this->states; return $this->states;
$allowed_states = array(); $allowed_states = array();
@ -510,7 +510,7 @@ class WC_Countries {
$allowed_countries_raw = get_option( 'woocommerce_specific_allowed_countries' ); $allowed_countries_raw = get_option( 'woocommerce_specific_allowed_countries' );
foreach ( $allowed_countries_raw as $country ) foreach ( $allowed_countries_raw as $country )
if ( ! empty( $this->states[ $country ] ) ) if ( ! empty( $this->states[ $country ] ) )
$allowed_states[ $country ] = $this->states[ $country ]; $allowed_states[ $country ] = $this->states[ $country ];
return $allowed_states; return $allowed_states;
@ -740,7 +740,7 @@ class WC_Countries {
$full_country = ( isset( $this->countries[ $country ] ) ) ? $this->countries[ $country ] : $country; $full_country = ( isset( $this->countries[ $country ] ) ) ? $this->countries[ $country ] : $country;
// Country is not needed if the same as base // Country is not needed if the same as base
if ( $country == $this->get_base_country() ) if ( $country == $this->get_base_country() )
$format = str_replace( '{country}', '', $format ); $format = str_replace( '{country}', '', $format );
// Handle full state name // Handle full state name
@ -769,7 +769,7 @@ class WC_Countries {
'{postcode_upper}' => strtoupper( $postcode ), '{postcode_upper}' => strtoupper( $postcode ),
'{country_upper}' => strtoupper( $full_country ), '{country_upper}' => strtoupper( $full_country ),
) ) ; ) ) ;
$replace = array_map( 'esc_html', $replace ); $replace = array_map( 'esc_html', $replace );
$formatted_address = str_replace( array_keys( $replace ), $replace, $format ); $formatted_address = str_replace( array_keys( $replace ), $replace, $format );

View File

@ -76,12 +76,12 @@ class WC_Coupon {
global $wpdb; global $wpdb;
$this->code = apply_filters( 'woocommerce_coupon_code', $code ); $this->code = apply_filters( 'woocommerce_coupon_code', $code );
// Coupon data lets developers create coupons through code // Coupon data lets developers create coupons through code
$coupon_data = apply_filters( 'woocommerce_get_shop_coupon_data', false, $code ); $coupon_data = apply_filters( 'woocommerce_get_shop_coupon_data', false, $code );
if ( $coupon_data ) { if ( $coupon_data ) {
$this->id = absint( $coupon_data['id'] ); $this->id = absint( $coupon_data['id'] );
$this->type = esc_html( $coupon_data['type'] ); $this->type = esc_html( $coupon_data['type'] );
$this->amount = esc_html( $coupon_data['amount'] ); $this->amount = esc_html( $coupon_data['amount'] );
@ -97,19 +97,19 @@ class WC_Coupon {
$this->exclude_product_categories = is_array( $coupon_data['exclude_product_categories'] ) ? $coupon_data['exclude_product_categories'] : array(); $this->exclude_product_categories = is_array( $coupon_data['exclude_product_categories'] ) ? $coupon_data['exclude_product_categories'] : array();
$this->minimum_amount = esc_html( $coupon_data['minimum_amount'] ); $this->minimum_amount = esc_html( $coupon_data['minimum_amount'] );
$this->customer_email = esc_html( $coupon_data['customer_email'] ); $this->customer_email = esc_html( $coupon_data['customer_email'] );
return true; return true;
} else { } else {
$coupon_id = $wpdb->get_var( $wpdb->prepare( apply_filters( 'woocommerce_coupon_code_query', "SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type = 'shop_coupon'" ), $this->code ) ); $coupon_id = $wpdb->get_var( $wpdb->prepare( apply_filters( 'woocommerce_coupon_code_query', "SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type = 'shop_coupon'" ), $this->code ) );
if ( $coupon_id ) if ( $coupon_id )
$coupon = get_post( $coupon_id ); $coupon = get_post( $coupon_id );
$coupon->post_title = apply_filters( 'woocommerce_coupon_code', $coupon->post_title ); $coupon->post_title = apply_filters( 'woocommerce_coupon_code', $coupon->post_title );
if ( empty( $coupon ) || $coupon->post_status !== 'publish' || $this->code !== $coupon->post_title ) if ( empty( $coupon ) || $coupon->post_status !== 'publish' || $this->code !== $coupon->post_title )
return false; return false;
$this->id = $coupon->ID; $this->id = $coupon->ID;
@ -132,7 +132,7 @@ class WC_Coupon {
'customer_email' => array() 'customer_email' => array()
); );
foreach ( $load_data as $key => $default ) foreach ( $load_data as $key => $default )
$this->$key = isset( $this->coupon_custom_fields[ $key ][0] ) && $this->coupon_custom_fields[ $key ][0] !== '' ? $this->coupon_custom_fields[ $key ][0] : $default; $this->$key = isset( $this->coupon_custom_fields[ $key ][0] ) && $this->coupon_custom_fields[ $key ][0] !== '' ? $this->coupon_custom_fields[ $key ][0] : $default;
// Alias // Alias
@ -149,7 +149,7 @@ class WC_Coupon {
return true; return true;
} }
return false; return false;
} }
@ -244,7 +244,7 @@ class WC_Coupon {
$valid_for_cart = false; $valid_for_cart = false;
if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) { if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) {
foreach( $woocommerce->cart->get_cart() as $cart_item_key => $cart_item ) { foreach( $woocommerce->cart->get_cart() as $cart_item_key => $cart_item ) {
if ( in_array( $cart_item['product_id'], $this->product_ids ) || in_array( $cart_item['variation_id'], $this->product_ids ) || in_array( $cart_item['data']->get_parent(), $this->product_ids ) ) if ( in_array( $cart_item['product_id'], $this->product_ids ) || in_array( $cart_item['variation_id'], $this->product_ids ) || in_array( $cart_item['data']->get_parent(), $this->product_ids ) )
$valid_for_cart = true; $valid_for_cart = true;
} }
@ -260,10 +260,10 @@ class WC_Coupon {
$valid_for_cart = false; $valid_for_cart = false;
if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) { if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) {
foreach( $woocommerce->cart->get_cart() as $cart_item_key => $cart_item ) { foreach( $woocommerce->cart->get_cart() as $cart_item_key => $cart_item ) {
$product_cats = wp_get_post_terms($cart_item['product_id'], 'product_cat', array("fields" => "ids")); $product_cats = wp_get_post_terms($cart_item['product_id'], 'product_cat', array("fields" => "ids"));
if ( sizeof( array_intersect( $product_cats, $this->product_categories ) ) > 0 ) if ( sizeof( array_intersect( $product_cats, $this->product_categories ) ) > 0 )
$valid_for_cart = true; $valid_for_cart = true;
} }
} }
@ -297,10 +297,10 @@ class WC_Coupon {
$valid_for_cart = true; $valid_for_cart = true;
if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) { if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) {
foreach( $woocommerce->cart->get_cart() as $cart_item_key => $cart_item ) { foreach( $woocommerce->cart->get_cart() as $cart_item_key => $cart_item ) {
$product_cats = wp_get_post_terms( $cart_item['product_id'], 'product_cat', array( "fields" => "ids" ) ); $product_cats = wp_get_post_terms( $cart_item['product_id'], 'product_cat', array( "fields" => "ids" ) );
if ( sizeof( array_intersect( $product_cats, $this->exclude_product_categories ) ) > 0 ) if ( sizeof( array_intersect( $product_cats, $this->exclude_product_categories ) ) > 0 )
$valid_for_cart = false; $valid_for_cart = false;
} }
} }

View File

@ -10,10 +10,10 @@
* @author WooThemes * @author WooThemes
*/ */
class WC_Customer { class WC_Customer {
/** Stores customer data as an array */ /** Stores customer data as an array */
protected $_data; protected $_data;
/** /**
* Constructor for the customer class loads the customer data. * Constructor for the customer class loads the customer data.
* *
@ -22,7 +22,7 @@ class WC_Customer {
*/ */
function __construct() { function __construct() {
global $woocommerce; global $woocommerce;
if ( empty( $woocommerce->session->customer ) ) { if ( empty( $woocommerce->session->customer ) ) {
$default = apply_filters( 'woocommerce_customer_default_location', get_option( 'woocommerce_default_country' ) ); $default = apply_filters( 'woocommerce_customer_default_location', get_option( 'woocommerce_default_country' ) );
@ -50,18 +50,18 @@ class WC_Customer {
'is_vat_exempt' => false, 'is_vat_exempt' => false,
'calculated_shipping' => false 'calculated_shipping' => false
); );
} else { } else {
$this->_data = $woocommerce->session->customer; $this->_data = $woocommerce->session->customer;
} }
// When leaving or ending page load, store data // When leaving or ending page load, store data
add_action( 'shutdown', array( &$this, 'save_data' ), 10 ); add_action( 'shutdown', array( &$this, 'save_data' ), 10 );
} }
/** /**
* __get function. * __get function.
* *
* @access public * @access public
* @param mixed $property * @param mixed $property
* @return mixed * @return mixed
@ -69,10 +69,10 @@ class WC_Customer {
public function __get( $property ) { public function __get( $property ) {
return isset( $this->_data[ $property ] ) ? $this->_data[ $property ] : null; return isset( $this->_data[ $property ] ) ? $this->_data[ $property ] : null;
} }
/** /**
* __set function. * __set function.
* *
* @access public * @access public
* @param mixed $property * @param mixed $property
* @param mixed $value * @param mixed $value
@ -81,10 +81,10 @@ class WC_Customer {
public function __set( $property, $value ) { public function __set( $property, $value ) {
$this->_data[ $property ] = $value; $this->_data[ $property ] = $value;
} }
/** /**
* save_data function. * save_data function.
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -156,11 +156,11 @@ class WC_Customer {
*/ */
function is_customer_outside_base() { function is_customer_outside_base() {
list( $country, $state, $postcode, $city ) = $this->get_taxable_address(); list( $country, $state, $postcode, $city ) = $this->get_taxable_address();
if ( $country ) { if ( $country ) {
$default = get_option('woocommerce_default_country'); $default = get_option('woocommerce_default_country');
if ( strstr( $default, ':' ) ) { if ( strstr( $default, ':' ) ) {
list( $default_country, $default_state ) = explode( ':', $default ); list( $default_country, $default_state ) = explode( ':', $default );
} else { } else {
@ -220,11 +220,11 @@ class WC_Customer {
$validation = $woocommerce->validation(); $validation = $woocommerce->validation();
if (isset($this->_data['postcode']) && $this->_data['postcode'] !== false) return $validation->format_postcode( $this->_data['postcode'], $this->get_country()); if (isset($this->_data['postcode']) && $this->_data['postcode'] !== false) return $validation->format_postcode( $this->_data['postcode'], $this->get_country());
} }
/** /**
* Get the city from the current session. * Get the city from the current session.
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -234,17 +234,17 @@ class WC_Customer {
/** /**
* Gets the address from the current session. * Gets the address from the current session.
* *
* @access public * @access public
* @return void * @return void
*/ */
function get_address() { function get_address() {
if ( isset( $this->_data['address'] ) ) return $this->_data['address']; if ( isset( $this->_data['address'] ) ) return $this->_data['address'];
} }
/** /**
* Gets the address_2 from the current session. * Gets the address_2 from the current session.
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -285,41 +285,41 @@ class WC_Customer {
$validation = $woocommerce->validation(); $validation = $woocommerce->validation();
if (isset($this->_data['shipping_postcode'])) return $validation->format_postcode( $this->_data['shipping_postcode'], $this->get_shipping_country()); if (isset($this->_data['shipping_postcode'])) return $validation->format_postcode( $this->_data['shipping_postcode'], $this->get_shipping_country());
} }
/** /**
* Gets the city from the current session. * Gets the city from the current session.
* *
* @access public * @access public
* @return void * @return void
*/ */
function get_shipping_city() { function get_shipping_city() {
if ( isset( $this->_data['shipping_city'] ) ) return $this->_data['shipping_city']; if ( isset( $this->_data['shipping_city'] ) ) return $this->_data['shipping_city'];
} }
/** /**
* Gets the address from the current session. * Gets the address from the current session.
* *
* @access public * @access public
* @return void * @return void
*/ */
function get_shipping_address() { function get_shipping_address() {
if ( isset( $this->_data['shipping_address'] ) ) return $this->_data['shipping_address']; if ( isset( $this->_data['shipping_address'] ) ) return $this->_data['shipping_address'];
} }
/** /**
* Gets the address_2 from the current session. * Gets the address_2 from the current session.
* *
* @access public * @access public
* @return void * @return void
*/ */
function get_shipping_address_2() { function get_shipping_address_2() {
if ( isset( $this->_data['shipping_address_2'] ) ) return $this->_data['shipping_address_2']; if ( isset( $this->_data['shipping_address_2'] ) ) return $this->_data['shipping_address_2'];
} }
/** /**
* get_taxable_address function. * get_taxable_address function.
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -338,10 +338,10 @@ class WC_Customer {
return apply_filters( 'woocommerce_customer_taxable_address', array( $country, $state, $postcode, $city ) ); return apply_filters( 'woocommerce_customer_taxable_address', array( $country, $state, $postcode, $city ) );
} }
/** /**
* Sets session data for the location. * Sets session data for the location.
* *
* @access public * @access public
* @param mixed $country * @param mixed $country
* @param mixed $state * @param mixed $state
@ -433,14 +433,14 @@ class WC_Customer {
* @param mixed $country * @param mixed $country
* @param string $state (default: '') * @param string $state (default: '')
* @param string $postcode (default: '') * @param string $postcode (default: '')
* @param string $city (default: '') * @param string $city (default: '')
* @return void * @return void
*/ */
function set_shipping_location( $country, $state = '', $postcode = '', $city = '' ) { function set_shipping_location( $country, $state = '', $postcode = '', $city = '' ) {
$this->_data['shipping_country'] = $country; $this->_data['shipping_country'] = $country;
$this->_data['shipping_state'] = $state; $this->_data['shipping_state'] = $state;
$this->_data['shipping_postcode'] = $postcode; $this->_data['shipping_postcode'] = $postcode;
$this->_data['shipping_city'] = $city; $this->_data['shipping_city'] = $city;
} }
@ -528,7 +528,7 @@ class WC_Customer {
/** /**
* calculated_shipping function. * calculated_shipping function.
* *
* @access public * @access public
* @param mixed $calculated * @param mixed $calculated
* @return void * @return void
@ -536,7 +536,7 @@ class WC_Customer {
function calculated_shipping( $calculated = true ) { function calculated_shipping( $calculated = true ) {
$this->_data['calculated_shipping'] = $calculated; $this->_data['calculated_shipping'] = $calculated;
} }
/** /**
* Gets a user's downloadable products if they are logged in. * Gets a user's downloadable products if they are logged in.
@ -554,7 +554,7 @@ class WC_Customer {
$user_info = get_userdata( get_current_user_id() ); $user_info = get_userdata( get_current_user_id() );
$results = $wpdb->get_results( $wpdb->prepare("SELECT * FROM ".$wpdb->prefix."woocommerce_downloadable_product_permissions WHERE user_id = '%s' ORDER BY order_id, product_id, download_id", get_current_user_id()) ); $results = $wpdb->get_results( $wpdb->prepare("SELECT * FROM ".$wpdb->prefix."woocommerce_downloadable_product_permissions WHERE user_id = '%s' ORDER BY order_id, product_id, download_id", get_current_user_id()) );
$_product = null; $_product = null;
$order = null; $order = null;
$file_number = 0; $file_number = 0;
@ -578,7 +578,7 @@ class WC_Customer {
endif; endif;
if ( ! $_product->exists() ) continue; if ( ! $_product->exists() ) continue;
if ( ! $_product->has_file( $result->download_id ) ) continue; if ( ! $_product->has_file( $result->download_id ) ) continue;
// Download name will be 'Product Name' for products with a single downloadable file, and 'Product Name - File X' for products with multiple files // Download name will be 'Product Name' for products with a single downloadable file, and 'Product Name - File X' for products with multiple files

View File

@ -86,11 +86,11 @@ class WC_Logger {
if ( $this->open( $handle ) ) if ( $this->open( $handle ) )
ftruncate( $this->handles[ $handle ], 0 ); ftruncate( $this->handles[ $handle ], 0 );
} }
/** /**
* file_name function. * file_name function.
* *
* @access private * @access private
* @param mixed $handle * @param mixed $handle
* @return void * @return void

View File

@ -386,23 +386,23 @@ class WC_Order {
/** /**
* Return an array of items/products within this order. * Return an array of items/products within this order.
* *
* @access public * @access public
* @param string $type Types of line items to get (array or string) * @param string $type Types of line items to get (array or string)
* @return void * @return void
*/ */
function get_items( $type = '' ) { function get_items( $type = '' ) {
global $wpdb, $woocommerce; global $wpdb, $woocommerce;
if ( empty( $type ) ) if ( empty( $type ) )
$type = array( 'line_item' ); $type = array( 'line_item' );
if ( ! is_array( $type ) ) { if ( ! is_array( $type ) ) {
$type = array( $type ); $type = array( $type );
} }
$type = array_map( 'esc_attr', $type ); $type = array_map( 'esc_attr', $type );
$line_items = $wpdb->get_results( $wpdb->prepare( " $line_items = $wpdb->get_results( $wpdb->prepare( "
SELECT order_item_id, order_item_name, order_item_type SELECT order_item_id, order_item_name, order_item_type
FROM {$wpdb->prefix}woocommerce_order_items FROM {$wpdb->prefix}woocommerce_order_items
@ -410,16 +410,16 @@ class WC_Order {
AND order_item_type IN ( '" . implode( "','", $type ) . "' ) AND order_item_type IN ( '" . implode( "','", $type ) . "' )
ORDER BY order_item_id ORDER BY order_item_id
", $this->id ) ); ", $this->id ) );
$items = array(); $items = array();
foreach ( $line_items as $item ) { foreach ( $line_items as $item ) {
// Place line item into array to return // Place line item into array to return
$items[ $item->order_item_id ]['name'] = $item->order_item_name; $items[ $item->order_item_id ]['name'] = $item->order_item_name;
$items[ $item->order_item_id ]['type'] = $item->order_item_type; $items[ $item->order_item_id ]['type'] = $item->order_item_type;
$items[ $item->order_item_id ]['item_meta'] = $this->get_item_meta( $item->order_item_id ); $items[ $item->order_item_id ]['item_meta'] = $this->get_item_meta( $item->order_item_id );
// Put meta into item array // Put meta into item array
foreach( $items[ $item->order_item_id ]['item_meta'] as $name => $value ) { foreach( $items[ $item->order_item_id ]['item_meta'] as $name => $value ) {
$key = substr( $name, 0, 1 ) == '_' ? substr( $name, 1 ) : $name; $key = substr( $name, 0, 1 ) == '_' ? substr( $name, 1 ) : $name;
@ -438,10 +438,10 @@ class WC_Order {
function get_fees() { function get_fees() {
return $this->get_items( 'fee' ); return $this->get_items( 'fee' );
} }
/** /**
* Return an array of taxes within this order. * Return an array of taxes within this order.
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -451,21 +451,21 @@ class WC_Order {
/** /**
* has_meta function for order items. * has_meta function for order items.
* *
* @access public * @access public
* @return array of meta data * @return array of meta data
*/ */
function has_meta( $order_item_id ) { function has_meta( $order_item_id ) {
global $wpdb; global $wpdb;
return $wpdb->get_results( $wpdb->prepare("SELECT meta_key, meta_value, meta_id, order_item_id return $wpdb->get_results( $wpdb->prepare("SELECT meta_key, meta_value, meta_id, order_item_id
FROM {$wpdb->prefix}woocommerce_order_itemmeta WHERE order_item_id = %d FROM {$wpdb->prefix}woocommerce_order_itemmeta WHERE order_item_id = %d
ORDER BY meta_key,meta_id", absint( $order_item_id ) ), ARRAY_A ); ORDER BY meta_key,meta_id", absint( $order_item_id ) ), ARRAY_A );
} }
/** /**
* Get order item meta. * Get order item meta.
* *
* @access public * @access public
* @param mixed $item_id * @param mixed $item_id
* @param string $key (default: '') * @param string $key (default: '')
@ -555,11 +555,11 @@ class WC_Order {
function get_total() { function get_total() {
return apply_filters( 'woocommerce_order_amount_total', number_format( (double) $this->order_total, 2, '.', '' ) ); return apply_filters( 'woocommerce_order_amount_total', number_format( (double) $this->order_total, 2, '.', '' ) );
} }
/** /**
* get_order_total function. Alias for get_total() * get_order_total function. Alias for get_total()
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -885,19 +885,19 @@ class WC_Order {
'label' => __( 'Shipping:', 'woocommerce' ), 'label' => __( 'Shipping:', 'woocommerce' ),
'value' => $this->get_shipping_to_display() 'value' => $this->get_shipping_to_display()
); );
if ( $fees = $this->get_fees() ) if ( $fees = $this->get_fees() )
foreach( $fees as $id => $fee ) { foreach( $fees as $id => $fee ) {
if ( $this->display_cart_ex_tax || ! $this->prices_include_tax ) { if ( $this->display_cart_ex_tax || ! $this->prices_include_tax ) {
$total_rows[ 'fee_' . $id ] = array( $total_rows[ 'fee_' . $id ] = array(
'label' => $fee['name'], 'label' => $fee['name'],
'value' => woocommerce_price( $fee['line_total'] ) 'value' => woocommerce_price( $fee['line_total'] )
); );
} else { } else {
$total_rows[ 'fee_' . $id ] = array( $total_rows[ 'fee_' . $id ] = array(
'label' => $fee['name'], 'label' => $fee['name'],
'value' => woocommerce_price( $fee['line_total'] + $fee['line_tax'] ) 'value' => woocommerce_price( $fee['line_total'] + $fee['line_tax'] )
@ -905,31 +905,31 @@ class WC_Order {
} }
} }
// Tax for tax exclusive prices // Tax for tax exclusive prices
if ( $this->display_cart_ex_tax || ! $this->prices_include_tax ) { if ( $this->display_cart_ex_tax || ! $this->prices_include_tax ) {
if ( $this->get_total_tax() > 0 ) { if ( $this->get_total_tax() > 0 ) {
if ( sizeof( $this->get_taxes() ) > 0 ) { if ( sizeof( $this->get_taxes() ) > 0 ) {
$has_compound_tax = false; $has_compound_tax = false;
foreach ( $this->get_taxes() as $tax ) { foreach ( $this->get_taxes() as $tax ) {
if ( $tax[ 'compound' ] ) { if ( $tax[ 'compound' ] ) {
$has_compound_tax = true; $has_compound_tax = true;
continue; continue;
} }
if ( ( $tax[ 'tax_amount' ] + $tax[ 'shipping_tax_amount' ] ) == 0 ) if ( ( $tax[ 'tax_amount' ] + $tax[ 'shipping_tax_amount' ] ) == 0 )
continue; continue;
$total_rows[ sanitize_title( $tax[ 'name' ] ) ] = array( $total_rows[ sanitize_title( $tax[ 'name' ] ) ] = array(
'label' => $tax[ 'name' ] . ':', 'label' => $tax[ 'name' ] . ':',
'value' => woocommerce_price( ( $tax[ 'tax_amount' ] + $tax[ 'shipping_tax_amount' ] ) ) 'value' => woocommerce_price( ( $tax[ 'tax_amount' ] + $tax[ 'shipping_tax_amount' ] ) )
); );
} }
if ( $has_compound_tax ) { if ( $has_compound_tax ) {
if ( $subtotal = $this->get_subtotal_to_display( true ) ) { if ( $subtotal = $this->get_subtotal_to_display( true ) ) {
$total_rows['subtotal'] = array( $total_rows['subtotal'] = array(
@ -938,14 +938,14 @@ class WC_Order {
); );
} }
} }
foreach ( $this->get_taxes() as $tax ) { foreach ( $this->get_taxes() as $tax ) {
if ( ! $tax[ 'compound' ] ) if ( ! $tax[ 'compound' ] )
continue; continue;
if ( ( $tax[ 'tax_amount' ] + $tax[ 'shipping_tax_amount' ] ) == 0 ) if ( ( $tax[ 'tax_amount' ] + $tax[ 'shipping_tax_amount' ] ) == 0 )
continue; continue;
$total_rows[ sanitize_title( $tax[ 'name' ] ) ] = array( $total_rows[ sanitize_title( $tax[ 'name' ] ) ] = array(
'label' => $tax[ 'name' ] . ':', 'label' => $tax[ 'name' ] . ':',
'value' => woocommerce_price( ( $tax[ 'tax_amount' ] + $tax[ 'shipping_tax_amount' ] ) ) 'value' => woocommerce_price( ( $tax[ 'tax_amount' ] + $tax[ 'shipping_tax_amount' ] ) )
@ -957,14 +957,14 @@ class WC_Order {
'value' => woocommerce_price( $this->get_total_tax() ) 'value' => woocommerce_price( $this->get_total_tax() )
); );
} }
} elseif ( get_option( 'woocommerce_display_cart_taxes_if_zero' ) == 'yes' ) { } elseif ( get_option( 'woocommerce_display_cart_taxes_if_zero' ) == 'yes' ) {
$total_rows['tax'] = array( $total_rows['tax'] = array(
'label' => $woocommerce->countries->tax_or_vat(), 'label' => $woocommerce->countries->tax_or_vat(),
'value' => _x( 'N/A', 'Relating to tax', 'woocommerce' ) 'value' => _x( 'N/A', 'Relating to tax', 'woocommerce' )
); );
} }
} }
if ( $this->get_order_discount() > 0 ) if ( $this->get_order_discount() > 0 )
@ -977,37 +977,37 @@ class WC_Order {
'label' => __( 'Order Total:', 'woocommerce' ), 'label' => __( 'Order Total:', 'woocommerce' ),
'value' => $this->get_formatted_order_total() 'value' => $this->get_formatted_order_total()
); );
// Tax for inclusive prices // Tax for inclusive prices
if ( ! $this->display_cart_ex_tax && $this->prices_include_tax ) { if ( ! $this->display_cart_ex_tax && $this->prices_include_tax ) {
$tax_string_array = array(); $tax_string_array = array();
if ( $this->get_total_tax() > 0 ) { if ( $this->get_total_tax() > 0 ) {
if ( sizeof( $this->get_taxes() ) > 0 ) { if ( sizeof( $this->get_taxes() ) > 0 ) {
foreach ( $this->get_taxes() as $tax ) { foreach ( $this->get_taxes() as $tax ) {
if ( ( $tax[ 'tax_amount' ] + $tax[ 'shipping_tax_amount' ] ) == 0 ) if ( ( $tax[ 'tax_amount' ] + $tax[ 'shipping_tax_amount' ] ) == 0 )
continue; continue;
$tax_string_array[] = sprintf( '%s %s', woocommerce_price( ( $tax[ 'tax_amount' ] + $tax[ 'shipping_tax_amount' ] ) ), $tax[ 'name' ] ); $tax_string_array[] = sprintf( '%s %s', woocommerce_price( ( $tax[ 'tax_amount' ] + $tax[ 'shipping_tax_amount' ] ) ), $tax[ 'name' ] );
} }
} else { } else {
$tax_string_array[] = sprintf( '%s %s', woocommerce_price( $this->get_total_tax() ), $woocommerce->countries->tax_or_vat() ); $tax_string_array[] = sprintf( '%s %s', woocommerce_price( $this->get_total_tax() ), $woocommerce->countries->tax_or_vat() );
} }
} elseif ( get_option( 'woocommerce_display_cart_taxes_if_zero' ) == 'yes' ) { } elseif ( get_option( 'woocommerce_display_cart_taxes_if_zero' ) == 'yes' ) {
$tax_string_array[] = sprintf( '%s %s', woocommerce_price( 0 ), $woocommerce->countries->tax_or_vat() ); $tax_string_array[] = sprintf( '%s %s', woocommerce_price( 0 ), $woocommerce->countries->tax_or_vat() );
} }
$total_rows['order_total']['value'] .= ' ' . sprintf( __( '(Includes %s)', 'woocommerce' ), implode( ', ', $tax_string_array ) ); $total_rows['order_total']['value'] .= ' ' . sprintf( __( '(Includes %s)', 'woocommerce' ), implode( ', ', $tax_string_array ) );
} }
return apply_filters( 'woocommerce_get_order_item_totals', $total_rows, $this ); return apply_filters( 'woocommerce_get_order_item_totals', $total_rows, $this );
@ -1029,7 +1029,7 @@ class WC_Order {
function email_order_items_table( $show_download_links = false, $show_sku = false, $show_purchase_note = false, $show_image = false, $image_size = array( 32, 32 ), $plain_text = false ) { function email_order_items_table( $show_download_links = false, $show_sku = false, $show_purchase_note = false, $show_image = false, $image_size = array( 32, 32 ), $plain_text = false ) {
ob_start(); ob_start();
$template = $plain_text ? 'emails/plain/email-order-items.php' : 'emails/email-order-items.php'; $template = $plain_text ? 'emails/plain/email-order-items.php' : 'emails/email-order-items.php';
woocommerce_get_template( $template, array( woocommerce_get_template( $template, array(
@ -1049,7 +1049,7 @@ class WC_Order {
/** /**
* Checks if product download is permitted * Checks if product download is permitted
* *
* @access public * @access public
* @return bool * @return bool
*/ */
@ -1186,12 +1186,12 @@ class WC_Order {
*/ */
function update_status( $new_status_slug, $note = '' ) { function update_status( $new_status_slug, $note = '' ) {
if ( $note ) if ( $note )
$note .= ' '; $note .= ' ';
$old_status = get_term_by( 'slug', sanitize_title( $this->status ), 'shop_order_status' ); $old_status = get_term_by( 'slug', sanitize_title( $this->status ), 'shop_order_status' );
$new_status = get_term_by( 'slug', sanitize_title( $new_status_slug ), 'shop_order_status' ); $new_status = get_term_by( 'slug', sanitize_title( $new_status_slug ), 'shop_order_status' );
if ( $new_status ) { if ( $new_status ) {
wp_set_object_terms( $this->id, array( $new_status->slug ), 'shop_order_status', false ); wp_set_object_terms( $this->id, array( $new_status->slug ), 'shop_order_status', false );
@ -1202,7 +1202,7 @@ class WC_Order {
do_action( 'woocommerce_order_status_' . $new_status->slug, $this->id ); do_action( 'woocommerce_order_status_' . $new_status->slug, $this->id );
do_action( 'woocommerce_order_status_' . $this->status . '_to_' . $new_status->slug, $this->id ); do_action( 'woocommerce_order_status_' . $this->status . '_to_' . $new_status->slug, $this->id );
do_action( 'woocommerce_order_status_changed', $this->id, $this->status, $new_status->slug ); do_action( 'woocommerce_order_status_changed', $this->id, $this->status, $new_status->slug );
$this->add_order_note( $note . sprintf( __( 'Order status changed from %s to %s.', 'woocommerce' ), __( $old_status->name, 'woocommerce' ), __( $new_status->name, 'woocommerce' ) ) ); $this->add_order_note( $note . sprintf( __( 'Order status changed from %s to %s.', 'woocommerce' ), __( $old_status->name, 'woocommerce' ), __( $new_status->name, 'woocommerce' ) ) );
// Record the completed date of the order // Record the completed date of the order
@ -1239,7 +1239,7 @@ class WC_Order {
*/ */
function cancel_order( $note = '' ) { function cancel_order( $note = '' ) {
global $woocommerce; global $woocommerce;
unset( $woocommerce->session->order_awaiting_payment ); unset( $woocommerce->session->order_awaiting_payment );
$this->update_status('cancelled', $note); $this->update_status('cancelled', $note);
@ -1261,7 +1261,7 @@ class WC_Order {
*/ */
function payment_complete() { function payment_complete() {
global $woocommerce; global $woocommerce;
unset( $woocommerce->session->order_awaiting_payment ); unset( $woocommerce->session->order_awaiting_payment );
if ( $this->status == 'on-hold' || $this->status == 'pending' || $this->status == 'failed' ) { if ( $this->status == 'on-hold' || $this->status == 'pending' || $this->status == 'failed' ) {
@ -1269,9 +1269,9 @@ class WC_Order {
$order_needs_processing = true; $order_needs_processing = true;
if ( sizeof( $this->get_items() ) > 0 ) { if ( sizeof( $this->get_items() ) > 0 ) {
foreach( $this->get_items() as $item ) { foreach( $this->get_items() as $item ) {
if ( $item['product_id'] > 0 ) { if ( $item['product_id'] > 0 ) {
$_product = $this->get_product_from_item( $item ); $_product = $this->get_product_from_item( $item );
@ -1545,16 +1545,16 @@ class WC_Order_Item_Meta {
global $woocommerce; global $woocommerce;
if ( ! empty( $this->meta ) ) { if ( ! empty( $this->meta ) ) {
$output = $flat ? '' : '<dl class="variation">'; $output = $flat ? '' : '<dl class="variation">';
$meta_list = array(); $meta_list = array();
foreach ( $this->meta as $meta_key => $meta_value ) { foreach ( $this->meta as $meta_key => $meta_value ) {
if ( ! $meta_value || ( ! empty( $hideprefix ) && substr( $meta_key, 0, 1 ) == $hideprefix ) ) if ( ! $meta_value || ( ! empty( $hideprefix ) && substr( $meta_key, 0, 1 ) == $hideprefix ) )
continue; continue;
// Get first value // Get first value
$meta_value = $meta_value[0]; $meta_value = $meta_value[0];
@ -1579,12 +1579,12 @@ class WC_Order_Item_Meta {
else else
$output .= implode( '', $meta_list ); $output .= implode( '', $meta_list );
if ( ! $flat ) if ( ! $flat )
$output .= '</dl>'; $output .= '</dl>';
if ( $return ) if ( $return )
return $output; return $output;
else else
echo $output; echo $output;
} }
} }

View File

@ -15,7 +15,7 @@ class WC_Product_External extends WC_Product {
/** /**
* __construct function. * __construct function.
* *
* @access public * @access public
* @param mixed $product * @param mixed $product
* @param array $args Contains arguments to set up this product * @param array $args Contains arguments to set up this product
@ -23,10 +23,10 @@ class WC_Product_External extends WC_Product {
function __construct( $product, $args ) { function __construct( $product, $args ) {
parent::__construct( $product ); parent::__construct( $product );
$this->product_type = 'external'; $this->product_type = 'external';
$this->product_custom_fields = get_post_custom( $this->id ); $this->product_custom_fields = get_post_custom( $this->id );
// Load data from custom fields // Load data from custom fields
$this->load_product_data( array( $this->load_product_data( array(
'sku' => '', 'sku' => '',
@ -52,7 +52,7 @@ class WC_Product_External extends WC_Product {
'sale_price_dates_to' => '', 'sale_price_dates_to' => '',
'featured' => 'no' 'featured' => 'no'
) ); ) );
$this->check_sale_price(); $this->check_sale_price();
} }

View File

@ -17,13 +17,13 @@ class WC_Product_Factory {
public function get_product( $the_product = false, $args = array() ) { public function get_product( $the_product = false, $args = array() ) {
global $post; global $post;
if ( false === $the_product ) { if ( false === $the_product ) {
$the_product = $post; $the_product = $post;
} elseif ( is_numeric( $the_product ) ) { } elseif ( is_numeric( $the_product ) ) {
$the_product = get_post( $the_product ); $the_product = get_post( $the_product );
} }
$product_id = absint( $the_product->ID ); $product_id = absint( $the_product->ID );
$post_type = $the_product->post_type; $post_type = $the_product->post_type;
@ -33,10 +33,10 @@ class WC_Product_Factory {
$terms = get_the_terms( $product_id, 'product_type' ); $terms = get_the_terms( $product_id, 'product_type' );
$product_type = ! empty( $terms ) && isset( current( $terms )->name ) ? sanitize_title( current( $terms )->name ) : 'simple'; $product_type = ! empty( $terms ) && isset( current( $terms )->name ) ? sanitize_title( current( $terms )->name ) : 'simple';
} }
// Filter classname so that the class can be overridden if extended. // Filter classname so that the class can be overridden if extended.
$classname = apply_filters( 'woocommerce_product_class', 'WC_Product_' . ucfirst($product_type), $product_type, $post_type, $product_id ); $classname = apply_filters( 'woocommerce_product_class', 'WC_Product_' . ucfirst($product_type), $product_type, $post_type, $product_id );
if ( class_exists( $classname ) ) { if ( class_exists( $classname ) ) {
return new $classname( $the_product, $args ); return new $classname( $the_product, $args );
} else { } else {

View File

@ -18,18 +18,18 @@ class WC_Product_Grouped extends WC_Product {
/** @var string The product's total stock, including that of its children. */ /** @var string The product's total stock, including that of its children. */
var $total_stock; var $total_stock;
/** /**
* __construct function. * __construct function.
* *
* @access public * @access public
* @param mixed $product * @param mixed $product
* @param array $args Contains arguments to set up this product * @param array $args Contains arguments to set up this product
*/ */
function __construct( $product, $args ) { function __construct( $product, $args ) {
parent::__construct( $product ); parent::__construct( $product );
$this->product_type = 'grouped'; $this->product_type = 'grouped';
$this->product_custom_fields = get_post_custom( $this->id ); $this->product_custom_fields = get_post_custom( $this->id );
@ -58,7 +58,7 @@ class WC_Product_Grouped extends WC_Product {
'sale_price_dates_to' => '', 'sale_price_dates_to' => '',
'featured' => 'no' 'featured' => 'no'
) ); ) );
$this->check_sale_price(); $this->check_sale_price();
} }

View File

@ -15,7 +15,7 @@ class WC_Product_Simple extends WC_Product {
/** /**
* __construct function. * __construct function.
* *
* @access public * @access public
* @param mixed $product * @param mixed $product
* @param array $args Contains arguments to set up this product * @param array $args Contains arguments to set up this product
@ -23,10 +23,10 @@ class WC_Product_Simple extends WC_Product {
function __construct( $product, $args ) { function __construct( $product, $args ) {
parent::__construct( $product ); parent::__construct( $product );
$this->product_type = 'simple'; $this->product_type = 'simple';
$this->product_custom_fields = get_post_custom( $this->id ); $this->product_custom_fields = get_post_custom( $this->id );
// Load data from custom fields // Load data from custom fields
$this->load_product_data( array( $this->load_product_data( array(
'sku' => '', 'sku' => '',
@ -52,7 +52,7 @@ class WC_Product_Simple extends WC_Product {
'sale_price_dates_to' => '', 'sale_price_dates_to' => '',
'featured' => 'no' 'featured' => 'no'
) ); ) );
$this->check_sale_price(); $this->check_sale_price();
} }
} }

View File

@ -12,13 +12,13 @@
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class WC_Product_Variable extends WC_Product { class WC_Product_Variable extends WC_Product {
/** @var array Array of child products/posts/variations. */ /** @var array Array of child products/posts/variations. */
var $children; var $children;
/** @var string The product's total stock, including that of its children. */ /** @var string The product's total stock, including that of its children. */
var $total_stock; var $total_stock;
/** @var string Used for variation prices. */ /** @var string Used for variation prices. */
var $min_variation_price; var $min_variation_price;
@ -36,10 +36,10 @@ class WC_Product_Variable extends WC_Product {
/** @var string Used for variation prices. */ /** @var string Used for variation prices. */
var $max_variation_sale_price; var $max_variation_sale_price;
/** /**
* __construct function. * __construct function.
* *
* @access public * @access public
* @param mixed $product * @param mixed $product
* @param array $args Contains arguments to set up this product * @param array $args Contains arguments to set up this product
@ -47,7 +47,7 @@ class WC_Product_Variable extends WC_Product {
function __construct( $product, $args ) { function __construct( $product, $args ) {
parent::__construct( $product ); parent::__construct( $product );
$this->product_type = 'variable'; $this->product_type = 'variable';
$this->product_custom_fields = get_post_custom( $this->id ); $this->product_custom_fields = get_post_custom( $this->id );
@ -82,7 +82,7 @@ class WC_Product_Variable extends WC_Product {
'min_variation_sale_price' => '', 'min_variation_sale_price' => '',
'max_variation_sale_price' => '', 'max_variation_sale_price' => '',
) ); ) );
$this->check_sale_price(); $this->check_sale_price();
} }
@ -172,8 +172,8 @@ class WC_Product_Variable extends WC_Product {
return apply_filters( 'woocommerce_stock_amount', $this->stock ); return apply_filters( 'woocommerce_stock_amount', $this->stock );
endif; endif;
} }
/** /**
* Return the products children posts. * Return the products children posts.
* *
@ -484,26 +484,26 @@ class WC_Product_Variable extends WC_Product {
$child_price = get_post_meta( $child, '_price', true ); $child_price = get_post_meta( $child, '_price', true );
$child_regular_price = get_post_meta( $child, '_regular_price', true ); $child_regular_price = get_post_meta( $child, '_regular_price', true );
$child_sale_price = get_post_meta( $child, '_sale_price', true ); $child_sale_price = get_post_meta( $child, '_sale_price', true );
// Regular prices // Regular prices
if ( ! is_numeric( $this->min_variation_regular_price ) || $child_regular_price < $this->min_variation_regular_price ) if ( ! is_numeric( $this->min_variation_regular_price ) || $child_regular_price < $this->min_variation_regular_price )
$this->min_variation_regular_price = $child_regular_price; $this->min_variation_regular_price = $child_regular_price;
if ( ! is_numeric( $this->max_variation_regular_price ) || $child_regular_price > $this->max_variation_regular_price ) if ( ! is_numeric( $this->max_variation_regular_price ) || $child_regular_price > $this->max_variation_regular_price )
$this->max_variation_regular_price = $child_regular_price; $this->max_variation_regular_price = $child_regular_price;
// Sale prices // Sale prices
if ( $child_price == $child_sale_price ) { if ( $child_price == $child_sale_price ) {
if ( $child_sale_price !== '' && ( ! is_numeric( $this->min_variation_sale_price ) || $child_sale_price < $this->min_variation_sale_price ) ) if ( $child_sale_price !== '' && ( ! is_numeric( $this->min_variation_sale_price ) || $child_sale_price < $this->min_variation_sale_price ) )
$this->min_variation_sale_price = $child_sale_price; $this->min_variation_sale_price = $child_sale_price;
if ( $child_sale_price !== '' && ( ! is_numeric( $this->max_variation_sale_price ) || $child_sale_price > $this->max_variation_sale_price ) ) if ( $child_sale_price !== '' && ( ! is_numeric( $this->max_variation_sale_price ) || $child_sale_price > $this->max_variation_sale_price ) )
$this->max_variation_sale_price = $child_sale_price; $this->max_variation_sale_price = $child_sale_price;
} }
} }
$this->min_variation_price = $this->min_variation_sale_price === '' || $this->min_variation_regular_price < $this->min_variation_sale_price ? $this->min_variation_regular_price : $this->min_variation_sale_price; $this->min_variation_price = $this->min_variation_sale_price === '' || $this->min_variation_regular_price < $this->min_variation_sale_price ? $this->min_variation_regular_price : $this->min_variation_sale_price;
$this->max_variation_price = $this->max_variation_sale_price === '' || $this->max_variation_regular_price > $this->max_variation_sale_price ? $this->max_variation_regular_price : $this->max_variation_sale_price; $this->max_variation_price = $this->max_variation_sale_price === '' || $this->max_variation_regular_price > $this->max_variation_sale_price ? $this->max_variation_regular_price : $this->max_variation_sale_price;
} }

View File

@ -34,7 +34,7 @@ class WC_Product_Variation extends WC_Product {
/** @var bool True if the variation has a price. */ /** @var bool True if the variation has a price. */
var $variation_has_price; var $variation_has_price;
/** @var bool True if the variation has a regular price. */ /** @var bool True if the variation has a regular price. */
var $variation_has_regular_price; var $variation_has_regular_price;
@ -148,7 +148,7 @@ class WC_Product_Variation extends WC_Product {
$this->variation_has_height = true; $this->variation_has_height = true;
$this->height = $product_custom_fields['_height'][0]; $this->height = $product_custom_fields['_height'][0];
} }
if ( isset( $product_custom_fields['_downloadable'][0] ) && $product_custom_fields['_downloadable'][0] == 'yes' ) { if ( isset( $product_custom_fields['_downloadable'][0] ) && $product_custom_fields['_downloadable'][0] == 'yes' ) {
$this->downloadable = 'yes'; $this->downloadable = 'yes';
} else { } else {
@ -165,42 +165,42 @@ class WC_Product_Variation extends WC_Product {
$this->variation_has_tax_class = true; $this->variation_has_tax_class = true;
$this->tax_class = $product_custom_fields['_tax_class'][0]; $this->tax_class = $product_custom_fields['_tax_class'][0];
} }
if ( isset( $product_custom_fields['_price'][0] ) && $product_custom_fields['_price'][0] !== '' ) { if ( isset( $product_custom_fields['_price'][0] ) && $product_custom_fields['_price'][0] !== '' ) {
$this->variation_has_price = true; $this->variation_has_price = true;
$this->price = $product_custom_fields['_price'][0]; $this->price = $product_custom_fields['_price'][0];
} }
if ( isset( $product_custom_fields['_regular_price'][0] ) && $product_custom_fields['_regular_price'][0] !== '' ) { if ( isset( $product_custom_fields['_regular_price'][0] ) && $product_custom_fields['_regular_price'][0] !== '' ) {
$this->variation_has_regular_price = true; $this->variation_has_regular_price = true;
$this->regular_price = $product_custom_fields['_regular_price'][0]; $this->regular_price = $product_custom_fields['_regular_price'][0];
} }
if ( isset( $product_custom_fields['_sale_price'][0] ) && $product_custom_fields['_sale_price'][0] !== '' ) { if ( isset( $product_custom_fields['_sale_price'][0] ) && $product_custom_fields['_sale_price'][0] !== '' ) {
$this->variation_has_sale_price = true; $this->variation_has_sale_price = true;
$this->sale_price = $product_custom_fields['_sale_price'][0]; $this->sale_price = $product_custom_fields['_sale_price'][0];
} }
// Backwards compat for prices // Backwards compat for prices
if ( $this->variation_has_price && ! $this->variation_has_regular_price ) { if ( $this->variation_has_price && ! $this->variation_has_regular_price ) {
update_post_meta( $this->variation_id, '_regular_price', $this->price ); update_post_meta( $this->variation_id, '_regular_price', $this->price );
$this->variation_has_regular_price = true; $this->variation_has_regular_price = true;
$this->regular_price = $this->price; $this->regular_price = $this->price;
if ( $this->variation_has_sale_price && $this->sale_price < $this->regular_price ) { if ( $this->variation_has_sale_price && $this->sale_price < $this->regular_price ) {
update_post_meta( $this->variation_id, '_price', $this->sale_price ); update_post_meta( $this->variation_id, '_price', $this->sale_price );
$this->price = $this->sale_price; $this->price = $this->sale_price;
} }
} }
if ( isset( $product_custom_fields['_sale_price_dates_from'][0] ) ) if ( isset( $product_custom_fields['_sale_price_dates_from'][0] ) )
$this->sale_price_dates_from = $product_custom_fields['_sale_price_dates_from'][0]; $this->sale_price_dates_from = $product_custom_fields['_sale_price_dates_from'][0];
if ( isset( $product_custom_fields['_sale_price_dates_to'][0] ) ) if ( isset( $product_custom_fields['_sale_price_dates_to'][0] ) )
$this->sale_price_dates_from = $product_custom_fields['_sale_price_dates_to'][0]; $this->sale_price_dates_from = $product_custom_fields['_sale_price_dates_to'][0];
$this->total_stock = $this->stock; $this->total_stock = $this->stock;
// Check sale dates // Check sale dates
$this->check_sale_price(); $this->check_sale_price();
} }
@ -384,7 +384,7 @@ class WC_Product_Variation extends WC_Product {
function get_shipping_class() { function get_shipping_class() {
if ( ! $this->variation_shipping_class ) { if ( ! $this->variation_shipping_class ) {
$classes = get_the_terms( $this->variation_id, 'product_shipping_class' ); $classes = get_the_terms( $this->variation_id, 'product_shipping_class' );
if ( $classes && ! is_wp_error( $classes ) ) { if ( $classes && ! is_wp_error( $classes ) ) {
$this->variation_shipping_class = esc_attr( current( $classes )->slug ); $this->variation_shipping_class = esc_attr( current( $classes )->slug );
} else { } else {
@ -418,13 +418,13 @@ class WC_Product_Variation extends WC_Product {
/** /**
* Get file download path identified by $download_id * Get file download path identified by $download_id
* *
* @access public * @access public
* @param string $download_id file identifier * @param string $download_id file identifier
* @return array * @return array
*/ */
function get_file_download_path( $download_id ) { function get_file_download_path( $download_id ) {
$file_path = ''; $file_path = '';
$file_paths = apply_filters( 'woocommerce_file_download_paths', get_post_meta( $this->variation_id, '_file_paths', true ), $this->variation_id, null, null ); $file_paths = apply_filters( 'woocommerce_file_download_paths', get_post_meta( $this->variation_id, '_file_paths', true ), $this->variation_id, null, null );
@ -438,7 +438,7 @@ class WC_Product_Variation extends WC_Product {
// allow overriding based on the particular file being requested // allow overriding based on the particular file being requested
return apply_filters( 'woocommerce_file_download_path', $file_path, $this->variation_id, $download_id ); return apply_filters( 'woocommerce_file_download_path', $file_path, $this->variation_id, $download_id );
} }
/** /**
* Checks sale data to see if the product is due to go on sale/sale has expired, and updates the main price. * Checks sale data to see if the product is due to go on sale/sale has expired, and updates the main price.
* *

View File

@ -69,7 +69,7 @@ class WC_Query {
// Get the actual WP page to avoid errors and let us use is_front_page() // Get the actual WP page to avoid errors and let us use is_front_page()
// This is hacky but works. Awaiting http://core.trac.wordpress.org/ticket/21096 // This is hacky but works. Awaiting http://core.trac.wordpress.org/ticket/21096
global $wp_post_types; global $wp_post_types;
$shop_page = get_post( woocommerce_get_page_id('shop') ); $shop_page = get_post( woocommerce_get_page_id('shop') );
$q->is_page = true; $q->is_page = true;
@ -81,7 +81,7 @@ class WC_Query {
$q->is_singular = false; $q->is_singular = false;
$q->is_post_type_archive = true; $q->is_post_type_archive = true;
$q->is_archive = true; $q->is_archive = true;
// Fix WP SEO // Fix WP SEO
if ( function_exists( 'wpseo_get_value' ) ) { if ( function_exists( 'wpseo_get_value' ) ) {
add_filter( 'wpseo_metadesc', array( &$this, 'wpseo_metadesc' ) ); add_filter( 'wpseo_metadesc', array( &$this, 'wpseo_metadesc' ) );
@ -104,11 +104,11 @@ class WC_Query {
// And remove the pre_get_posts hook // And remove the pre_get_posts hook
$this->remove_product_query(); $this->remove_product_query();
} }
/** /**
* wpseo_metadesc function. * wpseo_metadesc function.
* *
* @access public * @access public
* @param mixed $meta * @param mixed $meta
* @return void * @return void
@ -116,11 +116,11 @@ class WC_Query {
function wpseo_metadesc() { function wpseo_metadesc() {
return wpseo_get_value( 'metadesc', woocommerce_get_page_id('shop') ); return wpseo_get_value( 'metadesc', woocommerce_get_page_id('shop') );
} }
/** /**
* wpseo_metakey function. * wpseo_metakey function.
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -310,7 +310,7 @@ class WC_Query {
*/ */
function get_catalog_ordering_args() { function get_catalog_ordering_args() {
global $woocommerce; global $woocommerce;
$current_order = ( isset( $woocommerce->session->orderby ) ) ? $woocommerce->session->orderby : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) ); $current_order = ( isset( $woocommerce->session->orderby ) ) ? $woocommerce->session->orderby : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
switch ( $current_order ) { switch ( $current_order ) {

View File

@ -11,17 +11,17 @@
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class WC_Session_Transients extends WC_Session { class WC_Session_Transients extends WC_Session {
/** customer_id */ /** customer_id */
private $_customer_id; private $_customer_id;
/** cookie name */ /** cookie name */
private $_cookie; private $_cookie;
/** cookie expiration time */ /** cookie expiration time */
private $_cookie_expires; private $_cookie_expires;
/** /**
* Constructor for the session class. * Constructor for the session class.
* *
@ -30,19 +30,19 @@ class WC_Session_Transients extends WC_Session {
*/ */
public function __construct() { public function __construct() {
parent::__construct(); parent::__construct();
$this->_cookie = 'wc_session_cookie_' . COOKIEHASH; $this->_cookie = 'wc_session_cookie_' . COOKIEHASH;
$this->_cookie_expiration = apply_filters( 'wc_session_transients_expiration', 172800 ); // 48 hours default $this->_cookie_expiration = apply_filters( 'wc_session_transients_expiration', 172800 ); // 48 hours default
$this->_customer_id = $this->get_customer_id(); $this->_customer_id = $this->get_customer_id();
$this->_data = maybe_unserialize( get_transient( 'wc_session_' . $this->_customer_id ) ); $this->_data = maybe_unserialize( get_transient( 'wc_session_' . $this->_customer_id ) );
if ( false === $this->_data ) if ( false === $this->_data )
$this->_data = array(); $this->_data = array();
} }
/** /**
* get_customer_id function. * get_customer_id function.
* *
* @access private * @access private
* @return mixed * @return mixed
*/ */
@ -55,32 +55,32 @@ class WC_Session_Transients extends WC_Session {
return $this->create_customer_id(); return $this->create_customer_id();
} }
} }
/** /**
* get_session_cookie function. * get_session_cookie function.
* *
* @access private * @access private
* @return mixed * @return mixed
*/ */
private function get_session_cookie() { private function get_session_cookie() {
if ( ! isset( $_COOKIE[ $this->_cookie ] ) ) if ( ! isset( $_COOKIE[ $this->_cookie ] ) )
return false; return false;
list( $customer_id, $expires, $hash ) = explode( '|', $_COOKIE[ $this->_cookie ] ); list( $customer_id, $expires, $hash ) = explode( '|', $_COOKIE[ $this->_cookie ] );
// Validate hash // Validate hash
$data = $customer_id . $expires; $data = $customer_id . $expires;
$rehash = hash_hmac( 'md5', $data, wp_hash( $data ) ); $rehash = hash_hmac( 'md5', $data, wp_hash( $data ) );
if ( $hash != $rehash ) if ( $hash != $rehash )
return false; return false;
return $customer_id; return $customer_id;
} }
/** /**
* Create a unqiue customer ID and store it in a cookie, along with its hashed value and expirey date. Stored for 48hours. * Create a unqiue customer ID and store it in a cookie, along with its hashed value and expirey date. Stored for 48hours.
* *
* @access private * @access private
* @return void * @return void
*/ */
@ -90,15 +90,15 @@ class WC_Session_Transients extends WC_Session {
$data = $customer_id . $expires; $data = $customer_id . $expires;
$hash = hash_hmac( 'md5', $data, wp_hash( $data ) ); $hash = hash_hmac( 'md5', $data, wp_hash( $data ) );
$value = $customer_id . '|' . $expires . '|' . $hash; $value = $customer_id . '|' . $expires . '|' . $hash;
setcookie( $this->_cookie, $value, $expires, COOKIEPATH, COOKIE_DOMAIN, false, true ); setcookie( $this->_cookie, $value, $expires, COOKIEPATH, COOKIE_DOMAIN, false, true );
return $customer_id; return $customer_id;
} }
/** /**
* save_data function. * save_data function.
* *
* @access public * @access public
* @return void * @return void
*/ */

View File

@ -193,10 +193,10 @@ class WC_Settings_API {
$data['css'] = isset( $data['css'] ) ? $data['css'] : ''; $data['css'] = isset( $data['css'] ) ? $data['css'] : '';
$data['placeholder'] = isset( $data['placeholder'] ) ? $data['placeholder'] : ''; $data['placeholder'] = isset( $data['placeholder'] ) ? $data['placeholder'] : '';
$data['type'] = isset( $data['type'] ) ? $data['type'] : 'text'; $data['type'] = isset( $data['type'] ) ? $data['type'] : 'text';
// Custom attribute handling // Custom attribute handling
$custom_attributes = array(); $custom_attributes = array();
if ( ! empty( $data['custom_attributes'] ) && is_array( $data['custom_attributes'] ) ) if ( ! empty( $data['custom_attributes'] ) && is_array( $data['custom_attributes'] ) )
foreach ( $data['custom_attributes'] as $attribute => $attribute_value ) foreach ( $data['custom_attributes'] as $attribute => $attribute_value )
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"'; $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
@ -233,10 +233,10 @@ class WC_Settings_API {
$data['disabled'] = empty( $data['disabled'] ) ? false : true; $data['disabled'] = empty( $data['disabled'] ) ? false : true;
$data['class'] = isset( $data['class'] ) ? $data['class'] : ''; $data['class'] = isset( $data['class'] ) ? $data['class'] : '';
$data['css'] = isset( $data['css'] ) ? $data['css'] : ''; $data['css'] = isset( $data['css'] ) ? $data['css'] : '';
// Custom attribute handling // Custom attribute handling
$custom_attributes = array(); $custom_attributes = array();
if ( ! empty( $data['custom_attributes'] ) && is_array( $data['custom_attributes'] ) ) if ( ! empty( $data['custom_attributes'] ) && is_array( $data['custom_attributes'] ) )
foreach ( $data['custom_attributes'] as $attribute => $attribute_value ) foreach ( $data['custom_attributes'] as $attribute => $attribute_value )
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"'; $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
@ -274,10 +274,10 @@ class WC_Settings_API {
if ( ! isset( $this->settings[$key] ) ) $this->settings[$key] = ''; if ( ! isset( $this->settings[$key] ) ) $this->settings[$key] = '';
$data['class'] = isset( $data['class'] ) ? $data['class'] : ''; $data['class'] = isset( $data['class'] ) ? $data['class'] : '';
$data['css'] = isset( $data['css'] ) ? $data['css'] : ''; $data['css'] = isset( $data['css'] ) ? $data['css'] : '';
// Custom attribute handling // Custom attribute handling
$custom_attributes = array(); $custom_attributes = array();
if ( ! empty( $data['custom_attributes'] ) && is_array( $data['custom_attributes'] ) ) if ( ! empty( $data['custom_attributes'] ) && is_array( $data['custom_attributes'] ) )
foreach ( $data['custom_attributes'] as $attribute => $attribute_value ) foreach ( $data['custom_attributes'] as $attribute => $attribute_value )
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"'; $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
@ -315,10 +315,10 @@ class WC_Settings_API {
$data['disabled'] = empty( $data['disabled'] ) ? false : true; $data['disabled'] = empty( $data['disabled'] ) ? false : true;
$data['class'] = isset( $data['class'] ) ? $data['class'] : ''; $data['class'] = isset( $data['class'] ) ? $data['class'] : '';
$data['css'] = isset( $data['css'] ) ? $data['css'] : ''; $data['css'] = isset( $data['css'] ) ? $data['css'] : '';
// Custom attribute handling // Custom attribute handling
$custom_attributes = array(); $custom_attributes = array();
if ( ! empty( $data['custom_attributes'] ) && is_array( $data['custom_attributes'] ) ) if ( ! empty( $data['custom_attributes'] ) && is_array( $data['custom_attributes'] ) )
foreach ( $data['custom_attributes'] as $attribute => $attribute_value ) foreach ( $data['custom_attributes'] as $attribute => $attribute_value )
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"'; $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
@ -354,10 +354,10 @@ class WC_Settings_API {
$data['options'] = isset( $data['options'] ) ? (array) $data['options'] : array(); $data['options'] = isset( $data['options'] ) ? (array) $data['options'] : array();
$data['class'] = isset( $data['class'] ) ? $data['class'] : ''; $data['class'] = isset( $data['class'] ) ? $data['class'] : '';
$data['css'] = isset( $data['css'] ) ? $data['css'] : ''; $data['css'] = isset( $data['css'] ) ? $data['css'] : '';
// Custom attribute handling // Custom attribute handling
$custom_attributes = array(); $custom_attributes = array();
if ( ! empty( $data['custom_attributes'] ) && is_array( $data['custom_attributes'] ) ) if ( ! empty( $data['custom_attributes'] ) && is_array( $data['custom_attributes'] ) )
foreach ( $data['custom_attributes'] as $attribute => $attribute_value ) foreach ( $data['custom_attributes'] as $attribute => $attribute_value )
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"'; $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
@ -400,10 +400,10 @@ class WC_Settings_API {
$data['options'] = isset( $data['options'] ) ? (array) $data['options'] : array(); $data['options'] = isset( $data['options'] ) ? (array) $data['options'] : array();
$data['class'] = isset( $data['class'] ) ? $data['class'] : ''; $data['class'] = isset( $data['class'] ) ? $data['class'] : '';
$data['css'] = isset( $data['css'] ) ? $data['css'] : ''; $data['css'] = isset( $data['css'] ) ? $data['css'] : '';
// Custom attribute handling // Custom attribute handling
$custom_attributes = array(); $custom_attributes = array();
if ( ! empty( $data['custom_attributes'] ) && is_array( $data['custom_attributes'] ) ) if ( ! empty( $data['custom_attributes'] ) && is_array( $data['custom_attributes'] ) )
foreach ( $data['custom_attributes'] as $attribute => $attribute_value ) foreach ( $data['custom_attributes'] as $attribute => $attribute_value )
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"'; $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
@ -474,7 +474,7 @@ class WC_Settings_API {
$this->sanitized_fields = array(); $this->sanitized_fields = array();
foreach ( $form_fields as $k => $v ) { foreach ( $form_fields as $k => $v ) {
if ( empty( $v['type'] ) ) if ( empty( $v['type'] ) )
$v['type'] == 'text'; // Default to "text" field type. $v['type'] == 'text'; // Default to "text" field type.
if ( method_exists( $this, 'validate_' . $v['type'] . '_field' ) ) { if ( method_exists( $this, 'validate_' . $v['type'] . '_field' ) ) {

View File

@ -35,35 +35,35 @@ class WC_Tax {
if ( ! empty( $tax_rates ) ) { if ( ! empty( $tax_rates ) ) {
foreach( $tax_rates as $rate ) { foreach( $tax_rates as $rate ) {
// Standard Rate? // Standard Rate?
if ( empty( $rate['class'] ) ) if ( empty( $rate['class'] ) )
$rate['class'] = '*'; $rate['class'] = '*';
// Add entry for each country/state - each will hold all matching rates // Add entry for each country/state - each will hold all matching rates
if ( ! empty( $rate['countries'] ) ) { if ( ! empty( $rate['countries'] ) ) {
foreach( $rate['countries'] as $country => $states ) { foreach( $rate['countries'] as $country => $states ) {
if ( $states ) { if ( $states ) {
foreach ( $states as $state ) { foreach ( $states as $state ) {
if ( empty( $rate['label'] ) ) { if ( empty( $rate['label'] ) ) {
$rate['label'] = $woocommerce->countries->tax_or_vat(); $rate['label'] = $woocommerce->countries->tax_or_vat();
// Add % to label // Add % to label
if ( $rate['rate'] > 0 || $rate['rate'] === 0 ) if ( $rate['rate'] > 0 || $rate['rate'] === 0 )
$rate['label'] .= ' (' . rtrim( rtrim( $rate['rate'], '0' ), '.' ) . '%)'; $rate['label'] .= ' (' . rtrim( rtrim( $rate['rate'], '0' ), '.' ) . '%)';
} }
$flat_rates[ $index ] = $rate; $flat_rates[ $index ] = $rate;
$parsed_rates[ $country ][ $state ][ $rate['class'] ][ $index ] = array( $parsed_rates[ $country ][ $state ][ $rate['class'] ][ $index ] = array(
'label' => $rate['label'], 'label' => $rate['label'],
'rate' => $rate['rate'], 'rate' => $rate['rate'],
'shipping' => $rate['shipping'], 'shipping' => $rate['shipping'],
'compound' => $rate['compound'] 'compound' => $rate['compound']
); );
$index++; $index++;
} }
} }
} }
@ -73,32 +73,32 @@ class WC_Tax {
if ( ! empty( $local_tax_rates ) ) { if ( ! empty( $local_tax_rates ) ) {
foreach( $local_tax_rates as $rate ) { foreach( $local_tax_rates as $rate ) {
// Standard Rate? // Standard Rate?
if ( empty( $rate['class'] ) ) if ( empty( $rate['class'] ) )
$rate['class'] = '*'; $rate['class'] = '*';
if ( empty( $rate['label'] ) ) { if ( empty( $rate['label'] ) ) {
$rate['label'] = $woocommerce->countries->tax_or_vat(); $rate['label'] = $woocommerce->countries->tax_or_vat();
// Add % to label // Add % to label
if ( $rate['rate'] > 0 || $rate['rate'] === 0 ) if ( $rate['rate'] > 0 || $rate['rate'] === 0 )
$rate['label'] .= ' (' . rtrim( rtrim( $rate['rate'], '0' ), '.' ) . '%)'; $rate['label'] .= ' (' . rtrim( rtrim( $rate['rate'], '0' ), '.' ) . '%)';
} }
// Backwards compat // Backwards compat
if ( empty( $rate['locations'] ) && isset( $rate['postcode'] ) ) if ( empty( $rate['locations'] ) && isset( $rate['postcode'] ) )
$rate['locations'] = $rate['postcode']; $rate['locations'] = $rate['postcode'];
if ( empty( $rate['location_type'] ) ) if ( empty( $rate['location_type'] ) )
$rate['location_type'] = 'postcode'; $rate['location_type'] = 'postcode';
// Postcodes -> Uppercase // Postcodes -> Uppercase
if ( $rate['location_type'] == 'postcode' ) if ( $rate['location_type'] == 'postcode' )
$rate['locations'] = array_map( 'strtoupper', (array) $rate['locations'] ); $rate['locations'] = array_map( 'strtoupper', (array) $rate['locations'] );
$flat_rates[ $index ] = $rate; $flat_rates[ $index ] = $rate;
$parsed_rates[ $rate['country'] ][ $rate['state'] ][ $rate['class'] ][ $index ] = array( $parsed_rates[ $rate['country'] ][ $rate['state'] ][ $rate['class'] ][ $index ] = array(
'label' => $rate['label'], 'label' => $rate['label'],
'rate' => $rate['rate'], 'rate' => $rate['rate'],
@ -118,17 +118,17 @@ class WC_Tax {
do_action( 'woocommerce_get_tax_rates', $this ); do_action( 'woocommerce_get_tax_rates', $this );
} }
} }
/** /**
* Searches for all matching country/state/postcode tax rates. * Searches for all matching country/state/postcode tax rates.
* *
* @access public * @access public
* @param string $args (default: '') * @param string $args (default: '')
* @return array * @return array
*/ */
function find_rates( $args = '' ) { function find_rates( $args = '' ) {
$this->get_tax_rates(); $this->get_tax_rates();
$defaults = array( $defaults = array(
'country' => '', 'country' => '',
'state' => '', 'state' => '',
@ -141,14 +141,14 @@ class WC_Tax {
extract( $args, EXTR_SKIP ); extract( $args, EXTR_SKIP );
if ( ! $country ) if ( ! $country )
return array(); return array();
$state = $state ? $state : '*'; $state = $state ? $state : '*';
$tax_class = $tax_class ? $tax_class : '*'; $tax_class = $tax_class ? $tax_class : '*';
$city = sanitize_title( $city ); $city = sanitize_title( $city );
$tax_class = sanitize_title( $tax_class ); $tax_class = sanitize_title( $tax_class );
$found_rates = array(); $found_rates = array();
// Look for a state specific rule // Look for a state specific rule
@ -178,36 +178,36 @@ class WC_Tax {
foreach ( $found_rates as $key => $rate ) { foreach ( $found_rates as $key => $rate ) {
if ( ! empty( $rate['locations'] ) && $rate['location_type'] == 'postcode' ) { if ( ! empty( $rate['locations'] ) && $rate['location_type'] == 'postcode' ) {
// Local rate // Local rate
if ( $postcode ) { if ( $postcode ) {
// Check if postcode matches up // Check if postcode matches up
if ( in_array( $postcode, $rate['locations'] ) || sizeof( $rate['locations'] ) == 0 ) if ( in_array( $postcode, $rate['locations'] ) || sizeof( $rate['locations'] ) == 0 )
$matched_tax_rates[ $key ] = $rate; $matched_tax_rates[ $key ] = $rate;
// Check postcode ranges // Check postcode ranges
if ( is_numeric( $postcode ) ) { if ( is_numeric( $postcode ) ) {
foreach ( $rate['locations'] as $rate_postcode ) { foreach ( $rate['locations'] as $rate_postcode ) {
if ( strstr( $rate_postcode, '-' ) ) { if ( strstr( $rate_postcode, '-' ) ) {
$parts = array_map( 'trim', explode( '-', $rate_postcode ) ); $parts = array_map( 'trim', explode( '-', $rate_postcode ) );
if ( sizeof( $parts ) == 2 && is_numeric( $parts[0] ) && is_numeric( $parts[1] ) ) if ( sizeof( $parts ) == 2 && is_numeric( $parts[0] ) && is_numeric( $parts[1] ) )
if ( $postcode >= $parts[0] && $postcode <= $parts[1] ) if ( $postcode >= $parts[0] && $postcode <= $parts[1] )
$matched_tax_rates[ $key ] = $rate; $matched_tax_rates[ $key ] = $rate;
} }
} }
} }
} }
} elseif ( ! empty( $rate['locations'] ) && $rate['location_type'] == 'city' ) { } elseif ( ! empty( $rate['locations'] ) && $rate['location_type'] == 'city' ) {
// Local rate // Local rate
if ( $city ) { if ( $city ) {
// Check if city matches up // Check if city matches up
if ( in_array( $city, $rate['locations'] ) || sizeof( $rate['locations'] ) == 0 ) if ( in_array( $city, $rate['locations'] ) || sizeof( $rate['locations'] ) == 0 )
$matched_tax_rates[ $key ] = $rate; $matched_tax_rates[ $key ] = $rate;
} }
} else { } else {
// Standard rate // Standard rate
$matched_tax_rates[ $key ] = $rate; $matched_tax_rates[ $key ] = $rate;
@ -228,20 +228,20 @@ class WC_Tax {
*/ */
function get_rates( $tax_class = '' ) { function get_rates( $tax_class = '' ) {
global $woocommerce; global $woocommerce;
$this->get_tax_rates(); $this->get_tax_rates();
$tax_class = sanitize_title( $tax_class ); $tax_class = sanitize_title( $tax_class );
/* Checkout uses customer location for the tax rates. Also, if shipping has been calculated, use the customers address. */ /* Checkout uses customer location for the tax rates. Also, if shipping has been calculated, use the customers address. */
if ( ( defined('WOOCOMMERCE_CHECKOUT') && WOOCOMMERCE_CHECKOUT ) || $woocommerce->customer->has_calculated_shipping() ) { if ( ( defined('WOOCOMMERCE_CHECKOUT') && WOOCOMMERCE_CHECKOUT ) || $woocommerce->customer->has_calculated_shipping() ) {
list( $country, $state, $postcode, $city ) = $woocommerce->customer->get_taxable_address(); list( $country, $state, $postcode, $city ) = $woocommerce->customer->get_taxable_address();
$matched_tax_rates = $this->find_rates( array( $matched_tax_rates = $this->find_rates( array(
'country' => $country, 'country' => $country,
'state' => $state, 'state' => $state,
'postcode' => $postcode, 'postcode' => $postcode,
'city' => $city, 'city' => $city,
'tax_class' => $tax_class 'tax_class' => $tax_class
) ); ) );
@ -275,9 +275,9 @@ class WC_Tax {
$state = $woocommerce->countries->get_base_state(); $state = $woocommerce->countries->get_base_state();
return $this->find_rates( array( return $this->find_rates( array(
'country' => $country, 'country' => $country,
'state' => $state, 'state' => $state,
'tax_class' => $tax_class 'tax_class' => $tax_class
) ); ) );
} }
@ -289,7 +289,7 @@ class WC_Tax {
*/ */
function get_shipping_tax_rates( $tax_class = null ) { function get_shipping_tax_rates( $tax_class = null ) {
global $woocommerce; global $woocommerce;
// See if we have an explicitly set shipping tax class // See if we have an explicitly set shipping tax class
if ( $shipping_tax_class = get_option( 'woocommerce_shipping_tax_class' ) ) { if ( $shipping_tax_class = get_option( 'woocommerce_shipping_tax_class' ) ) {
$tax_class = $shipping_tax_class == 'standard' ? '' : $shipping_tax_class; $tax_class = $shipping_tax_class == 'standard' ? '' : $shipping_tax_class;
@ -298,11 +298,11 @@ class WC_Tax {
$this->get_tax_rates(); $this->get_tax_rates();
if ( ( defined('WOOCOMMERCE_CHECKOUT') && WOOCOMMERCE_CHECKOUT ) || $woocommerce->customer->has_calculated_shipping() ) { if ( ( defined('WOOCOMMERCE_CHECKOUT') && WOOCOMMERCE_CHECKOUT ) || $woocommerce->customer->has_calculated_shipping() ) {
list( $country, $state, $postcode, $city ) = $woocommerce->customer->get_taxable_address(); list( $country, $state, $postcode, $city ) = $woocommerce->customer->get_taxable_address();
} else { } else {
// Prices which include tax should always use the base rate if we don't know where the user is located // Prices which include tax should always use the base rate if we don't know where the user is located
// Prices exlcuding tax however should just not add any taxes, as they will be added during checkout // Prices exlcuding tax however should just not add any taxes, as they will be added during checkout
if ( $woocommerce->cart->prices_include_tax ) { if ( $woocommerce->cart->prices_include_tax ) {
@ -323,14 +323,14 @@ class WC_Tax {
// This will be per item shipping // This will be per item shipping
$rates = $this->find_rates( array( $rates = $this->find_rates( array(
'country' => $country, 'country' => $country,
'state' => $state, 'state' => $state,
'postcode' => $postcode, 'postcode' => $postcode,
'city' => $city, 'city' => $city,
'tax_class' => $tax_class 'tax_class' => $tax_class
) ); ) );
if ( $rates ) if ( $rates )
foreach ( $rates as $key => $rate ) foreach ( $rates as $key => $rate )
if ( isset( $rate['shipping'] ) && $rate['shipping'] == 'yes' ) if ( isset( $rate['shipping'] ) && $rate['shipping'] == 'yes' )
$matched_tax_rates[ $key ] = $rate; $matched_tax_rates[ $key ] = $rate;
@ -338,13 +338,13 @@ class WC_Tax {
if ( sizeof( $matched_tax_rates ) == 0 ) { if ( sizeof( $matched_tax_rates ) == 0 ) {
// Get standard rate // Get standard rate
$rates = $this->find_rates( array( $rates = $this->find_rates( array(
'country' => $country, 'country' => $country,
'state' => $state, 'state' => $state,
'city' => $city, 'city' => $city,
'postcode' => $postcode, 'postcode' => $postcode,
) ); ) );
if ( $rates ) if ( $rates )
foreach ( $rates as $key => $rate ) foreach ( $rates as $key => $rate )
if ( isset( $rate['shipping'] ) && $rate['shipping'] == 'yes' ) if ( isset( $rate['shipping'] ) && $rate['shipping'] == 'yes' )
$matched_tax_rates[ $key ] = $rate; $matched_tax_rates[ $key ] = $rate;
@ -360,7 +360,7 @@ class WC_Tax {
$rates = false; $rates = false;
// Loop cart and find the highest tax band // Loop cart and find the highest tax band
if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) if ( sizeof( $woocommerce->cart->get_cart() ) > 0 )
foreach ( $woocommerce->cart->get_cart() as $item ) foreach ( $woocommerce->cart->get_cart() as $item )
$found_tax_classes[] = $item['data']->get_tax_class(); $found_tax_classes[] = $item['data']->get_tax_class();
@ -371,10 +371,10 @@ class WC_Tax {
if ( in_array( '', $found_tax_classes ) ) { if ( in_array( '', $found_tax_classes ) ) {
$rates = $this->find_rates( array( $rates = $this->find_rates( array(
'country' => $country, 'country' => $country,
'state' => $state, 'state' => $state,
'city' => $city, 'city' => $city,
'postcode' => $postcode, 'postcode' => $postcode,
) ); ) );
} else { } else {
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option( 'woocommerce_tax_classes' ) ) ) ); $tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option( 'woocommerce_tax_classes' ) ) ) );
@ -382,11 +382,11 @@ class WC_Tax {
foreach ( $tax_classes as $tax_class ) { foreach ( $tax_classes as $tax_class ) {
if ( in_array( $tax_class, $found_tax_classes ) ) { if ( in_array( $tax_class, $found_tax_classes ) ) {
$rates = $this->find_rates( array( $rates = $this->find_rates( array(
'country' => $country, 'country' => $country,
'state' => $state, 'state' => $state,
'postcode' => $postcode, 'postcode' => $postcode,
'city' => $city, 'city' => $city,
'tax_class' => $tax_class 'tax_class' => $tax_class
) ); ) );
break; break;
} }
@ -397,11 +397,11 @@ class WC_Tax {
} elseif ( sizeof( $found_tax_classes ) == 1 ) { } elseif ( sizeof( $found_tax_classes ) == 1 ) {
$rates = $this->find_rates( array( $rates = $this->find_rates( array(
'country' => $country, 'country' => $country,
'state' => $state, 'state' => $state,
'postcode' => $postcode, 'postcode' => $postcode,
'city' => $city, 'city' => $city,
'tax_class' => $found_tax_classes[0] 'tax_class' => $found_tax_classes[0]
) ); ) );
} }
@ -409,13 +409,13 @@ class WC_Tax {
// If no class rate are found, use standard rates // If no class rate are found, use standard rates
if ( ! $rates ) if ( ! $rates )
$rates = $this->find_rates( array( $rates = $this->find_rates( array(
'country' => $country, 'country' => $country,
'state' => $state, 'state' => $state,
'postcode' => $postcode, 'postcode' => $postcode,
'city' => $city, 'city' => $city,
) ); ) );
if ( $rates ) if ( $rates )
foreach ( $rates as $key => $rate ) foreach ( $rates as $key => $rate )
if ( isset( $rate['shipping'] ) && $rate['shipping'] == 'yes' ) if ( isset( $rate['shipping'] ) && $rate['shipping'] == 'yes' )
$matched_tax_rates[ $key ] = $rate; $matched_tax_rates[ $key ] = $rate;
@ -613,7 +613,7 @@ class WC_Tax {
*/ */
function get_rate_label( $key ) { function get_rate_label( $key ) {
$label = empty( $this->rates[ $key ]['label'] ) ? '' : $this->rates[ $key ]['label']; $label = empty( $this->rates[ $key ]['label'] ) ? '' : $this->rates[ $key ]['label'];
return apply_filters( 'woocommerce_rate_label', $label, $key, $this ); return apply_filters( 'woocommerce_rate_label', $label, $key, $this );
} }

View File

@ -19,23 +19,23 @@ class WC_Email_Customer_Completed_Order extends WC_Email {
* Constructor * Constructor
*/ */
function __construct() { function __construct() {
$this->id = 'customer_completed_order'; $this->id = 'customer_completed_order';
$this->title = __( 'Completed order', 'woocommerce' ); $this->title = __( 'Completed order', 'woocommerce' );
$this->description = __( 'Order complete emails are sent to the customer when the order is marked complete and usual indicates that the order has been shipped.', 'woocommerce' ); $this->description = __( 'Order complete emails are sent to the customer when the order is marked complete and usual indicates that the order has been shipped.', 'woocommerce' );
$this->heading = __( 'Your order is complete', 'woocommerce' ); $this->heading = __( 'Your order is complete', 'woocommerce' );
$this->subject = __( 'Your {blogname} order from {order_date} is complete', 'woocommerce' ); $this->subject = __( 'Your {blogname} order from {order_date} is complete', 'woocommerce' );
$this->heading_downloadable = __( 'Your order is complete - download your files', 'woocommerce' ); $this->heading_downloadable = __( 'Your order is complete - download your files', 'woocommerce' );
$this->subject_downloadable = __( 'Your {blogname} order from {order_date} is complete - download your files', 'woocommerce' ); $this->subject_downloadable = __( 'Your {blogname} order from {order_date} is complete - download your files', 'woocommerce' );
$this->template_html = 'emails/customer-completed-order.php'; $this->template_html = 'emails/customer-completed-order.php';
$this->template_plain = 'emails/plain/customer-completed-order.php'; $this->template_plain = 'emails/plain/customer-completed-order.php';
// Triggers for this email // Triggers for this email
add_action( 'woocommerce_order_status_completed_notification', array( &$this, 'trigger' ) ); add_action( 'woocommerce_order_status_completed_notification', array( &$this, 'trigger' ) );
// Call parent constuctor // Call parent constuctor
parent::__construct(); parent::__construct();
@ -46,33 +46,33 @@ class WC_Email_Customer_Completed_Order extends WC_Email {
/** /**
* trigger function. * trigger function.
* *
* @access public * @access public
* @return void * @return void
*/ */
function trigger( $order_id ) { function trigger( $order_id ) {
global $woocommerce; global $woocommerce;
if ( $order_id ) { if ( $order_id ) {
$this->object = new WC_Order( $order_id ); $this->object = new WC_Order( $order_id );
$this->recipient = $this->object->billing_email; $this->recipient = $this->object->billing_email;
$this->find[] = '{order_date}'; $this->find[] = '{order_date}';
$this->replace[] = date_i18n( woocommerce_date_format(), strtotime( $this->object->order_date ) ); $this->replace[] = date_i18n( woocommerce_date_format(), strtotime( $this->object->order_date ) );
$this->find[] = '{order_number}'; $this->find[] = '{order_number}';
$this->replace[] = $this->object->get_order_number(); $this->replace[] = $this->object->get_order_number();
} }
if ( ! $this->is_enabled() || ! $this->get_recipient() ) if ( ! $this->is_enabled() || ! $this->get_recipient() )
return; return;
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() ); $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
} }
/** /**
* get_subject function. * get_subject function.
* *
* @access public * @access public
* @return string * @return string
*/ */
@ -85,7 +85,7 @@ class WC_Email_Customer_Completed_Order extends WC_Email {
/** /**
* get_heading function. * get_heading function.
* *
* @access public * @access public
* @return string * @return string
*/ */
@ -98,7 +98,7 @@ class WC_Email_Customer_Completed_Order extends WC_Email {
/** /**
* get_content_html function. * get_content_html function.
* *
* @access public * @access public
* @return string * @return string
*/ */
@ -110,10 +110,10 @@ class WC_Email_Customer_Completed_Order extends WC_Email {
) ); ) );
return ob_get_clean(); return ob_get_clean();
} }
/** /**
* get_content_plain function. * get_content_plain function.
* *
* @access public * @access public
* @return string * @return string
*/ */
@ -125,7 +125,7 @@ class WC_Email_Customer_Completed_Order extends WC_Email {
) ); ) );
return ob_get_clean(); return ob_get_clean();
} }
/** /**
* Initialise Settings Form Fields * Initialise Settings Form Fields
* *

View File

@ -14,35 +14,35 @@
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class WC_Email_Customer_Invoice extends WC_Email { class WC_Email_Customer_Invoice extends WC_Email {
var $find; var $find;
var $replace; var $replace;
/** /**
* Constructor * Constructor
*/ */
function __construct() { function __construct() {
$this->id = 'customer_invoice'; $this->id = 'customer_invoice';
$this->title = __( 'Customer invoice', 'woocommerce' ); $this->title = __( 'Customer invoice', 'woocommerce' );
$this->description = __( 'Customer invoice emails can be sent to the user containing order info and payment links.', 'woocommerce' ); $this->description = __( 'Customer invoice emails can be sent to the user containing order info and payment links.', 'woocommerce' );
$this->template_html = 'emails/customer-invoice.php'; $this->template_html = 'emails/customer-invoice.php';
$this->template_plain = 'emails/plain/customer-invoice.php'; $this->template_plain = 'emails/plain/customer-invoice.php';
$this->subject = __( 'Invoice for order {order_number} from {order_date}', 'woocommerce'); $this->subject = __( 'Invoice for order {order_number} from {order_date}', 'woocommerce');
$this->heading = __( 'Invoice for order {order_number}', 'woocommerce'); $this->heading = __( 'Invoice for order {order_number}', 'woocommerce');
$this->subject_paid = __( 'Your {blogname} order from {order_date}', 'woocommerce'); $this->subject_paid = __( 'Your {blogname} order from {order_date}', 'woocommerce');
$this->heading_paid = __( 'Order {order_number} details', 'woocommerce'); $this->heading_paid = __( 'Order {order_number} details', 'woocommerce');
// Call parent constuctor // Call parent constuctor
parent::__construct(); parent::__construct();
} }
/** /**
* trigger function. * trigger function.
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -52,27 +52,27 @@ class WC_Email_Customer_Invoice extends WC_Email {
if ( ! is_object( $order ) ) { if ( ! is_object( $order ) ) {
$order = new WC_Order( absint( $order ) ); $order = new WC_Order( absint( $order ) );
} }
if ( $order ) { if ( $order ) {
$this->object = $order; $this->object = $order;
$this->recipient = $this->object->billing_email; $this->recipient = $this->object->billing_email;
$this->find[] = '{order_date}'; $this->find[] = '{order_date}';
$this->replace[] = date_i18n( woocommerce_date_format(), strtotime( $this->object->order_date ) ); $this->replace[] = date_i18n( woocommerce_date_format(), strtotime( $this->object->order_date ) );
$this->find[] = '{order_number}'; $this->find[] = '{order_number}';
$this->replace[] = $this->object->get_order_number(); $this->replace[] = $this->object->get_order_number();
} }
if ( ! $this->is_enabled() || ! $this->get_recipient() ) if ( ! $this->is_enabled() || ! $this->get_recipient() )
return; return;
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() ); $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
} }
/** /**
* get_subject function. * get_subject function.
* *
* @access public * @access public
* @return string * @return string
*/ */
@ -85,7 +85,7 @@ class WC_Email_Customer_Invoice extends WC_Email {
/** /**
* get_heading function. * get_heading function.
* *
* @access public * @access public
* @return string * @return string
*/ */
@ -98,7 +98,7 @@ class WC_Email_Customer_Invoice extends WC_Email {
/** /**
* get_content_html function. * get_content_html function.
* *
* @access public * @access public
* @return string * @return string
*/ */
@ -110,10 +110,10 @@ class WC_Email_Customer_Invoice extends WC_Email {
) ); ) );
return ob_get_clean(); return ob_get_clean();
} }
/** /**
* get_content_plain function. * get_content_plain function.
* *
* @access public * @access public
* @return string * @return string
*/ */
@ -125,7 +125,7 @@ class WC_Email_Customer_Invoice extends WC_Email {
) ); ) );
return ob_get_clean(); return ob_get_clean();
} }
/** /**
* Initialise Settings Form Fields * Initialise Settings Form Fields
* *

View File

@ -14,11 +14,11 @@
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class WC_Email_Customer_New_Account extends WC_Email { class WC_Email_Customer_New_Account extends WC_Email {
var $user_login; var $user_login;
var $user_email; var $user_email;
var $user_pass; var $user_pass;
/** /**
* Constructor * Constructor
* *
@ -26,14 +26,14 @@ class WC_Email_Customer_New_Account extends WC_Email {
* @return void * @return void
*/ */
function __construct() { function __construct() {
$this->id = 'customer_new_account'; $this->id = 'customer_new_account';
$this->title = __( 'New account', 'woocommerce' ); $this->title = __( 'New account', 'woocommerce' );
$this->description = __( 'Customer new account emails are sent when a customer signs up via the checkout or My Account page.', 'woocommerce' ); $this->description = __( 'Customer new account emails are sent when a customer signs up via the checkout or My Account page.', 'woocommerce' );
$this->template_html = 'emails/customer-new-account.php'; $this->template_html = 'emails/customer-new-account.php';
$this->template_plain = 'emails/plain/customer-new-account.php'; $this->template_plain = 'emails/plain/customer-new-account.php';
$this->subject = __( 'Your account on {blogname}', 'woocommerce'); $this->subject = __( 'Your account on {blogname}', 'woocommerce');
$this->heading = __( 'Welcome to {blogname}', 'woocommerce'); $this->heading = __( 'Welcome to {blogname}', 'woocommerce');
@ -43,31 +43,31 @@ class WC_Email_Customer_New_Account extends WC_Email {
/** /**
* trigger function. * trigger function.
* *
* @access public * @access public
* @return void * @return void
*/ */
function trigger( $user_id, $user_pass = '' ) { function trigger( $user_id, $user_pass = '' ) {
global $woocommerce; global $woocommerce;
if ( $user_id ) { if ( $user_id ) {
$this->object = new WP_User( $user_id ); $this->object = new WP_User( $user_id );
$this->user_pass = $user_pass; $this->user_pass = $user_pass;
$this->user_login = stripslashes( $this->object->user_login ); $this->user_login = stripslashes( $this->object->user_login );
$this->user_email = stripslashes( $this->object->user_email ); $this->user_email = stripslashes( $this->object->user_email );
$this->recipient = $this->user_email; $this->recipient = $this->user_email;
} }
if ( ! $this->is_enabled() || ! $this->get_recipient() ) if ( ! $this->is_enabled() || ! $this->get_recipient() )
return; return;
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() ); $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
} }
/** /**
* get_content_html function. * get_content_html function.
* *
* @access public * @access public
* @return string * @return string
*/ */
@ -81,10 +81,10 @@ class WC_Email_Customer_New_Account extends WC_Email {
) ); ) );
return ob_get_clean(); return ob_get_clean();
} }
/** /**
* get_content_plain function. * get_content_plain function.
* *
* @access public * @access public
* @return string * @return string
*/ */

View File

@ -14,9 +14,9 @@
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class WC_Email_Customer_Note extends WC_Email { class WC_Email_Customer_Note extends WC_Email {
var $customer_note; var $customer_note;
/** /**
* Constructor * Constructor
* *
@ -24,64 +24,64 @@ class WC_Email_Customer_Note extends WC_Email {
* @return void * @return void
*/ */
function __construct() { function __construct() {
$this->id = 'customer_note'; $this->id = 'customer_note';
$this->title = __( 'Customer note', 'woocommerce' ); $this->title = __( 'Customer note', 'woocommerce' );
$this->description = __( 'Customer note emails are sent when you add a note to an order.', 'woocommerce' ); $this->description = __( 'Customer note emails are sent when you add a note to an order.', 'woocommerce' );
$this->template_html = 'emails/customer-note.php'; $this->template_html = 'emails/customer-note.php';
$this->template_plain = 'emails/plain/customer-note.php'; $this->template_plain = 'emails/plain/customer-note.php';
$this->subject = __( 'Note added to your {blogname} order from {order_date}', 'woocommerce'); $this->subject = __( 'Note added to your {blogname} order from {order_date}', 'woocommerce');
$this->heading = __( 'A note has been added to your order', 'woocommerce'); $this->heading = __( 'A note has been added to your order', 'woocommerce');
// Triggers // Triggers
add_action( 'woocommerce_new_customer_note_notification', array( &$this, 'trigger' ) ); add_action( 'woocommerce_new_customer_note_notification', array( &$this, 'trigger' ) );
// Call parent constuctor // Call parent constuctor
parent::__construct(); parent::__construct();
} }
/** /**
* trigger function. * trigger function.
* *
* @access public * @access public
* @return void * @return void
*/ */
function trigger( $args ) { function trigger( $args ) {
global $woocommerce; global $woocommerce;
if ( $args ) { if ( $args ) {
$defaults = array( $defaults = array(
'order_id' => '', 'order_id' => '',
'customer_note' => '' 'customer_note' => ''
); );
$args = wp_parse_args( $args, $defaults ); $args = wp_parse_args( $args, $defaults );
extract( $args ); extract( $args );
$this->object = new WC_Order( $order_id ); $this->object = new WC_Order( $order_id );
$this->recipient = $this->object->billing_email; $this->recipient = $this->object->billing_email;
$this->customer_note = $customer_note; $this->customer_note = $customer_note;
$this->find[] = '{order_date}'; $this->find[] = '{order_date}';
$this->replace[] = date_i18n( woocommerce_date_format(), strtotime( $this->object->order_date ) ); $this->replace[] = date_i18n( woocommerce_date_format(), strtotime( $this->object->order_date ) );
$this->find[] = '{order_number}'; $this->find[] = '{order_number}';
$this->replace[] = $this->object->get_order_number(); $this->replace[] = $this->object->get_order_number();
} }
if ( ! $this->is_enabled() || ! $this->get_recipient() ) if ( ! $this->is_enabled() || ! $this->get_recipient() )
return; return;
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() ); $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
} }
/** /**
* get_content_html function. * get_content_html function.
* *
* @access public * @access public
* @return string * @return string
*/ */
@ -94,10 +94,10 @@ class WC_Email_Customer_Note extends WC_Email {
) ); ) );
return ob_get_clean(); return ob_get_clean();
} }
/** /**
* get_content_plain function. * get_content_plain function.
* *
* @access public * @access public
* @return string * @return string
*/ */

View File

@ -23,41 +23,41 @@ class WC_Email_Customer_Processing_Order extends WC_Email {
$this->id = 'customer_processing_order'; $this->id = 'customer_processing_order';
$this->title = __( 'Processing order', 'woocommerce' ); $this->title = __( 'Processing order', 'woocommerce' );
$this->description = __( 'This is an order notification sent to the customer after payment containing order details.', 'woocommerce' ); $this->description = __( 'This is an order notification sent to the customer after payment containing order details.', 'woocommerce' );
$this->heading = __( 'Thank you for your order', 'woocommerce' ); $this->heading = __( 'Thank you for your order', 'woocommerce' );
$this->subject = __( 'Your {blogname} order receipt from {order_date}', 'woocommerce' ); $this->subject = __( 'Your {blogname} order receipt from {order_date}', 'woocommerce' );
$this->template_html = 'emails/customer-processing-order.php'; $this->template_html = 'emails/customer-processing-order.php';
$this->template_plain = 'emails/plain/customer-processing-order.php'; $this->template_plain = 'emails/plain/customer-processing-order.php';
// Triggers for this email // Triggers for this email
add_action( 'woocommerce_order_status_pending_to_processing_notification', array( &$this, 'trigger' ) ); add_action( 'woocommerce_order_status_pending_to_processing_notification', array( &$this, 'trigger' ) );
add_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( &$this, 'trigger' ) ); add_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( &$this, 'trigger' ) );
// Call parent constuctor // Call parent constuctor
parent::__construct(); parent::__construct();
} }
/** /**
* trigger function. * trigger function.
* *
* @access public * @access public
* @return void * @return void
*/ */
function trigger( $order_id ) { function trigger( $order_id ) {
global $woocommerce; global $woocommerce;
if ( $order_id ) { if ( $order_id ) {
$this->object = new WC_Order( $order_id ); $this->object = new WC_Order( $order_id );
$this->recipient = $this->object->billing_email; $this->recipient = $this->object->billing_email;
$this->find[] = '{order_date}'; $this->find[] = '{order_date}';
$this->replace[] = date_i18n( woocommerce_date_format(), strtotime( $this->object->order_date ) ); $this->replace[] = date_i18n( woocommerce_date_format(), strtotime( $this->object->order_date ) );
$this->find[] = '{order_number}'; $this->find[] = '{order_number}';
$this->replace[] = $this->object->get_order_number(); $this->replace[] = $this->object->get_order_number();
} }
if ( ! $this->is_enabled() || ! $this->get_recipient() ) if ( ! $this->is_enabled() || ! $this->get_recipient() )
return; return;
@ -66,7 +66,7 @@ class WC_Email_Customer_Processing_Order extends WC_Email {
/** /**
* get_content_html function. * get_content_html function.
* *
* @access public * @access public
* @return string * @return string
*/ */
@ -78,10 +78,10 @@ class WC_Email_Customer_Processing_Order extends WC_Email {
) ); ) );
return ob_get_clean(); return ob_get_clean();
} }
/** /**
* get_content_plain function. * get_content_plain function.
* *
* @access public * @access public
* @return string * @return string
*/ */

View File

@ -23,13 +23,13 @@ class WC_Email_New_Order extends WC_Email {
$this->id = 'new_order'; $this->id = 'new_order';
$this->title = __( 'New order', 'woocommerce' ); $this->title = __( 'New order', 'woocommerce' );
$this->description = __( 'New order emails are sent when an order is received/paid by a customer.', 'woocommerce' ); $this->description = __( 'New order emails are sent when an order is received/paid by a customer.', 'woocommerce' );
$this->heading = __( 'New customer order', 'woocommerce' ); $this->heading = __( 'New customer order', 'woocommerce' );
$this->subject = __( '[{blogname}] New customer order ({order_number}) - {order_date}', 'woocommerce' ); $this->subject = __( '[{blogname}] New customer order ({order_number}) - {order_date}', 'woocommerce' );
$this->template_html = 'emails/admin-new-order.php'; $this->template_html = 'emails/admin-new-order.php';
$this->template_plain = 'emails/plain/admin-new-order.php'; $this->template_plain = 'emails/plain/admin-new-order.php';
// Triggers for this email // Triggers for this email
add_action( 'woocommerce_order_status_pending_to_processing_notification', array( &$this, 'trigger' ) ); add_action( 'woocommerce_order_status_pending_to_processing_notification', array( &$this, 'trigger' ) );
add_action( 'woocommerce_order_status_pending_to_completed_notification', array( &$this, 'trigger' ) ); add_action( 'woocommerce_order_status_pending_to_completed_notification', array( &$this, 'trigger' ) );
@ -37,36 +37,36 @@ class WC_Email_New_Order extends WC_Email {
add_action( 'woocommerce_order_status_failed_to_processing_notification', array( &$this, 'trigger' ) ); add_action( 'woocommerce_order_status_failed_to_processing_notification', array( &$this, 'trigger' ) );
add_action( 'woocommerce_order_status_failed_to_completed_notification', array( &$this, 'trigger' ) ); add_action( 'woocommerce_order_status_failed_to_completed_notification', array( &$this, 'trigger' ) );
add_action( 'woocommerce_order_status_failed_to_on-hold_notification', array( &$this, 'trigger' ) ); add_action( 'woocommerce_order_status_failed_to_on-hold_notification', array( &$this, 'trigger' ) );
// Call parent constuctor // Call parent constuctor
parent::__construct(); parent::__construct();
// Other settings // Other settings
$this->recipient = $this->settings['recipient']; $this->recipient = $this->settings['recipient'];
if ( ! $this->recipient ) if ( ! $this->recipient )
$this->recipient = get_option( 'admin_email' ); $this->recipient = get_option( 'admin_email' );
} }
/** /**
* trigger function. * trigger function.
* *
* @access public * @access public
* @return void * @return void
*/ */
function trigger( $order_id ) { function trigger( $order_id ) {
global $woocommerce; global $woocommerce;
if ( $order_id ) { if ( $order_id ) {
$this->object = new WC_Order( $order_id ); $this->object = new WC_Order( $order_id );
$this->find[] = '{order_date}'; $this->find[] = '{order_date}';
$this->replace[] = date_i18n( woocommerce_date_format(), strtotime( $this->object->order_date ) ); $this->replace[] = date_i18n( woocommerce_date_format(), strtotime( $this->object->order_date ) );
$this->find[] = '{order_number}'; $this->find[] = '{order_number}';
$this->replace[] = $this->object->get_order_number(); $this->replace[] = $this->object->get_order_number();
} }
if ( ! $this->is_enabled() || ! $this->get_recipient() ) if ( ! $this->is_enabled() || ! $this->get_recipient() )
return; return;
@ -75,7 +75,7 @@ class WC_Email_New_Order extends WC_Email {
/** /**
* get_content_html function. * get_content_html function.
* *
* @access public * @access public
* @return string * @return string
*/ */
@ -87,10 +87,10 @@ class WC_Email_New_Order extends WC_Email {
) ); ) );
return ob_get_clean(); return ob_get_clean();
} }
/** /**
* get_content_plain function. * get_content_plain function.
* *
* @access public * @access public
* @return string * @return string
*/ */
@ -102,7 +102,7 @@ class WC_Email_New_Order extends WC_Email {
) ); ) );
return ob_get_clean(); return ob_get_clean();
} }
/** /**
* Initialise Settings Form Fields * Initialise Settings Form Fields
* *

View File

@ -26,40 +26,40 @@ class WC_Email extends WC_Settings_API {
/** @var string Description for the gateway. */ /** @var string Description for the gateway. */
var $description; var $description;
/** @var string plain text template path */ /** @var string plain text template path */
var $template_plain; var $template_plain;
/** @var string html template path */ /** @var string html template path */
var $template_html; var $template_html;
/** @var string template path */ /** @var string template path */
var $template_base; var $template_base;
/** @var string recipients for the email */ /** @var string recipients for the email */
var $recipient; var $recipient;
/** @var string heading for the email content */ /** @var string heading for the email content */
var $heading; var $heading;
/** @var string subject for the email */ /** @var string subject for the email */
var $subject; var $subject;
/** @var object this email is for, for example a customer, product, or email */ /** @var object this email is for, for example a customer, product, or email */
var $object; var $object;
/** @var array strings to find in subjects/headings */ /** @var array strings to find in subjects/headings */
var $find; var $find;
/** @var array strings to replace in subjects/headings */ /** @var array strings to replace in subjects/headings */
var $replace; var $replace;
/** @var string For multipart emails */ /** @var string For multipart emails */
var $mime_boundary; var $mime_boundary;
/** @var string For multipart emails */ /** @var string For multipart emails */
var $mime_boundary_header; var $mime_boundary_header;
/** @var bool true when email is being sent */ /** @var bool true when email is being sent */
var $sending; var $sending;
@ -75,7 +75,7 @@ class WC_Email extends WC_Settings_API {
// Init settings // Init settings
$this->init_form_fields(); $this->init_form_fields();
$this->init_settings(); $this->init_settings();
// Save settings hook // Save settings hook
add_action( 'woocommerce_update_options_email_' . $this->id, array( &$this, 'process_admin_options' ) ); add_action( 'woocommerce_update_options_email_' . $this->id, array( &$this, 'process_admin_options' ) );
@ -85,105 +85,105 @@ class WC_Email extends WC_Settings_API {
$this->subject = empty( $this->settings['subject'] ) ? $this->subject : $this->settings['subject']; $this->subject = empty( $this->settings['subject'] ) ? $this->subject : $this->settings['subject'];
$this->email_type = $this->settings['email_type']; $this->email_type = $this->settings['email_type'];
$this->enabled = $this->settings['enabled']; $this->enabled = $this->settings['enabled'];
// Find/replace // Find/replace
$this->find = array( '{blogname}' ); $this->find = array( '{blogname}' );
$this->replace = array( $this->get_blogname() ); $this->replace = array( $this->get_blogname() );
// For multipart messages // For multipart messages
add_filter( 'phpmailer_init', array( &$this, 'handle_multipart' ) ); add_filter( 'phpmailer_init', array( &$this, 'handle_multipart' ) );
} }
/** /**
* handle_multipart function. * handle_multipart function.
* *
* @access public * @access public
* @param mixed $mailer * @param mixed $mailer
* @return void * @return void
*/ */
function handle_multipart( $mailer ) { function handle_multipart( $mailer ) {
if ( $this->sending && $this->get_email_type() == 'multipart' ) { if ( $this->sending && $this->get_email_type() == 'multipart' ) {
$mailer->AltBody = wordwrap( html_entity_decode( strip_tags( $this->get_content_plain() ) ), 70 ); $mailer->AltBody = wordwrap( html_entity_decode( strip_tags( $this->get_content_plain() ) ), 70 );
$this->sending = false; $this->sending = false;
} }
return $mailer; return $mailer;
} }
/** /**
* format_string function. * format_string function.
* *
* @access public * @access public
* @param mixed $string * @param mixed $string
* @return string * @return string
*/ */
function format_string( $string ) { function format_string( $string ) {
return str_replace( $this->find, $this->replace, $string ); return str_replace( $this->find, $this->replace, $string );
} }
/** /**
* get_subject function. * get_subject function.
* *
* @access public * @access public
* @return string * @return string
*/ */
function get_subject() { function get_subject() {
return apply_filters( 'woocommerce_email_subject_' . $this->id, $this->format_string( $this->subject ), $this->object ); return apply_filters( 'woocommerce_email_subject_' . $this->id, $this->format_string( $this->subject ), $this->object );
} }
/** /**
* get_heading function. * get_heading function.
* *
* @access public * @access public
* @return string * @return string
*/ */
function get_heading() { function get_heading() {
return apply_filters( 'woocommerce_email_heading_' . $this->id, $this->format_string( $this->heading ), $this->object ); return apply_filters( 'woocommerce_email_heading_' . $this->id, $this->format_string( $this->heading ), $this->object );
} }
/** /**
* get_recipient function. * get_recipient function.
* *
* @access public * @access public
* @return string * @return string
*/ */
function get_recipient() { function get_recipient() {
return apply_filters( 'woocommerce_email_recipient_' . $this->id, $this->recipient, $this->object ); return apply_filters( 'woocommerce_email_recipient_' . $this->id, $this->recipient, $this->object );
} }
/** /**
* get_headers function. * get_headers function.
* *
* @access public * @access public
* @return string * @return string
*/ */
function get_headers() { function get_headers() {
return apply_filters( 'woocommerce_email_headers', "Content-Type: " . $this->get_content_type() . "\r\n", $this->id, $this->object ); return apply_filters( 'woocommerce_email_headers', "Content-Type: " . $this->get_content_type() . "\r\n", $this->id, $this->object );
} }
/** /**
* get_attachments function. * get_attachments function.
* *
* @access public * @access public
* @return string * @return string
*/ */
function get_attachments() { function get_attachments() {
return apply_filters( 'woocommerce_email_attachments', '', $this->id, $this->object ); return apply_filters( 'woocommerce_email_attachments', '', $this->id, $this->object );
} }
/** /**
* get_type function. * get_type function.
* *
* @access public * @access public
* @return string * @return string
*/ */
function get_email_type() { function get_email_type() {
return $this->email_type ? $this->email_type : 'plain'; return $this->email_type ? $this->email_type : 'plain';
} }
/** /**
* get_content_type function. * get_content_type function.
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -197,7 +197,7 @@ class WC_Email extends WC_Settings_API {
return 'text/plain'; return 'text/plain';
} }
} }
/** /**
* Checks if this email is enabled and will be sent. * Checks if this email is enabled and will be sent.
* *
@ -208,10 +208,10 @@ class WC_Email extends WC_Settings_API {
if ( $this->enabled == "yes" ) if ( $this->enabled == "yes" )
return true; return true;
} }
/** /**
* get_blogname function. * get_blogname function.
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -221,14 +221,14 @@ class WC_Email extends WC_Settings_API {
/** /**
* get_content function. * get_content function.
* *
* @access public * @access public
* @return string * @return string
*/ */
function get_content() { function get_content() {
$this->sending = true; $this->sending = true;
if ( $this->get_email_type() == 'plain' ) { if ( $this->get_email_type() == 'plain' ) {
$email_content = html_entity_decode( strip_tags( $this->get_content_plain() ) ); $email_content = html_entity_decode( strip_tags( $this->get_content_plain() ) );
} else { } else {
@ -237,66 +237,66 @@ class WC_Email extends WC_Settings_API {
return $email_content; return $email_content;
} }
/** /**
* Apply inline styles to dynamic content. * Apply inline styles to dynamic content.
* *
* @access public * @access public
* @param mixed $content * @param mixed $content
* @return void * @return void
*/ */
function style_inline( $content ) { function style_inline( $content ) {
if ( ! class_exists( 'DOMDocument' ) ) if ( ! class_exists( 'DOMDocument' ) )
return $content; return $content;
$dom = new DOMDocument(); $dom = new DOMDocument();
@$dom->loadHTML( $content ); @$dom->loadHTML( $content );
$nodes = $dom->getElementsByTagName('img'); $nodes = $dom->getElementsByTagName('img');
foreach( $nodes as $node ) foreach( $nodes as $node )
if ( ! $node->hasAttribute( 'style' ) ) if ( ! $node->hasAttribute( 'style' ) )
$node->setAttribute( "style", "display:inline; border:none; font-size:14px; font-weight:bold; height:auto; line-height:100%; outline:none; text-decoration:none; text-transform:capitalize;" ); $node->setAttribute( "style", "display:inline; border:none; font-size:14px; font-weight:bold; height:auto; line-height:100%; outline:none; text-decoration:none; text-transform:capitalize;" );
$nodes_h1 = $dom->getElementsByTagName('h1'); $nodes_h1 = $dom->getElementsByTagName('h1');
$nodes_h2 = $dom->getElementsByTagName('h2'); $nodes_h2 = $dom->getElementsByTagName('h2');
$nodes_h3 = $dom->getElementsByTagName('h3'); $nodes_h3 = $dom->getElementsByTagName('h3');
foreach( $nodes_h1 as $node ) foreach( $nodes_h1 as $node )
if ( ! $node->hasAttribute( 'style' ) ) if ( ! $node->hasAttribute( 'style' ) )
$node->setAttribute( "style", "color: " . get_option( 'woocommerce_email_text_color' ) . "; display:block; font-family:Arial; font-size:34px; font-weight:bold; margin-top: 10px; margin-right:0; margin-bottom:10px; margin-left:0; text-align:left; line-height: 150%;" ); $node->setAttribute( "style", "color: " . get_option( 'woocommerce_email_text_color' ) . "; display:block; font-family:Arial; font-size:34px; font-weight:bold; margin-top: 10px; margin-right:0; margin-bottom:10px; margin-left:0; text-align:left; line-height: 150%;" );
foreach( $nodes_h2 as $node ) foreach( $nodes_h2 as $node )
if ( ! $node->hasAttribute( 'style' ) ) if ( ! $node->hasAttribute( 'style' ) )
$node->setAttribute( "style", "color: " . get_option( 'woocommerce_email_text_color' ) . "; display:block; font-family:Arial; font-size:30px; font-weight:bold; margin-top: 10px; margin-right:0; margin-bottom:10px; margin-left:0; text-align:left; line-height: 150%;" ); $node->setAttribute( "style", "color: " . get_option( 'woocommerce_email_text_color' ) . "; display:block; font-family:Arial; font-size:30px; font-weight:bold; margin-top: 10px; margin-right:0; margin-bottom:10px; margin-left:0; text-align:left; line-height: 150%;" );
foreach( $nodes_h3 as $node ) foreach( $nodes_h3 as $node )
if ( ! $node->hasAttribute( 'style' ) ) if ( ! $node->hasAttribute( 'style' ) )
$node->setAttribute( "style", "color: " . get_option( 'woocommerce_email_text_color' ) . "; display:block; font-family:Arial; font-size:26px; font-weight:bold; margin-top: 10px; margin-right:0; margin-bottom:10px; margin-left:0; text-align:left; line-height: 150%;" ); $node->setAttribute( "style", "color: " . get_option( 'woocommerce_email_text_color' ) . "; display:block; font-family:Arial; font-size:26px; font-weight:bold; margin-top: 10px; margin-right:0; margin-bottom:10px; margin-left:0; text-align:left; line-height: 150%;" );
$nodes = $dom->getElementsByTagName('a'); $nodes = $dom->getElementsByTagName('a');
foreach( $nodes as $node ) foreach( $nodes as $node )
if ( ! $node->hasAttribute( 'style' ) ) if ( ! $node->hasAttribute( 'style' ) )
$node->setAttribute( "style", "color: " . get_option( 'woocommerce_email_text_color' ) . "; font-weight:normal; text-decoration:underline;" ); $node->setAttribute( "style", "color: " . get_option( 'woocommerce_email_text_color' ) . "; font-weight:normal; text-decoration:underline;" );
$content = $dom->saveHTML(); $content = $dom->saveHTML();
return $content; return $content;
} }
/** /**
* get_content_plain function. * get_content_plain function.
* *
* @access public * @access public
* @return void * @return void
*/ */
function get_content_plain() {} function get_content_plain() {}
/** /**
* get_content_html function. * get_content_html function.
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -321,7 +321,7 @@ class WC_Email extends WC_Settings_API {
function get_from_address() { function get_from_address() {
return sanitize_email( get_option( 'woocommerce_email_from_address' ) ); return sanitize_email( get_option( 'woocommerce_email_from_address' ) );
} }
/** /**
* Send the email. * Send the email.
* *
@ -337,14 +337,14 @@ class WC_Email extends WC_Settings_API {
add_filter( 'wp_mail_from', array( &$this, 'get_from_address' ) ); add_filter( 'wp_mail_from', array( &$this, 'get_from_address' ) );
add_filter( 'wp_mail_from_name', array( &$this, 'get_from_name' ) ); add_filter( 'wp_mail_from_name', array( &$this, 'get_from_name' ) );
add_filter( 'wp_mail_content_type', array( &$this, 'get_content_type' ) ); add_filter( 'wp_mail_content_type', array( &$this, 'get_content_type' ) );
wp_mail( $to, $subject, $message, $headers, $attachments ); wp_mail( $to, $subject, $message, $headers, $attachments );
remove_filter( 'wp_mail_from', array( &$this, 'get_from_address' ) ); remove_filter( 'wp_mail_from', array( &$this, 'get_from_address' ) );
remove_filter( 'wp_mail_from_name', array( &$this, 'get_from_name' ) ); remove_filter( 'wp_mail_from_name', array( &$this, 'get_from_name' ) );
remove_filter( 'wp_mail_content_type', array( &$this, 'get_content_type' ) ); remove_filter( 'wp_mail_content_type', array( &$this, 'get_content_type' ) );
} }
/** /**
* Initialise Settings Form Fields - these are generic email options most will use. * Initialise Settings Form Fields - these are generic email options most will use.
* *
@ -387,7 +387,7 @@ class WC_Email extends WC_Settings_API {
) )
); );
} }
/** /**
* Admin Panel Options Processing * Admin Panel Options Processing
* - Saves the options to the DB * - Saves the options to the DB
@ -397,17 +397,17 @@ class WC_Email extends WC_Settings_API {
* @return bool * @return bool
*/ */
public function process_admin_options() { public function process_admin_options() {
// Save regular options // Save regular options
parent::process_admin_options(); parent::process_admin_options();
// Save templates // Save templates
if ( ! empty( $_POST['template_html_code'] ) && ! empty( $this->template_html ) ) { if ( ! empty( $_POST['template_html_code'] ) && ! empty( $this->template_html ) ) {
$saved = false; $saved = false;
$file = get_stylesheet_directory() . '/woocommerce/' . $this->template_html; $file = get_stylesheet_directory() . '/woocommerce/' . $this->template_html;
$code = stripslashes( $_POST['template_html_code'] ); $code = stripslashes( $_POST['template_html_code'] );
if ( is_writeable( $file ) ) { if ( is_writeable( $file ) ) {
$f = fopen( $file, 'w+' ); $f = fopen( $file, 'w+' );
if ( $f !== FALSE ) { if ( $f !== FALSE ) {
@ -416,19 +416,19 @@ class WC_Email extends WC_Settings_API {
$saved = true; $saved = true;
} }
} }
if ( ! $saved ) { if ( ! $saved ) {
$redirect = add_query_arg( 'wc_error', urlencode( __( 'Could not write to template file.', 'woocommerce' ) ) ); $redirect = add_query_arg( 'wc_error', urlencode( __( 'Could not write to template file.', 'woocommerce' ) ) );
wp_redirect( $redirect ); wp_redirect( $redirect );
exit; exit;
} }
} }
if ( ! empty( $_POST['template_plain_code'] ) && ! empty( $this->template_plain ) ) { if ( ! empty( $_POST['template_plain_code'] ) && ! empty( $this->template_plain ) ) {
$saved = false; $saved = false;
$file = get_stylesheet_directory() . '/woocommerce/' . $this->template_plain; $file = get_stylesheet_directory() . '/woocommerce/' . $this->template_plain;
$code = stripslashes( $_POST['template_plain_code'] ); $code = stripslashes( $_POST['template_plain_code'] );
if ( is_writeable( $file ) ) { if ( is_writeable( $file ) ) {
$f = fopen( $file, 'w+' ); $f = fopen( $file, 'w+' );
if ( $f !== FALSE ) { if ( $f !== FALSE ) {
@ -437,15 +437,15 @@ class WC_Email extends WC_Settings_API {
$saved = true; $saved = true;
} }
} }
if ( ! $saved ) { if ( ! $saved ) {
$redirect = add_query_arg( 'wc_error', __( 'Could not write to template file.', 'woocommerce' ) ); $redirect = add_query_arg( 'wc_error', __( 'Could not write to template file.', 'woocommerce' ) );
wp_redirect( $redirect ); wp_redirect( $redirect );
exit; exit;
} }
} }
} }
/** /**
* Admin Options * Admin Options
* *
@ -456,12 +456,12 @@ class WC_Email extends WC_Settings_API {
* @access public * @access public
* @return void * @return void
*/ */
function admin_options() { function admin_options() {
global $woocommerce; global $woocommerce;
// Handle any actions // Handle any actions
if ( ! empty( $this->template_html ) || ! empty( $this->template_plain ) ) { if ( ! empty( $this->template_html ) || ! empty( $this->template_plain ) ) {
if ( ! empty( $_GET['move_template'] ) && ( $template = esc_attr( basename( $_GET['move_template'] ) ) ) ) { if ( ! empty( $_GET['move_template'] ) && ( $template = esc_attr( basename( $_GET['move_template'] ) ) ) ) {
if ( ! empty( $this->$template ) ) { if ( ! empty( $this->$template ) ) {
if ( wp_mkdir_p( dirname( get_stylesheet_directory() . '/woocommerce/' . $this->$template ) ) && ! file_exists( get_stylesheet_directory() . '/woocommerce/' . $this->$template ) ) { if ( wp_mkdir_p( dirname( get_stylesheet_directory() . '/woocommerce/' . $this->$template ) ) && ! file_exists( get_stylesheet_directory() . '/woocommerce/' . $this->$template ) ) {
@ -470,7 +470,7 @@ class WC_Email extends WC_Settings_API {
} }
} }
} }
if ( ! empty( $_GET['delete_template'] ) && ( $template = esc_attr( basename( $_GET['delete_template'] ) ) ) ) { if ( ! empty( $_GET['delete_template'] ) && ( $template = esc_attr( basename( $_GET['delete_template'] ) ) ) ) {
if ( ! empty( $this->$template ) ) { if ( ! empty( $this->$template ) ) {
if ( file_exists( get_stylesheet_directory() . '/woocommerce/' . $this->$template ) ) { if ( file_exists( get_stylesheet_directory() . '/woocommerce/' . $this->$template ) ) {
@ -479,9 +479,9 @@ class WC_Email extends WC_Settings_API {
} }
} }
} }
} }
?> ?>
<h3><?php echo ( ! empty( $this->title ) ) ? $this->title : __( 'Settings','woocommerce' ) ; ?></h3> <h3><?php echo ( ! empty( $this->title ) ) ? $this->title : __( 'Settings','woocommerce' ) ; ?></h3>
@ -490,67 +490,67 @@ class WC_Email extends WC_Settings_API {
<table class="form-table"> <table class="form-table">
<?php $this->generate_settings_html(); ?> <?php $this->generate_settings_html(); ?>
</table> </table>
<?php if ( ! empty( $this->template_html ) || ! empty( $this->template_plain ) ) { ?> <?php if ( ! empty( $this->template_html ) || ! empty( $this->template_plain ) ) { ?>
<div id="template"> <div id="template">
<?php <?php
$templates = array( $templates = array(
'template_html' => __( 'HTML template', 'woocommerce' ), 'template_html' => __( 'HTML template', 'woocommerce' ),
'template_plain' => __( 'Plain text template', 'woocommerce' ) 'template_plain' => __( 'Plain text template', 'woocommerce' )
); );
foreach ( $templates as $template => $title ) : foreach ( $templates as $template => $title ) :
if ( empty( $this->$template ) ) if ( empty( $this->$template ) )
continue; continue;
$local_file = get_stylesheet_directory() . '/woocommerce/' . $this->$template; $local_file = get_stylesheet_directory() . '/woocommerce/' . $this->$template;
$core_file = $this->template_base . $this->$template; $core_file = $this->template_base . $this->$template;
?> ?>
<div class="template <?php echo $template; ?>"> <div class="template <?php echo $template; ?>">
<h4><?php echo wp_kses_post( $title ); ?></h4> <h4><?php echo wp_kses_post( $title ); ?></h4>
<?php if ( file_exists( $local_file ) ) : ?> <?php if ( file_exists( $local_file ) ) : ?>
<p> <p>
<a href="#" class="button toggle_editor"></a> <a href="#" class="button toggle_editor"></a>
<?php if ( is_writable( $local_file ) ) : ?> <?php if ( is_writable( $local_file ) ) : ?>
<a href="<?php echo remove_query_arg( array( 'move_template', 'saved' ), add_query_arg( 'delete_template', $template ) ); ?>" class="delete_template button"><?php _e( 'Delete template file', 'woocommerce' ); ?></a> <a href="<?php echo remove_query_arg( array( 'move_template', 'saved' ), add_query_arg( 'delete_template', $template ) ); ?>" class="delete_template button"><?php _e( 'Delete template file', 'woocommerce' ); ?></a>
<?php endif; ?> <?php endif; ?>
<?php printf( __( 'This template has been overridden by your theme and can be found in: <code>%s</code>.', 'woocommerce' ), 'yourtheme/woocommerce/' . $this->$template ); ?> <?php printf( __( 'This template has been overridden by your theme and can be found in: <code>%s</code>.', 'woocommerce' ), 'yourtheme/woocommerce/' . $this->$template ); ?>
</p> </p>
<div class="editor" style="display:none"> <div class="editor" style="display:none">
<textarea class="code" cols="25" rows="20" <?php if ( ! is_writable( $local_file ) ) : ?>readonly="readonly" disabled="disabled"<?php else : ?>data-name="<?php echo $template . '_code'; ?>"<?php endif; ?>><?php echo file_get_contents( $local_file ); ?></textarea> <textarea class="code" cols="25" rows="20" <?php if ( ! is_writable( $local_file ) ) : ?>readonly="readonly" disabled="disabled"<?php else : ?>data-name="<?php echo $template . '_code'; ?>"<?php endif; ?>><?php echo file_get_contents( $local_file ); ?></textarea>
</div> </div>
<?php elseif ( file_exists( $core_file ) ) : ?> <?php elseif ( file_exists( $core_file ) ) : ?>
<p> <p>
<a href="#" class="button toggle_editor"></a> <a href="#" class="button toggle_editor"></a>
<?php if ( ( is_dir( get_stylesheet_directory() . '/woocommerce/emails/' ) && is_writable( get_stylesheet_directory() . '/woocommerce/emails/' ) ) || is_writable( get_stylesheet_directory() ) ) : ?> <?php if ( ( is_dir( get_stylesheet_directory() . '/woocommerce/emails/' ) && is_writable( get_stylesheet_directory() . '/woocommerce/emails/' ) ) || is_writable( get_stylesheet_directory() ) ) : ?>
<a href="<?php echo remove_query_arg( array( 'delete_template', 'saved' ), add_query_arg( 'move_template', $template ) ); ?>" class="button"><?php _e( 'Copy file to theme', 'woocommerce' ); ?></a> <a href="<?php echo remove_query_arg( array( 'delete_template', 'saved' ), add_query_arg( 'move_template', $template ) ); ?>" class="button"><?php _e( 'Copy file to theme', 'woocommerce' ); ?></a>
<?php endif; ?> <?php endif; ?>
<?php printf( __( 'To override and edit this email template copy <code>%s</code> to your theme folder: <code>%s</code>.', 'woocommerce' ), 'woocommerce/templates/' . $this->$template, 'yourtheme/woocommerce/' . $this->$template ); ?> <?php printf( __( 'To override and edit this email template copy <code>%s</code> to your theme folder: <code>%s</code>.', 'woocommerce' ), 'woocommerce/templates/' . $this->$template, 'yourtheme/woocommerce/' . $this->$template ); ?>
</p> </p>
<div class="editor" style="display:none"> <div class="editor" style="display:none">
<textarea class="code" readonly="readonly" disabled="disabled" cols="25" rows="20"><?php echo file_get_contents( $core_file ); ?></textarea> <textarea class="code" readonly="readonly" disabled="disabled" cols="25" rows="20"><?php echo file_get_contents( $core_file ); ?></textarea>
</div> </div>
<?php else : ?> <?php else : ?>
<p><?php _e( 'File was not found.', 'woocommerce' ); ?></p> <p><?php _e( 'File was not found.', 'woocommerce' ); ?></p>
<?php endif; ?> <?php endif; ?>
</div> </div>
<?php <?php
endforeach; endforeach;
@ -559,22 +559,22 @@ class WC_Email extends WC_Settings_API {
<?php <?php
$woocommerce->add_inline_js(" $woocommerce->add_inline_js("
jQuery('select.email_type').change(function(){ jQuery('select.email_type').change(function(){
var val = jQuery( this ).val(); var val = jQuery( this ).val();
jQuery('.template_plain, .template_html').show(); jQuery('.template_plain, .template_html').show();
if ( val != 'multipart' && val != 'html' ) if ( val != 'multipart' && val != 'html' )
jQuery('.template_html').hide(); jQuery('.template_html').hide();
if ( val != 'multipart' && val != 'plain' ) if ( val != 'multipart' && val != 'plain' )
jQuery('.template_plain').hide(); jQuery('.template_plain').hide();
}).change(); }).change();
var view = '" . __( 'View template', 'woocommerce' ) . "'; var view = '" . __( 'View template', 'woocommerce' ) . "';
var hide = '" . __( 'Hide template', 'woocommerce' ) . "'; var hide = '" . __( 'Hide template', 'woocommerce' ) . "';
jQuery('a.toggle_editor').text( view ).toggle( function() { jQuery('a.toggle_editor').text( view ).toggle( function() {
jQuery( this ).text( hide ).closest('.template').find('.editor').slideToggle(); jQuery( this ).text( hide ).closest('.template').find('.editor').slideToggle();
return false; return false;
@ -582,19 +582,19 @@ class WC_Email extends WC_Settings_API {
jQuery( this ).text( view ).closest('.template').find('.editor').slideToggle(); jQuery( this ).text( view ).closest('.template').find('.editor').slideToggle();
return false; return false;
} ); } );
jQuery('a.delete_template').click(function(){ jQuery('a.delete_template').click(function(){
var answer = confirm('" . __( 'Are you sure you want to delete this template file?', 'woocommerce' ) . "'); var answer = confirm('" . __( 'Are you sure you want to delete this template file?', 'woocommerce' ) . "');
if (answer) if (answer)
return true; return true;
return false; return false;
}); });
jQuery('.editor textarea').change(function(){ jQuery('.editor textarea').change(function(){
var name = jQuery(this).attr( 'data-name' ); var name = jQuery(this).attr( 'data-name' );
if ( name ) if ( name )
jQuery(this).attr( 'name', name ); jQuery(this).attr( 'name', name );
}); });

View File

@ -10,13 +10,13 @@
* @author WooThemes * @author WooThemes
*/ */
class WC_Emails { class WC_Emails {
/** /**
* @var array Array of email notification classes. * @var array Array of email notification classes.
* @access public * @access public
*/ */
public $emails; public $emails;
/** /**
* @var string Stores the emailer's address. * @var string Stores the emailer's address.
* @access private * @access private
@ -28,7 +28,7 @@ class WC_Emails {
* @access private * @access private
*/ */
private $_from_name; private $_from_name;
/** /**
* @var mixed Content type for sent emails * @var mixed Content type for sent emails
* @access private * @access private
@ -42,7 +42,7 @@ class WC_Emails {
* @return void * @return void
*/ */
function __construct() { function __construct() {
// Include email classes // Include email classes
include_once( 'class-wc-email.php' ); include_once( 'class-wc-email.php' );
include_once( 'class-wc-email-customer-completed-order.php' ); include_once( 'class-wc-email-customer-completed-order.php' );
@ -52,7 +52,7 @@ class WC_Emails {
include_once( 'class-wc-email-customer-reset-password.php' ); include_once( 'class-wc-email-customer-reset-password.php' );
include_once( 'class-wc-email-customer-processing-order.php' ); include_once( 'class-wc-email-customer-processing-order.php' );
include_once( 'class-wc-email-new-order.php' ); include_once( 'class-wc-email-new-order.php' );
$this->emails['WC_Email_New_Order'] = new WC_Email_New_Order(); $this->emails['WC_Email_New_Order'] = new WC_Email_New_Order();
$this->emails['WC_Email_Customer_Processing_Order'] = new WC_Email_Customer_Processing_Order(); $this->emails['WC_Email_Customer_Processing_Order'] = new WC_Email_Customer_Processing_Order();
$this->emails['WC_Email_Customer_Completed_Order'] = new WC_Email_Customer_Completed_Order(); $this->emails['WC_Email_Customer_Completed_Order'] = new WC_Email_Customer_Completed_Order();
@ -60,7 +60,7 @@ class WC_Emails {
$this->emails['WC_Email_Customer_Note'] = new WC_Email_Customer_Note(); $this->emails['WC_Email_Customer_Note'] = new WC_Email_Customer_Note();
$this->emails['WC_Email_Customer_Reset_Password'] = new WC_Email_Customer_Reset_Password(); $this->emails['WC_Email_Customer_Reset_Password'] = new WC_Email_Customer_Reset_Password();
$this->emails['WC_Email_Customer_New_Account'] = new WC_Email_Customer_New_Account(); $this->emails['WC_Email_Customer_New_Account'] = new WC_Email_Customer_New_Account();
$this->emails = apply_filters( 'woocommerce_email_classes', $this->emails ); $this->emails = apply_filters( 'woocommerce_email_classes', $this->emails );
// Email Header, Footer and content hooks // Email Header, Footer and content hooks
@ -72,14 +72,14 @@ class WC_Emails {
add_action( 'woocommerce_low_stock_notification', array( &$this, 'low_stock' ) ); add_action( 'woocommerce_low_stock_notification', array( &$this, 'low_stock' ) );
add_action( 'woocommerce_no_stock_notification', array( &$this, 'no_stock' ) ); add_action( 'woocommerce_no_stock_notification', array( &$this, 'no_stock' ) );
add_action( 'woocommerce_product_on_backorder_notification', array( &$this, 'backorder' )); add_action( 'woocommerce_product_on_backorder_notification', array( &$this, 'backorder' ));
// Let 3rd parties unhook the above via this hook // Let 3rd parties unhook the above via this hook
do_action( 'woocommerce_email', $this ); do_action( 'woocommerce_email', $this );
} }
/** /**
* Return the email classes - used in admin to load settings. * Return the email classes - used in admin to load settings.
* *
* @access public * @access public
* @return array * @return array
*/ */
@ -96,7 +96,7 @@ class WC_Emails {
function get_from_name() { function get_from_name() {
if ( ! $this->_from_name ) if ( ! $this->_from_name )
$this->_from_name = get_option( 'woocommerce_email_from_name' ); $this->_from_name = get_option( 'woocommerce_email_from_name' );
return $this->_from_name; return $this->_from_name;
} }
@ -109,7 +109,7 @@ class WC_Emails {
function get_from_address() { function get_from_address() {
if ( ! $this->_from_address ) if ( ! $this->_from_address )
$this->_from_address = get_option( 'woocommerce_email_from_address' ); $this->_from_address = get_option( 'woocommerce_email_from_address' );
return $this->_from_address; return $this->_from_address;
} }
@ -181,15 +181,15 @@ class WC_Emails {
* @return void * @return void
*/ */
function send( $to, $subject, $message, $headers = "Content-Type: text/html\r\n", $attachments = "", $content_type = 'text/html' ) { function send( $to, $subject, $message, $headers = "Content-Type: text/html\r\n", $attachments = "", $content_type = 'text/html' ) {
// Set content type // Set content type
$this->_content_type = $content_type; $this->_content_type = $content_type;
// Filters for the email // Filters for the email
add_filter( 'wp_mail_from', array( &$this, 'get_from_address' ) ); add_filter( 'wp_mail_from', array( &$this, 'get_from_address' ) );
add_filter( 'wp_mail_from_name', array( &$this, 'get_from_name' ) ); add_filter( 'wp_mail_from_name', array( &$this, 'get_from_name' ) );
add_filter( 'wp_mail_content_type', array( &$this, 'get_content_type' ) ); add_filter( 'wp_mail_content_type', array( &$this, 'get_content_type' ) );
// Send // Send
wp_mail( $to, $subject, $message, $headers, $attachments ); wp_mail( $to, $subject, $message, $headers, $attachments );
@ -198,7 +198,7 @@ class WC_Emails {
remove_filter( 'wp_mail_from_name', array( &$this, 'get_from_name' ) ); remove_filter( 'wp_mail_from_name', array( &$this, 'get_from_name' ) );
remove_filter( 'wp_mail_content_type', array( &$this, 'get_content_type' ) ); remove_filter( 'wp_mail_content_type', array( &$this, 'get_content_type' ) );
} }
/** /**
* Prepare and send the customer invoice email on demand. * Prepare and send the customer invoice email on demand.
* *
@ -210,7 +210,7 @@ class WC_Emails {
$email = $this->emails['WC_Email_Customer_Invoice']; $email = $this->emails['WC_Email_Customer_Invoice'];
$email->trigger( $order ); $email->trigger( $order );
} }
/** /**
* Customer new account welcome email. * Customer new account welcome email.
* *
@ -220,16 +220,16 @@ class WC_Emails {
* @return void * @return void
*/ */
function customer_new_account( $user_id, $plaintext_pass ) { function customer_new_account( $user_id, $plaintext_pass ) {
if ( ! $user_id || ! $plaintext_pass) if ( ! $user_id || ! $plaintext_pass)
return; return;
$email = $this->emails['WC_Email_Customer_New_Account']; $email = $this->emails['WC_Email_Customer_New_Account'];
$email->trigger( $user_id, $plaintext_pass ); $email->trigger( $user_id, $plaintext_pass );
} }
/** /**
* Add order meta to email templates. * Add order meta to email templates.
* *
* @access public * @access public
* @param mixed $order * @param mixed $order
* @param bool $sent_to_admin (default: false) * @param bool $sent_to_admin (default: false)
@ -244,20 +244,20 @@ class WC_Emails {
if ( $order->customer_note ) if ( $order->customer_note )
$meta[ __( 'Note', 'woocommerce' ) ] = wptexturize( $order->customer_note ); $meta[ __( 'Note', 'woocommerce' ) ] = wptexturize( $order->customer_note );
if ( $show_fields ) if ( $show_fields )
foreach ( $show_fields as $field ) { foreach ( $show_fields as $field ) {
$value = get_post_meta( $order->id, $field, true ); $value = get_post_meta( $order->id, $field, true );
if ( $value ) if ( $value )
$meta[ ucwords( esc_attr( $field ) ) ] = wptexturize( $value ); $meta[ ucwords( esc_attr( $field ) ) ] = wptexturize( $value );
} }
if ( sizeof( $meta ) > 0 ) { if ( sizeof( $meta ) > 0 ) {
if ( $plain_text ) { if ( $plain_text ) {
foreach ( $meta as $key => $value ) foreach ( $meta as $key => $value )
echo $key . ': ' . $value . "\n"; echo $key . ': ' . $value . "\n";
} else { } else {
foreach ( $meta as $key => $value ) foreach ( $meta as $key => $value )

View File

@ -69,13 +69,13 @@ class WC_COD extends WC_Payment_Gateway {
*/ */
function init_form_fields() { function init_form_fields() {
global $woocommerce; global $woocommerce;
$shipping_methods = array(); $shipping_methods = array();
foreach ( $woocommerce->shipping->load_shipping_methods() as $method ) { foreach ( $woocommerce->shipping->load_shipping_methods() as $method ) {
$shipping_methods[ $method->id ] = $method->get_title(); $shipping_methods[ $method->id ] = $method->get_title();
} }
$this->form_fields = array( $this->form_fields = array(
'enabled' => array( 'enabled' => array(
'title' => __( 'Enable COD', 'woocommerce' ), 'title' => __( 'Enable COD', 'woocommerce' ),
@ -123,41 +123,41 @@ class WC_COD extends WC_Payment_Gateway {
*/ */
function is_available() { function is_available() {
global $woocommerce; global $woocommerce;
if ( ! empty( $this->enable_for_methods ) ) { if ( ! empty( $this->enable_for_methods ) ) {
if ( is_page( woocommerce_get_page_id( 'pay' ) ) ) { if ( is_page( woocommerce_get_page_id( 'pay' ) ) ) {
$order_id = (int) $_GET['order_id']; $order_id = (int) $_GET['order_id'];
$order = new WC_Order( $order_id ); $order = new WC_Order( $order_id );
if ( ! $order->shipping_method ) if ( ! $order->shipping_method )
return false; return false;
$chosen_method = $order->shipping_method; $chosen_method = $order->shipping_method;
} elseif ( empty( $woocommerce->session->chosen_shipping_method ) ) { } elseif ( empty( $woocommerce->session->chosen_shipping_method ) ) {
return false; return false;
} else { } else {
$chosen_method = $woocommerce->session->chosen_shipping_method; $chosen_method = $woocommerce->session->chosen_shipping_method;
} }
$found = false; $found = false;
foreach ( $this->enable_for_methods as $method_id ) { foreach ( $this->enable_for_methods as $method_id ) {
if ( strpos( $chosen_method, $method_id ) === 0 ) { if ( strpos( $chosen_method, $method_id ) === 0 ) {
$found = true; $found = true;
break; break;
} }
} }
if ( ! $found ) if ( ! $found )
return false; return false;
} }
return parent::is_available(); return parent::is_available();
} }
/** /**
* Process the payment and return the result * Process the payment and return the result

View File

@ -231,16 +231,16 @@ class WC_Mijireh_Checkout extends WC_Payment_Gateway {
// add items to order // add items to order
$items = $wc_order->get_items(); $items = $wc_order->get_items();
foreach( $items as $item ) { foreach( $items as $item ) {
$product = $wc_order->get_product_from_item( $item ); $product = $wc_order->get_product_from_item( $item );
$mj_order->add_item( $item['name'], $wc_order->get_item_subtotal( $item, false, false ), $item['qty'], $product->get_sku() ); $mj_order->add_item( $item['name'], $wc_order->get_item_subtotal( $item, false, false ), $item['qty'], $product->get_sku() );
} }
// Handle fees // Handle fees
$items = $wc_order->get_fees(); $items = $wc_order->get_fees();
foreach( $items as $item ) { foreach( $items as $item ) {
$mj_order->add_item( $item['name'], $item['line_total'], 1, '' ); $mj_order->add_item( $item['name'], $item['line_total'], 1, '' );
} }
@ -290,10 +290,10 @@ class WC_Mijireh_Checkout extends WC_Payment_Gateway {
// Set URL for mijireh payment notificatoin - use WC API // Set URL for mijireh payment notificatoin - use WC API
$mj_order->return_url = str_replace( 'https:', 'http:', add_query_arg( 'wc-api', 'WC_Mijireh_Checkout', home_url( '/' ) ) ); $mj_order->return_url = str_replace( 'https:', 'http:', add_query_arg( 'wc-api', 'WC_Mijireh_Checkout', home_url( '/' ) ) );
// Identify woocommerce // Identify woocommerce
$mj_order->partner_id = 'woo'; $mj_order->partner_id = 'woo';
try { try {
$mj_order->create(); $mj_order->create();
$result = array( $result = array(

View File

@ -3,11 +3,11 @@
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class Mijireh_Address extends Mijireh_Model { class Mijireh_Address extends Mijireh_Model {
public function __construct() { public function __construct() {
$this->init(); $this->init();
} }
public function init() { public function init() {
$this->_data = array( $this->_data = array(
'first_name' => '', 'first_name' => '',
@ -22,15 +22,15 @@ class Mijireh_Address extends Mijireh_Model {
'phone' => '' 'phone' => ''
); );
} }
public function validate() { public function validate() {
$is_valid = $this->_check_required_fields(); $is_valid = $this->_check_required_fields();
return $is_valid; return $is_valid;
} }
/** /**
* Return true if all of the required fields have a non-empty value * Return true if all of the required fields have a non-empty value
* *
* @return boolean * @return boolean
*/ */
private function _check_required_fields() { private function _check_required_fields() {
@ -44,5 +44,5 @@ class Mijireh_Address extends Mijireh_Model {
} }
return $pass; return $pass;
} }
} }

View File

@ -3,7 +3,7 @@
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class Mijireh_Item extends Mijireh_Model { class Mijireh_Item extends Mijireh_Model {
private function _init() { private function _init() {
$this->_data = array( $this->_data = array(
'name' => null, 'name' => null,
@ -12,27 +12,27 @@ class Mijireh_Item extends Mijireh_Model {
'sku' => null 'sku' => null
); );
} }
private function _check_required_fields() { private function _check_required_fields() {
if(empty($this->_data['name'])) { if(empty($this->_data['name'])) {
$this->add_error('item name is required.'); $this->add_error('item name is required.');
} }
if(!is_numeric($this->_data['price'])) { if(!is_numeric($this->_data['price'])) {
$this->add_error('price must be a number.'); $this->add_error('price must be a number.');
} }
} }
private function _check_quantity() { private function _check_quantity() {
if($this->_data['quantity'] < 1) { if($this->_data['quantity'] < 1) {
$this->add_error('quantity must be greater than or equal to 1'); $this->add_error('quantity must be greater than or equal to 1');
} }
} }
public function __construct() { public function __construct() {
$this->_init(); $this->_init();
} }
public function __get($key) { public function __get($key) {
$value = false; $value = false;
if($key == 'total') { if($key == 'total') {
@ -44,17 +44,17 @@ class Mijireh_Item extends Mijireh_Model {
} }
return $value; return $value;
} }
public function get_data() { public function get_data() {
$data = parent::get_data(); $data = parent::get_data();
$data['total'] = $this->total; $data['total'] = $this->total;
return $data; return $data;
} }
public function validate() { public function validate() {
$this->_check_required_fields(); $this->_check_required_fields();
$this->_check_quantity(); $this->_check_quantity();
return count($this->_errors) == 0; return count($this->_errors) == 0;
} }
} }

View File

@ -3,13 +3,13 @@
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class Mijireh_Model { class Mijireh_Model {
protected $_data = array(); protected $_data = array();
protected $_errors = array(); protected $_errors = array();
/** /**
* Set the value of one of the keys in the private $_data array. * Set the value of one of the keys in the private $_data array.
* *
* @param string $key The key in the $_data array * @param string $key The key in the $_data array
* @param string $value The value to assign to the key * @param string $value The value to assign to the key
* @return boolean * @return boolean
@ -22,12 +22,12 @@ class Mijireh_Model {
} }
return $success; return $success;
} }
/** /**
* Get the value for the key from the private $_data array. * Get the value for the key from the private $_data array.
* *
* Return false if the requested key does not exist * Return false if the requested key does not exist
* *
* @param string $key The key from the $_data array * @param string $key The key from the $_data array
* @return mixed * @return mixed
*/ */
@ -36,29 +36,29 @@ class Mijireh_Model {
if(array_key_exists($key, $this->_data)) { if(array_key_exists($key, $this->_data)) {
$value = $this->_data[$key]; $value = $this->_data[$key];
} }
/* /*
elseif(method_exists($this, $key)) { elseif(method_exists($this, $key)) {
$value = call_user_func_array(array($this, $key), func_get_args()); $value = call_user_func_array(array($this, $key), func_get_args());
} }
*/ */
return $value; return $value;
} }
/** /**
* Return true if the given $key in the private $_data array is set * Return true if the given $key in the private $_data array is set
* *
* @param string $key * @param string $key
* @return boolean * @return boolean
*/ */
public function __isset($key) { public function __isset($key) {
return isset($this->_data[$key]); return isset($this->_data[$key]);
} }
/** /**
* Set the value of the $_data array to null for the given key. * Set the value of the $_data array to null for the given key.
* *
* @param string $key * @param string $key
* @return void * @return void
*/ */
@ -67,26 +67,26 @@ class Mijireh_Model {
$this->_data[$key] = null; $this->_data[$key] = null;
} }
} }
/** /**
* Return the private $_data array * Return the private $_data array
* *
* @return mixed * @return mixed
*/ */
public function get_data() { public function get_data() {
return $this->_data; return $this->_data;
} }
/** /**
* Return true if the given $key exists in the private $_data array * Return true if the given $key exists in the private $_data array
* *
* @param string $key * @param string $key
* @return boolean * @return boolean
*/ */
public function field_exists($key) { public function field_exists($key) {
return array_key_exists($key, $this->_data); return array_key_exists($key, $this->_data);
} }
public function copy_from(array $data) { public function copy_from(array $data) {
foreach($data as $key => $value) { foreach($data as $key => $value) {
if(array_key_exists($key, $this->_data)) { if(array_key_exists($key, $this->_data)) {
@ -94,7 +94,7 @@ class Mijireh_Model {
} }
} }
} }
public function clear() { public function clear() {
foreach($this->_data as $key => $value) { foreach($this->_data as $key => $value) {
if($key == 'id') { if($key == 'id') {
@ -105,21 +105,21 @@ class Mijireh_Model {
} }
} }
} }
public function add_error($error_message) { public function add_error($error_message) {
if(!empty($error_message)) { if(!empty($error_message)) {
$this->_errors[] = $error_message; $this->_errors[] = $error_message;
} }
} }
public function clear_errors() { public function clear_errors() {
$this->_errors = array(); $this->_errors = array();
} }
public function get_errors() { public function get_errors() {
return $this->_errors; return $this->_errors;
} }
public function get_error_lines($glue="\n") { public function get_error_lines($glue="\n") {
$error_lines = ''; $error_lines = '';
if(count($this->_errors)) { if(count($this->_errors)) {
@ -127,9 +127,9 @@ class Mijireh_Model {
} }
return $error_lines; return $error_lines;
} }
public function is_valid() { public function is_valid() {
return count($this->_errors) == 0; return count($this->_errors) == 0;
} }
} }

View File

@ -3,7 +3,7 @@
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class Mijireh_Order extends Mijireh_Model { class Mijireh_Order extends Mijireh_Model {
private function _init() { private function _init() {
$this->_data = array( $this->_data = array(
'partner_id' => null, 'partner_id' => null,
@ -27,19 +27,19 @@ class Mijireh_Order extends Mijireh_Model {
'billing_address' => array() 'billing_address' => array()
); );
} }
public function __construct($order_number=null) { public function __construct($order_number=null) {
$this->_init(); $this->_init();
if(isset($order_number)) { if(isset($order_number)) {
$this->load($order_number); $this->load($order_number);
} }
} }
public function load($order_number) { public function load($order_number) {
if(strlen(Mijireh::$access_key) < 5) { if(strlen(Mijireh::$access_key) < 5) {
throw new Mijireh_Exception('missing mijireh access key'); throw new Mijireh_Exception('missing mijireh access key');
} }
$rest = new Mijireh_RestJSON(Mijireh::$url); $rest = new Mijireh_RestJSON(Mijireh::$url);
$rest->setupAuth(Mijireh::$access_key, ''); $rest->setupAuth(Mijireh::$access_key, '');
try { try {
@ -63,7 +63,7 @@ class Mijireh_Order extends Mijireh_Model {
throw new Mijireh_ServerError($e->getMessage()); throw new Mijireh_ServerError($e->getMessage());
} }
} }
public function copy_from($order_data) { public function copy_from($order_data) {
foreach($order_data as $key => $value) { foreach($order_data as $key => $value) {
if($key == 'items') { if($key == 'items') {
@ -100,24 +100,24 @@ class Mijireh_Order extends Mijireh_Model {
$this->$key = $value; $this->$key = $value;
} }
} }
if(!$this->validate()) { if(!$this->validate()) {
throw new Mijireh_Exception('invalid order hydration: ' . $this->get_errors_lines()); throw new Mijireh_Exception('invalid order hydration: ' . $this->get_errors_lines());
} }
return $this; return $this;
} }
public function create() { public function create() {
if(strlen(Mijireh::$access_key) < 5) { if(strlen(Mijireh::$access_key) < 5) {
throw new Mijireh_Exception('missing mijireh access key'); throw new Mijireh_Exception('missing mijireh access key');
} }
if(!$this->validate()) { if(!$this->validate()) {
$error_message = 'unable to create order: ' . $this->get_error_lines(); $error_message = 'unable to create order: ' . $this->get_error_lines();
throw new Mijireh_Exception($error_message); throw new Mijireh_Exception($error_message);
} }
$rest = new Mijireh_RestJSON(Mijireh::$url); $rest = new Mijireh_RestJSON(Mijireh::$url);
$rest->setupAuth(Mijireh::$access_key, ''); $rest->setupAuth(Mijireh::$access_key, '');
try { try {
@ -141,7 +141,7 @@ class Mijireh_Order extends Mijireh_Model {
throw new Mijireh_ServerError($e->getMessage()); throw new Mijireh_ServerError($e->getMessage());
} }
} }
/** /**
* If meta_data or shipping_address are empty, exclude them altogether. * If meta_data or shipping_address are empty, exclude them altogether.
*/ */
@ -152,12 +152,12 @@ class Mijireh_Order extends Mijireh_Model {
if(count($data['billing_address']) == 0) { unset($data['billing_address']); } if(count($data['billing_address']) == 0) { unset($data['billing_address']); }
return $data; return $data;
} }
/** /**
* Add the specified item and price to the order. * Add the specified item and price to the order.
* *
* Return the total number of items in the order (including the one that was just added) * Return the total number of items in the order (including the one that was just added)
* *
* @return int * @return int
*/ */
public function add_item($name, $price=0, $quantity=1, $sku='') { public function add_item($name, $price=0, $quantity=1, $sku='') {
@ -172,7 +172,7 @@ class Mijireh_Order extends Mijireh_Model {
$item->quantity = $quantity; $item->quantity = $quantity;
$item->sku = $sku; $item->sku = $sku;
} }
if($item->validate()) { if($item->validate()) {
$this->_data['items'][] = $item->get_data(); $this->_data['items'][] = $item->get_data();
return $this->item_count(); return $this->item_count();
@ -182,17 +182,17 @@ class Mijireh_Order extends Mijireh_Model {
throw new Mijireh_Exception('unable to add invalid item to order :: ' . $errors); throw new Mijireh_Exception('unable to add invalid item to order :: ' . $errors);
} }
} }
public function add_meta_data($key, $value) { public function add_meta_data($key, $value) {
if(!is_array($this->_data['meta_data'])) { if(!is_array($this->_data['meta_data'])) {
$this->_data['meta_data'] = array(); $this->_data['meta_data'] = array();
} }
$this->_data['meta_data'][$key] = $value; $this->_data['meta_data'][$key] = $value;
} }
/** /**
* Return the value associated with the given key in the order's meta data. * Return the value associated with the given key in the order's meta data.
* *
* If the key does not exist, return false. * If the key does not exist, return false.
*/ */
public function get_meta_value($key) { public function get_meta_value($key) {
@ -202,7 +202,7 @@ class Mijireh_Order extends Mijireh_Model {
} }
return $value; return $value;
} }
public function item_count() { public function item_count() {
$item_count = 0; $item_count = 0;
if(is_array($this->_data['items'])) { if(is_array($this->_data['items'])) {
@ -210,7 +210,7 @@ class Mijireh_Order extends Mijireh_Model {
} }
return $item_count; return $item_count;
} }
public function get_items() { public function get_items() {
$items = array(); $items = array();
foreach($this->_data['items'] as $item_data) { foreach($this->_data['items'] as $item_data) {
@ -218,29 +218,29 @@ class Mijireh_Order extends Mijireh_Model {
$item->copy_from($item_data); $item->copy_from($item_data);
} }
} }
public function clear_items() { public function clear_items() {
$this->_data['items'] = array(); $this->_data['items'] = array();
} }
public function clear_meta_data() { public function clear_meta_data() {
$this->_data['meta_data'] = array(); $this->_data['meta_data'] = array();
} }
public function validate() { public function validate() {
$this->_check_total(); $this->_check_total();
$this->_check_return_url(); $this->_check_return_url();
$this->_check_items(); $this->_check_items();
return count($this->_errors) == 0; return count($this->_errors) == 0;
} }
/** /**
* Alias for set_shipping_address() * Alias for set_shipping_address()
*/ */
public function set_address(Mijireh_Address $address){ public function set_address(Mijireh_Address $address){
$this->set_shipping_address($address); $this->set_shipping_address($address);
} }
public function set_shipping_address(Mijireh_Address $address) { public function set_shipping_address(Mijireh_Address $address) {
if($address->validate()) { if($address->validate()) {
$this->_data['shipping_address'] = $address->get_data(); $this->_data['shipping_address'] = $address->get_data();
@ -249,7 +249,7 @@ class Mijireh_Order extends Mijireh_Model {
throw new Mijireh_Exception('invalid shipping address'); throw new Mijireh_Exception('invalid shipping address');
} }
} }
public function set_billing_address(Mijireh_Address $address) { public function set_billing_address(Mijireh_Address $address) {
if($address->validate()) { if($address->validate()) {
$this->_data['billing_address'] = $address->get_data(); $this->_data['billing_address'] = $address->get_data();
@ -258,14 +258,14 @@ class Mijireh_Order extends Mijireh_Model {
throw new Mijireh_Exception('invalid shipping address'); throw new Mijireh_Exception('invalid shipping address');
} }
} }
/** /**
* Alias for get_shipping_address() * Alias for get_shipping_address()
*/ */
public function get_address() { public function get_address() {
return $this->get_shipping_address(); return $this->get_shipping_address();
} }
public function get_shipping_address() { public function get_shipping_address() {
$address = false; $address = false;
if(is_array($this->_data['shipping_address'])) { if(is_array($this->_data['shipping_address'])) {
@ -274,7 +274,7 @@ class Mijireh_Order extends Mijireh_Model {
} }
return $address; return $address;
} }
public function get_billing_address() { public function get_billing_address() {
$address = false; $address = false;
if(is_array($this->_data['billing_address'])) { if(is_array($this->_data['billing_address'])) {
@ -283,12 +283,12 @@ class Mijireh_Order extends Mijireh_Model {
} }
return $address; return $address;
} }
/** /**
* The order total must be greater than zero. * The order total must be greater than zero.
* *
* Return true if valid, otherwise false. * Return true if valid, otherwise false.
* *
* @return boolean * @return boolean
*/ */
private function _check_total() { private function _check_total() {
@ -299,12 +299,12 @@ class Mijireh_Order extends Mijireh_Model {
} }
return $is_valid; return $is_valid;
} }
/** /**
* The return url must be provided and must start with http. * The return url must be provided and must start with http.
* *
* Return true if valid, otherwise false * Return true if valid, otherwise false
* *
* @return boolean * @return boolean
*/ */
private function _check_return_url() { private function _check_return_url() {
@ -323,12 +323,12 @@ class Mijireh_Order extends Mijireh_Model {
} }
return $is_valid; return $is_valid;
} }
/** /**
* An order must contain at least one item * An order must contain at least one item
* *
* Return true if the order has at least one item, otherwise false. * Return true if the order has at least one item, otherwise false.
* *
* @return boolean * @return boolean
*/ */
private function _check_items() { private function _check_items() {
@ -339,5 +339,5 @@ class Mijireh_Order extends Mijireh_Model {
} }
return $is_valid; return $is_valid;
} }
} }

View File

@ -8,9 +8,9 @@
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class Mijireh_Rest { class Mijireh_Rest {
public $curl_opts = array( public $curl_opts = array(
CURLOPT_RETURNTRANSFER => true, // return result instead of echoing CURLOPT_RETURNTRANSFER => true, // return result instead of echoing
CURLOPT_SSL_VERIFYPEER => false, // stop cURL from verifying the peer's certificate CURLOPT_SSL_VERIFYPEER => false, // stop cURL from verifying the peer's certificate
@ -18,20 +18,20 @@ class Mijireh_Rest {
); );
public $base_url; public $base_url;
public $last_response; public $last_response;
public $last_request; public $last_request;
public $throw_exceptions = true; public $throw_exceptions = true;
public function __construct($base_url, $curl_options=null) { public function __construct($base_url, $curl_options=null) {
if (!function_exists('curl_init')) { if (!function_exists('curl_init')) {
throw new Exception('CURL module not available! Mijireh_Rest requires CURL. See http://php.net/manual/en/book.curl.php'); throw new Exception('CURL module not available! Mijireh_Rest requires CURL. See http://php.net/manual/en/book.curl.php');
} }
if(isset($curl_options) && is_array($curl_options)) { if(isset($curl_options) && is_array($curl_options)) {
foreach($curl_options as $key => $value) { foreach($curl_options as $key => $value) {
if($key == 'CURLOPT_FOLLOWLOCATION') { if($key == 'CURLOPT_FOLLOWLOCATION') {
// only enable CURLOPT_FOLLOWLOCATION if safe_mode and open_base_dir are not in use // only enable CURLOPT_FOLLOWLOCATION if safe_mode and open_base_dir are not in use
if(ini_get('open_basedir') == '' && !ini_get('safe_mode')) { if(ini_get('open_basedir') == '' && !ini_get('safe_mode')) {
@ -41,151 +41,151 @@ class Mijireh_Rest {
else { else {
$this->curl_opts[$key] = $value; $this->curl_opts[$key] = $value;
} }
} }
} }
$this->base_url = $base_url; $this->base_url = $base_url;
} }
// $auth can be 'basic' or 'digest' // $auth can be 'basic' or 'digest'
public function setupAuth($user, $pass, $auth = 'basic') { public function setupAuth($user, $pass, $auth = 'basic') {
$this->curl_opts[CURLOPT_HTTPAUTH] = constant('CURLAUTH_'.strtoupper($auth)); $this->curl_opts[CURLOPT_HTTPAUTH] = constant('CURLAUTH_'.strtoupper($auth));
$this->curl_opts[CURLOPT_USERPWD] = $user . ":" . $pass; $this->curl_opts[CURLOPT_USERPWD] = $user . ":" . $pass;
} }
public function get($url) { public function get($url) {
$curl = $this->prepRequest($this->curl_opts, $url); $curl = $this->prepRequest($this->curl_opts, $url);
$body = $this->doRequest($curl); $body = $this->doRequest($curl);
$body = $this->processBody($body); $body = $this->processBody($body);
return $body; return $body;
} }
public function post($url, $data, $headers=array()) { public function post($url, $data, $headers=array()) {
$data = (is_array($data)) ? http_build_query($data) : $data; $data = (is_array($data)) ? http_build_query($data) : $data;
$curl_opts = $this->curl_opts; $curl_opts = $this->curl_opts;
$curl_opts[CURLOPT_CUSTOMREQUEST] = 'POST'; $curl_opts[CURLOPT_CUSTOMREQUEST] = 'POST';
$headers[] = 'Content-Length: '.strlen($data); $headers[] = 'Content-Length: '.strlen($data);
$curl_opts[CURLOPT_HTTPHEADER] = $headers; $curl_opts[CURLOPT_HTTPHEADER] = $headers;
$curl_opts[CURLOPT_POSTFIELDS] = $data; $curl_opts[CURLOPT_POSTFIELDS] = $data;
$curl = $this->prepRequest($curl_opts, $url); $curl = $this->prepRequest($curl_opts, $url);
$body = $this->doRequest($curl); $body = $this->doRequest($curl);
$body = $this->processBody($body); $body = $this->processBody($body);
return $body; return $body;
} }
public function put($url, $data, $headers=array()) { public function put($url, $data, $headers=array()) {
$data = (is_array($data)) ? http_build_query($data) : $data; $data = (is_array($data)) ? http_build_query($data) : $data;
$curl_opts = $this->curl_opts; $curl_opts = $this->curl_opts;
$curl_opts[CURLOPT_CUSTOMREQUEST] = 'PUT'; $curl_opts[CURLOPT_CUSTOMREQUEST] = 'PUT';
$headers[] = 'Content-Length: '.strlen($data); $headers[] = 'Content-Length: '.strlen($data);
$curl_opts[CURLOPT_HTTPHEADER] = $headers; $curl_opts[CURLOPT_HTTPHEADER] = $headers;
$curl_opts[CURLOPT_POSTFIELDS] = $data; $curl_opts[CURLOPT_POSTFIELDS] = $data;
$curl = $this->prepRequest($curl_opts, $url); $curl = $this->prepRequest($curl_opts, $url);
$body = $this->doRequest($curl); $body = $this->doRequest($curl);
$body = $this->processBody($body); $body = $this->processBody($body);
return $body; return $body;
} }
public function delete($url) { public function delete($url) {
$curl_opts = $this->curl_opts; $curl_opts = $this->curl_opts;
$curl_opts[CURLOPT_CUSTOMREQUEST] = 'DELETE'; $curl_opts[CURLOPT_CUSTOMREQUEST] = 'DELETE';
$curl = $this->prepRequest($curl_opts, $url); $curl = $this->prepRequest($curl_opts, $url);
$body = $this->doRequest($curl); $body = $this->doRequest($curl);
$body = $this->processBody($body); $body = $this->processBody($body);
return $body; return $body;
} }
public function lastBody() { public function lastBody() {
return $this->last_response['body']; return $this->last_response['body'];
} }
public function lastStatus() { public function lastStatus() {
return $this->last_response['meta']['http_code']; return $this->last_response['meta']['http_code'];
} }
protected function processBody($body) { protected function processBody($body) {
// Override this in classes that extend Mijireh_Rest. // Override this in classes that extend Mijireh_Rest.
// The body of every GET/POST/PUT/DELETE response goes through // The body of every GET/POST/PUT/DELETE response goes through
// here prior to being returned. // here prior to being returned.
return $body; return $body;
} }
protected function processError($body) { protected function processError($body) {
// Override this in classes that extend Mijireh_Rest. // Override this in classes that extend Mijireh_Rest.
// The body of every erroneous (non-2xx/3xx) GET/POST/PUT/DELETE // The body of every erroneous (non-2xx/3xx) GET/POST/PUT/DELETE
// response goes through here prior to being used as the 'message' // response goes through here prior to being used as the 'message'
// of the resulting Mijireh_Rest_Exception // of the resulting Mijireh_Rest_Exception
return $body; return $body;
} }
protected function prepRequest($opts, $url) { protected function prepRequest($opts, $url) {
if (strncmp($url, $this->base_url, strlen($this->base_url)) != 0) { if (strncmp($url, $this->base_url, strlen($this->base_url)) != 0) {
$url = $this->base_url . $url; $url = $this->base_url . $url;
} }
$curl = curl_init($url); $curl = curl_init($url);
foreach ($opts as $opt => $val) { foreach ($opts as $opt => $val) {
@curl_setopt($curl, $opt, $val); @curl_setopt($curl, $opt, $val);
} }
$this->last_request = array( $this->last_request = array(
'url' => $url 'url' => $url
); );
if (isset($opts[CURLOPT_CUSTOMREQUEST])) if (isset($opts[CURLOPT_CUSTOMREQUEST]))
$this->last_request['method'] = $opts[CURLOPT_CUSTOMREQUEST]; $this->last_request['method'] = $opts[CURLOPT_CUSTOMREQUEST];
else else
$this->last_request['method'] = 'GET'; $this->last_request['method'] = 'GET';
if (isset($opts[CURLOPT_POSTFIELDS])) if (isset($opts[CURLOPT_POSTFIELDS]))
$this->last_request['data'] = $opts[CURLOPT_POSTFIELDS]; $this->last_request['data'] = $opts[CURLOPT_POSTFIELDS];
return $curl; return $curl;
} }
private function doRequest($curl) { private function doRequest($curl) {
$body = curl_exec($curl); $body = curl_exec($curl);
$meta = curl_getinfo($curl); $meta = curl_getinfo($curl);
$this->last_response = array( $this->last_response = array(
'body' => $body, 'body' => $body,
'meta' => $meta 'meta' => $meta
); );
curl_close($curl); curl_close($curl);
$this->checkLastResponseForError(); $this->checkLastResponseForError();
return $body; return $body;
} }
protected function checkLastResponseForError() { protected function checkLastResponseForError() {
if ( !$this->throw_exceptions) if ( !$this->throw_exceptions)
return; return;
$meta = $this->last_response['meta']; $meta = $this->last_response['meta'];
$body = $this->last_response['body']; $body = $this->last_response['body'];
if (!$meta) if (!$meta)
return; return;
$err = null; $err = null;
switch ($meta['http_code']) { switch ($meta['http_code']) {
case 400: case 400:
@ -213,7 +213,7 @@ class Mijireh_Rest {
// Unprocessable Entity -- see http://www.iana.org/assignments/http-status-codes // Unprocessable Entity -- see http://www.iana.org/assignments/http-status-codes
// This is now commonly used (in Rails, at least) to indicate // This is now commonly used (in Rails, at least) to indicate
// a response to a request that is syntactically correct, // a response to a request that is syntactically correct,
// but semantically invalid (for example, when trying to // but semantically invalid (for example, when trying to
// create a resource with some required fields missing) // create a resource with some required fields missing)
throw new Mijireh_Rest_InvalidRecord($this->processError($body)); throw new Mijireh_Rest_InvalidRecord($this->processError($body));
break; break;

View File

@ -3,11 +3,11 @@
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class Mijireh_RestJSON extends Mijireh_Rest { class Mijireh_RestJSON extends Mijireh_Rest {
public function post($url, $data, $headers=array()) { public function post($url, $data, $headers=array()) {
return parent::post($url, json_encode($data), $headers); return parent::post($url, json_encode($data), $headers);
} }
public function put($url, $data, $headers=array()) { public function put($url, $data, $headers=array()) {
return parent::put($url, json_encode($data), $headers); return parent::put($url, json_encode($data), $headers);
} }
@ -21,5 +21,5 @@ class Mijireh_RestJSON extends Mijireh_Rest {
public function processBody($body) { public function processBody($body) {
return json_decode($body, true); return json_decode($body, true);
} }
} }

View File

@ -14,9 +14,9 @@
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class WC_Paypal extends WC_Payment_Gateway { class WC_Paypal extends WC_Payment_Gateway {
var $notify_url; var $notify_url;
/** /**
* Constructor for the gateway. * Constructor for the gateway.
* *
@ -59,7 +59,7 @@ class WC_Paypal extends WC_Payment_Gateway {
add_action( 'valid-paypal-standard-ipn-request', array( &$this, 'successful_request' ) ); add_action( 'valid-paypal-standard-ipn-request', array( &$this, 'successful_request' ) );
add_action( 'woocommerce_receipt_paypal', array( &$this, 'receipt_page' ) ); add_action( 'woocommerce_receipt_paypal', array( &$this, 'receipt_page' ) );
add_action( 'woocommerce_update_options_payment_gateways', array( &$this, 'process_admin_options' ) ); add_action( 'woocommerce_update_options_payment_gateways', array( &$this, 'process_admin_options' ) );
// Payment listener/API hook // Payment listener/API hook
add_action( 'woocommerce_api_wc_paypal', array( &$this, 'check_ipn_response' ) ); add_action( 'woocommerce_api_wc_paypal', array( &$this, 'check_ipn_response' ) );
@ -218,7 +218,7 @@ class WC_Paypal extends WC_Payment_Gateway {
$order_id = $order->id; $order_id = $order->id;
if ( $this->debug == 'yes' ) if ( $this->debug == 'yes' )
$this->log->add( 'paypal', 'Generating payment form for order ' . $order->get_order_number() . '. Notify URL: ' . $this->notify_url ); $this->log->add( 'paypal', 'Generating payment form for order ' . $order->get_order_number() . '. Notify URL: ' . $this->notify_url );
if ( in_array( $order->billing_country, array( 'US','CA' ) ) ) { if ( in_array( $order->billing_country, array( 'US','CA' ) ) ) {
@ -303,9 +303,9 @@ class WC_Paypal extends WC_Payment_Gateway {
// Don't pass items - paypal borks tax due to prices including tax. PayPal has no option for tax inclusive pricing sadly. Pass 1 item for the order items overall // Don't pass items - paypal borks tax due to prices including tax. PayPal has no option for tax inclusive pricing sadly. Pass 1 item for the order items overall
$item_names = array(); $item_names = array();
if ( sizeof( $order->get_items() ) > 0 ) if ( sizeof( $order->get_items() ) > 0 )
foreach ( $order->get_items() as $item ) foreach ( $order->get_items() as $item )
if ( $item['qty'] ) if ( $item['qty'] )
$item_names[] = $item['name'] . ' x ' . $item['qty']; $item_names[] = $item['name'] . ' x ' . $item['qty'];
$paypal_args['item_name_1'] = sprintf( __( 'Order %s' , 'woocommerce'), $order->get_order_number() ) . " - " . implode( ', ', $item_names ); $paypal_args['item_name_1'] = sprintf( __( 'Order %s' , 'woocommerce'), $order->get_order_number() ) . " - " . implode( ', ', $item_names );
@ -333,32 +333,32 @@ class WC_Paypal extends WC_Payment_Gateway {
if ( sizeof( $order->get_items() ) > 0 ) { if ( sizeof( $order->get_items() ) > 0 ) {
foreach ( $order->get_items() as $item ) { foreach ( $order->get_items() as $item ) {
if ( $item['qty'] ) { if ( $item['qty'] ) {
$item_loop++; $item_loop++;
$product = $order->get_product_from_item( $item ); $product = $order->get_product_from_item( $item );
$item_name = $item['name']; $item_name = $item['name'];
$item_meta = new WC_Order_Item_Meta( $item['item_meta'] ); $item_meta = new WC_Order_Item_Meta( $item['item_meta'] );
if ( $meta = $item_meta->display( true, true ) ) if ( $meta = $item_meta->display( true, true ) )
$item_name .= ' ( ' . $meta . ' )'; $item_name .= ' ( ' . $meta . ' )';
$paypal_args[ 'item_name_' . $item_loop ] = $item_name; $paypal_args[ 'item_name_' . $item_loop ] = $item_name;
$paypal_args[ 'quantity_' . $item_loop ] = $item['qty']; $paypal_args[ 'quantity_' . $item_loop ] = $item['qty'];
$paypal_args[ 'amount_' . $item_loop ] = $order->get_item_total( $item, false ); $paypal_args[ 'amount_' . $item_loop ] = $order->get_item_total( $item, false );
if ( $product->get_sku() ) if ( $product->get_sku() )
$paypal_args[ 'item_number_' . $item_loop ] = $product->get_sku(); $paypal_args[ 'item_number_' . $item_loop ] = $product->get_sku();
} }
} }
} }
// Fees // Fees
if ( sizeof( $order->get_fees() ) > 0 ) { if ( sizeof( $order->get_fees() ) > 0 ) {
foreach ( $order->get_fees() as $item ) { foreach ( $order->get_fees() as $item ) {
$item_loop++; $item_loop++;
$paypal_args[ 'item_name_' . $item_loop ] = $item['name']; $paypal_args[ 'item_name_' . $item_loop ] = $item['name'];
$paypal_args[ 'quantity_' . $item_loop ] = 1; $paypal_args[ 'quantity_' . $item_loop ] = 1;
$paypal_args[ 'amount_' . $item_loop ] = $item['line_total']; $paypal_args[ 'amount_' . $item_loop ] = $item['line_total'];
@ -496,7 +496,7 @@ class WC_Paypal extends WC_Payment_Gateway {
function check_ipn_request_is_valid() { function check_ipn_request_is_valid() {
global $woocommerce; global $woocommerce;
if ( $this->debug == 'yes' ) if ( $this->debug == 'yes' )
$this->log->add( 'paypal', 'Checking IPN response is valid...' ); $this->log->add( 'paypal', 'Checking IPN response is valid...' );
// Get recieved values from post data // Get recieved values from post data
@ -522,14 +522,14 @@ class WC_Paypal extends WC_Payment_Gateway {
// Post back to get a response // Post back to get a response
$response = wp_remote_post( $paypal_adr, $params ); $response = wp_remote_post( $paypal_adr, $params );
if ( $this->debug == 'yes' ) if ( $this->debug == 'yes' )
$this->log->add( 'paypal', 'IPN Response: ' . print_r( $response, true ) ); $this->log->add( 'paypal', 'IPN Response: ' . print_r( $response, true ) );
// check to see if the request was valid // check to see if the request was valid
if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && ( strcmp( $response['body'], "VERIFIED" ) == 0 ) ) { if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && ( strcmp( $response['body'], "VERIFIED" ) == 0 ) ) {
if ( $this->debug == 'yes' ) if ( $this->debug == 'yes' )
$this->log->add( 'paypal', 'Received valid response from PayPal' ); $this->log->add( 'paypal', 'Received valid response from PayPal' );
return true; return true;
} }
@ -582,18 +582,18 @@ class WC_Paypal extends WC_Payment_Gateway {
// Custom holds post ID // Custom holds post ID
if ( ! empty( $posted['invoice'] ) && ! empty( $posted['custom'] ) ) { if ( ! empty( $posted['invoice'] ) && ! empty( $posted['custom'] ) ) {
$order = $this->get_paypal_order( $posted ); $order = $this->get_paypal_order( $posted );
// Lowercase returned variables // Lowercase returned variables
$posted['payment_status'] = strtolower( $posted['payment_status'] ); $posted['payment_status'] = strtolower( $posted['payment_status'] );
$posted['txn_type'] = strtolower( $posted['txn_type'] ); $posted['txn_type'] = strtolower( $posted['txn_type'] );
// Sandbox fix // Sandbox fix
if ( $posted['test_ipn'] == 1 && $posted['payment_status'] == 'pending' ) if ( $posted['test_ipn'] == 1 && $posted['payment_status'] == 'pending' )
$posted['payment_status'] = 'completed'; $posted['payment_status'] = 'completed';
if ( $this->debug == 'yes' ) if ( $this->debug == 'yes' )
$this->log->add( 'paypal', 'Payment status: ' . $posted['payment_status'] ); $this->log->add( 'paypal', 'Payment status: ' . $posted['payment_status'] );
// We are here so lets check status and do actions // We are here so lets check status and do actions
@ -602,7 +602,7 @@ class WC_Paypal extends WC_Payment_Gateway {
// Check order not already completed // Check order not already completed
if ( $order->status == 'completed' ) { if ( $order->status == 'completed' ) {
if ( $this->debug == 'yes' ) if ( $this->debug == 'yes' )
$this->log->add( 'paypal', 'Aborting, Order #' . $order_id . ' is already complete.' ); $this->log->add( 'paypal', 'Aborting, Order #' . $order_id . ' is already complete.' );
exit; exit;
} }
@ -610,22 +610,22 @@ class WC_Paypal extends WC_Payment_Gateway {
// Check valid txn_type // Check valid txn_type
$accepted_types = array( 'cart', 'instant', 'express_checkout', 'web_accept', 'masspay', 'send_money' ); $accepted_types = array( 'cart', 'instant', 'express_checkout', 'web_accept', 'masspay', 'send_money' );
if ( ! in_array( $posted['txn_type'], $accepted_types ) ) { if ( ! in_array( $posted['txn_type'], $accepted_types ) ) {
if ( $this->debug == 'yes' ) if ( $this->debug == 'yes' )
$this->log->add( 'paypal', 'Aborting, Invalid type:' . $posted['txn_type'] ); $this->log->add( 'paypal', 'Aborting, Invalid type:' . $posted['txn_type'] );
exit; exit;
} }
// Validate Amount // Validate Amount
if ( $order->get_total() != $posted['mc_gross'] ) { if ( $order->get_total() != $posted['mc_gross'] ) {
if ( $this->debug == 'yes' ) if ( $this->debug == 'yes' )
$this->log->add( 'paypal', 'Payment error: Amounts do not match (gross ' . $posted['mc_gross'] . ')' ); $this->log->add( 'paypal', 'Payment error: Amounts do not match (gross ' . $posted['mc_gross'] . ')' );
// Put this order on-hold for manual checking // Put this order on-hold for manual checking
$order->update_status( 'on-hold', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'woocommerce' ), $posted['mc_gross'] ) ); $order->update_status( 'on-hold', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'woocommerce' ), $posted['mc_gross'] ) );
exit; exit;
} }
// Store PP Details // Store PP Details
if ( ! empty( $posted['payer_email'] ) ) if ( ! empty( $posted['payer_email'] ) )
@ -643,7 +643,7 @@ class WC_Paypal extends WC_Payment_Gateway {
$order->add_order_note( __( 'IPN payment completed', 'woocommerce' ) ); $order->add_order_note( __( 'IPN payment completed', 'woocommerce' ) );
$order->payment_complete(); $order->payment_complete();
if ( $this->debug == 'yes' ) if ( $this->debug == 'yes' )
$this->log->add( 'paypal', 'Payment complete.' ); $this->log->add( 'paypal', 'Payment complete.' );
break; break;
@ -699,11 +699,11 @@ class WC_Paypal extends WC_Payment_Gateway {
} }
} }
/** /**
* get_paypal_order function. * get_paypal_order function.
* *
* @access public * @access public
* @param mixed $posted * @param mixed $posted
* @return void * @return void
@ -724,19 +724,19 @@ class WC_Paypal extends WC_Payment_Gateway {
$order = new WC_Order( $order_id ); $order = new WC_Order( $order_id );
if ( ! isset( $order->id ) ) { if ( ! isset( $order->id ) ) {
// We have an invalid $order_id, probably because invoice_prefix has changed // We have an invalid $order_id, probably because invoice_prefix has changed
$order_id = woocommerce_get_order_id_by_order_key( $order_key ); $order_id = woocommerce_get_order_id_by_order_key( $order_key );
$order = new WC_Order( $order_id ); $order = new WC_Order( $order_id );
} }
// Validate key // Validate key
if ( $order->order_key !== $order_key ) { if ( $order->order_key !== $order_key ) {
if ( $this->debug=='yes' ) if ( $this->debug=='yes' )
$this->log->add( 'paypal', 'Error: Order Key does not match invoice.' ); $this->log->add( 'paypal', 'Error: Order Key does not match invoice.' );
exit; exit;
} }
return $order; return $order;
} }

View File

@ -268,7 +268,7 @@ class WC_Google_Analytics extends WC_Integration {
* @return void * @return void
*/ */
function loop_add_to_cart() { function loop_add_to_cart() {
if ( $this->disable_tracking( $this->ga_event_tracking_enabled ) ) return; if ( $this->disable_tracking( $this->ga_event_tracking_enabled ) ) return;
$parameters = array(); $parameters = array();
@ -293,7 +293,7 @@ class WC_Google_Analytics extends WC_Integration {
global $woocommerce; global $woocommerce;
$parameters = apply_filters( 'woocommerce_ga_event_tracking_parameters', $parameters ); $parameters = apply_filters( 'woocommerce_ga_event_tracking_parameters', $parameters );
$woocommerce->add_inline_js(" $woocommerce->add_inline_js("
$('" . $selector . "').click(function() { $('" . $selector . "').click(function() {
" . sprintf( "_gaq.push(['_trackEvent', %s, %s, %s]);", $parameters['category'], $parameters['action'], $parameters['label'] ) . " " . sprintf( "_gaq.push(['_trackEvent', %s, %s, %s]);", $parameters['category'], $parameters['action'], $parameters['label'] ) . "

View File

@ -17,27 +17,27 @@ class ShareYourCartWooCommerceEx extends ShareYourCartWooCommerce {
parent::__construct(); parent::__construct();
} }
public function isCartActive() { public function isCartActive() {
return true; //since this class has loaded, the WooCommerce plugin is active return true; //since this class has loaded, the WooCommerce plugin is active
} }
public function getSecretKey() { public function getSecretKey() {
return '2cfd496d-7812-44ba-91ce-e43c59f6c680'; return '2cfd496d-7812-44ba-91ce-e43c59f6c680';
} }
public function showAdminMenu() { public function showAdminMenu() {
//since we have allready integrated this in our own settings page, //since we have allready integrated this in our own settings page,
//leave this function empty //leave this function empty
} }
/** /**
* *
* Set the field value * Set the field value
* *
*/ */
protected function setConfigValue($field, $value) { protected function setConfigValue($field, $value) {
$this->settings[$field] = $value; $this->settings[$field] = $value;
//make sure to update the enabled field as well, based on the account_status //make sure to update the enabled field as well, based on the account_status
@ -51,11 +51,11 @@ class ShareYourCartWooCommerceEx extends ShareYourCartWooCommerce {
parent::setConfigValue($field, $value); parent::setConfigValue($field, $value);
break; break;
} }
//save the config in the DB //save the config in the DB
update_option( 'woocommerce_shareyourcart_settings', $this->settings ); update_option( 'woocommerce_shareyourcart_settings', $this->settings );
} }
/** /**
* *
* Get the field value * Get the field value
@ -64,15 +64,15 @@ class ShareYourCartWooCommerceEx extends ShareYourCartWooCommerce {
protected function getConfigValue( $field ) { protected function getConfigValue( $field ) {
$value = ( isset( $this->settings[$field] ) ) ? $this->settings[$field] : ''; $value = ( isset( $this->settings[$field] ) ) ? $this->settings[$field] : '';
//search for the global value of this field //search for the global value of this field
//as it might have been changed by an external ShareYourCart integration //as it might have been changed by an external ShareYourCart integration
if($field == "plugin_current_version"){ if($field == "plugin_current_version"){
$val = parent::getConfigValue($field); $val = parent::getConfigValue($field);
if(!empty($val)) $value = $val; if(!empty($val)) $value = $val;
} }
return $value; return $value;
} }
} }

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* ShareYourCart Integration * ShareYourCart Integration
* *
* Enables ShareYourCart integration. * Enables ShareYourCart integration.
* *
* @class WC_ShareYourCart * @class WC_ShareYourCart
@ -9,77 +9,77 @@
* @category Integrations * @category Integrations
* @author WooThemes * @author WooThemes
*/ */
class WC_ShareYourCart extends WC_Integration { class WC_ShareYourCart extends WC_Integration {
var $ShareYourCartWooCommerce; var $ShareYourCartWooCommerce;
public function __construct() { public function __construct() {
$this->id = 'shareyourcart'; $this->id = 'shareyourcart';
$this->method_title = __( 'ShareYourCart', 'woocommerce' ); $this->method_title = __( 'ShareYourCart', 'woocommerce' );
$this->method_description = __( 'Increase your social media exposure by 10 percent! ShareYourCart helps you get more customers by motivating satisfied customers to talk with their friends about your products. For help with ShareYourCart view the <a href="http://www.woothemes.com/woocommerce-docs/user-guide/shareyourcart/" target="__blank">documentation</a>.', 'woocommerce' ); $this->method_description = __( 'Increase your social media exposure by 10 percent! ShareYourCart helps you get more customers by motivating satisfied customers to talk with their friends about your products. For help with ShareYourCart view the <a href="http://www.woothemes.com/woocommerce-docs/user-guide/shareyourcart/" target="__blank">documentation</a>.', 'woocommerce' );
// Load the settings. // Load the settings.
$this->settings = ( array ) get_option( $this->plugin_id . $this->id . '_settings' ); //do not rely on the base implementation of init_settings $this->settings = ( array ) get_option( $this->plugin_id . $this->id . '_settings' ); //do not rely on the base implementation of init_settings
//the classes need to be initialized //the classes need to be initialized
$this->init_share_your_cart(); $this->init_share_your_cart();
//hook to the admin settings page //hook to the admin settings page
add_action( 'woocommerce_update_options_integration_shareyourcart', array( &$this, 'process_forms') ); add_action( 'woocommerce_update_options_integration_shareyourcart', array( &$this, 'process_forms') );
} }
/** /**
* styles function. * styles function.
* *
* @access public * @access public
* @return void * @return void
*/ */
public function styles() { public function styles() {
wp_enqueue_style( 'shareyourcart', plugins_url( 'css/style.css', __FILE__ ) ); wp_enqueue_style( 'shareyourcart', plugins_url( 'css/style.css', __FILE__ ) );
} }
/** /**
* init_share_your_cart function. * init_share_your_cart function.
* *
* @access public * @access public
* @return void * @return void
*/ */
function init_share_your_cart() { function init_share_your_cart() {
if ( empty( $this->shareYourCartWooCommerce ) ) { if ( empty( $this->shareYourCartWooCommerce ) ) {
// Share your cart api class // Share your cart api class
include_once('class-shareyourcart-woocommerce-extended.php'); include_once('class-shareyourcart-woocommerce-extended.php');
// Init the class // Init the class
$this->shareYourCartWooCommerce = new ShareYourCartWooCommerceEx( $this->settings ); $this->shareYourCartWooCommerce = new ShareYourCartWooCommerceEx( $this->settings );
//by the time we get here, the plugins_loaded hook has allready been called //by the time we get here, the plugins_loaded hook has allready been called
//so call the method manually //so call the method manually
$this->shareYourCartWooCommerce->pluginsLoadedHook(); $this->shareYourCartWooCommerce->pluginsLoadedHook();
} }
} }
/** /**
* process_forms function. * process_forms function.
* *
* @access public * @access public
*/ */
function process_forms() { function process_forms() {
//after this function completes, WooCommerce will refresh the page, so we need to save the data here //after this function completes, WooCommerce will refresh the page, so we need to save the data here
//stripslashes from button_html //stripslashes from button_html
if(isset($_POST['button_html'])) if(isset($_POST['button_html']))
$_POST['button_html'] = stripslashes($_POST['button_html']); $_POST['button_html'] = stripslashes($_POST['button_html']);
//TODO: investigate why the files are not being uploaded //TODO: investigate why the files are not being uploaded
$this->shareYourCartWooCommerce->getAdminPage($this); //get the admin page ( so that the data is processed, but do not show it ) $this->shareYourCartWooCommerce->getAdminPage($this); //get the admin page ( so that the data is processed, but do not show it )
$this->shareYourCartWooCommerce->getButtonCustomizationPage(); //get the customization page ( so that the data is processed, but do not show it ) $this->shareYourCartWooCommerce->getButtonCustomizationPage(); //get the customization page ( so that the data is processed, but do not show it )
} }
/** /**
* Admin Options * Admin Options
* *
@ -89,17 +89,17 @@ class WC_ShareYourCart extends WC_Integration {
* @since 1.0.0 * @since 1.0.0
*/ */
function admin_options() { function admin_options() {
if ( $this->shareYourCartWooCommerce->isActive() ) { if ( $this->shareYourCartWooCommerce->isActive() ) {
// call this manually ( to determine if there needs to be a table update, or not ) // call this manually ( to determine if there needs to be a table update, or not )
$this->shareYourCartWooCommerce->install(); $this->shareYourCartWooCommerce->install();
} }
$this->shareYourCartWooCommerce->showAdminHeader(); $this->shareYourCartWooCommerce->showAdminHeader();
$this->shareYourCartWooCommerce->showAdminPage($this,true,false); //send this obj to the view, but do not show the footer $this->shareYourCartWooCommerce->showAdminPage($this,true,false); //send this obj to the view, but do not show the footer
$this->shareYourCartWooCommerce->showButtonCustomizationPage(null,false,false); //do not show neither the header, nor the footer of this page $this->shareYourCartWooCommerce->showButtonCustomizationPage(null,false,false); //do not show neither the header, nor the footer of this page
} }
} }
/** /**
@ -107,7 +107,7 @@ class WC_ShareYourCart extends WC_Integration {
**/ **/
function add_shareyourcart_integration( $integrations ) { function add_shareyourcart_integration( $integrations ) {
if ( ! class_exists('ShareYourCartAPI') ) // Only allow this integration if we're not already using shareyourcart via another plugin if ( ! class_exists('ShareYourCartAPI') ) // Only allow this integration if we're not already using shareyourcart via another plugin
$integrations[] = 'WC_ShareYourCart'; $integrations[] = 'WC_ShareYourCart';
return $integrations; return $integrations;
} }
add_filter('woocommerce_integrations', 'add_shareyourcart_integration' ); add_filter('woocommerce_integrations', 'add_shareyourcart_integration' );

View File

@ -5,10 +5,10 @@ require_once("class.shareyourcart-wp.php");
if(!class_exists('ShareYourCartWooCommerce',false)){ if(!class_exists('ShareYourCartWooCommerce',false)){
class ShareYourCartWooCommerce extends ShareYourCartWordpressPlugin{ class ShareYourCartWooCommerce extends ShareYourCartWordpressPlugin{
public $_plugin_name = "shareyourcart_woo_commerce"; public $_plugin_name = "shareyourcart_woo_commerce";
public $_post_user_id = 1; public $_post_user_id = 1;
public function processInit(){ public function processInit(){
if(isset($_REQUEST['action'])){ if(isset($_REQUEST['action'])){
switch($_REQUEST['action']){ switch($_REQUEST['action']){
@ -22,11 +22,11 @@ class ShareYourCartWooCommerce extends ShareYourCartWordpressPlugin{
} }
} }
} }
public function isCartActive() { public function isCartActive() {
return in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ); return in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) );
} }
/* /*
* *
* Extend the base class implementation * Extend the base class implementation
@ -34,15 +34,15 @@ class ShareYourCartWooCommerce extends ShareYourCartWordpressPlugin{
*/ */
public function pluginsLoadedHook() { public function pluginsLoadedHook() {
parent::pluginsLoadedHook(); parent::pluginsLoadedHook();
if(!$this->isCartActive()) return; if(!$this->isCartActive()) return;
add_action('init', array(&$this, 'processInit')); add_action('init', array(&$this, 'processInit'));
add_action('woocommerce_before_single_product', array(&$this,'showProductButton')); add_action('woocommerce_before_single_product', array(&$this,'showProductButton'));
add_action('woocommerce_cart_contents', array(&$this,'showCartButton')); add_action('woocommerce_cart_contents', array(&$this,'showCartButton'));
} }
/** /**
* *
* Return the jQuery sibling selector for the product button * Return the jQuery sibling selector for the product button
@ -52,7 +52,7 @@ class ShareYourCartWooCommerce extends ShareYourCartWordpressPlugin{
$selector = parent::getProductButtonPosition(); $selector = parent::getProductButtonPosition();
return (!empty($selector) ? $selector : ".summary .price .amount"); return (!empty($selector) ? $selector : ".summary .price .amount");
} }
/** /**
* *
* Return the jQuery sibling selector for the cart button * Return the jQuery sibling selector for the cart button
@ -62,20 +62,20 @@ class ShareYourCartWooCommerce extends ShareYourCartWordpressPlugin{
$selector = parent::getCartButtonPosition(); $selector = parent::getCartButtonPosition();
return (!empty($selector) ? $selector : ".cart-subtotal .amount"); return (!empty($selector) ? $selector : ".cart-subtotal .amount");
} }
public function getSecretKey() { public function getSecretKey() {
return 'd3ce6c18-7e45-495d-aa4c-8f63edee03a5'; return 'd3ce6c18-7e45-495d-aa4c-8f63edee03a5';
} }
public function isSingleProduct() { public function isSingleProduct() {
return is_singular('product'); return is_singular('product');
} }
protected function saveCoupon($token, $coupon_code, $coupon_value, $coupon_type, $product_unique_ids = array()) { protected function saveCoupon($token, $coupon_code, $coupon_value, $coupon_type, $product_unique_ids = array()) {
// Create coupon // Create coupon
$post_id = $this->_saveCouponPost($coupon_code); $post_id = $this->_saveCouponPost($coupon_code);
// Set coupon meta // Set coupon meta
switch ($coupon_type) { switch ($coupon_type) {
case 'amount': case 'amount':
@ -113,16 +113,16 @@ class ShareYourCartWooCommerce extends ShareYourCartWordpressPlugin{
// parent // parent
parent::saveCoupon( $token, $coupon_code, $coupon_value, $coupon_type ); parent::saveCoupon( $token, $coupon_code, $coupon_value, $coupon_type );
} }
public function applyCoupon($coupon_code) { public function applyCoupon($coupon_code) {
//$this->_loadWooCommerce(); //$this->_loadWooCommerce();
//global $woocommerce; //global $woocommerce;
//$woocommerce->cart->add_discount($coupon_code); //$woocommerce->cart->add_discount($coupon_code);
return; return;
} }
private function _saveCouponPost($coupon_code){ private function _saveCouponPost($coupon_code){
$new_post = array( $new_post = array(
'post_title' => $coupon_code, 'post_title' => $coupon_code,
@ -139,7 +139,7 @@ class ShareYourCartWooCommerce extends ShareYourCartWordpressPlugin{
return $post_id; return $post_id;
} }
public function getButtonCallbackURL() { public function getButtonCallbackURL() {
global $wp_query; global $wp_query;
@ -151,7 +151,7 @@ class ShareYourCartWooCommerce extends ShareYourCartWordpressPlugin{
return $callback_url; return $callback_url;
} }
public function buttonCallback(){ public function buttonCallback(){
if(!$this->isCartActive()) return; if(!$this->isCartActive()) return;
@ -166,10 +166,10 @@ class ShareYourCartWooCommerce extends ShareYourCartWordpressPlugin{
//there is no product set, thus send the products from the shopping cart //there is no product set, thus send the products from the shopping cart
if(!isset($_REQUEST['p'])) if(!isset($_REQUEST['p']))
{ {
if(empty($_SESSION['cart'])) if(empty($_SESSION['cart']))
exit("Cart is empty"); exit("Cart is empty");
foreach($_SESSION['cart'] as $cart_details){ foreach($_SESSION['cart'] as $cart_details){
$params['cart'][] = $this->_getProductDetails($cart_details['product_id']); $params['cart'][] = $this->_getProductDetails($cart_details['product_id']);
} }
@ -179,18 +179,18 @@ class ShareYourCartWooCommerce extends ShareYourCartWordpressPlugin{
$params['cart'][] = $this->_getProductDetails($_REQUEST['p']); $params['cart'][] = $this->_getProductDetails($_REQUEST['p']);
} }
try try
{ {
$this->startSession($params); $this->startSession($params);
} }
catch(Exception $e) catch(Exception $e)
{ {
//display the error to the user //display the error to the user
echo $e->getMessage(); echo $e->getMessage();
} }
exit; exit;
} }
private function _getProductDetails($product_id){ private function _getProductDetails($product_id){
$product = get_product($product_id); $product = get_product($product_id);
@ -198,14 +198,14 @@ class ShareYourCartWooCommerce extends ShareYourCartWordpressPlugin{
ob_start(); ob_start();
echo $product->get_image(); //older WooCommerce versions might allready echo, but newer versions don't, so force it anyway echo $product->get_image(); //older WooCommerce versions might allready echo, but newer versions don't, so force it anyway
$image = ob_get_clean(); $image = ob_get_clean();
//check is image actually a HTML img entity //check is image actually a HTML img entity
if(($doc = @DomDocument::loadHTML($image)) !== FALSE) if(($doc = @DomDocument::loadHTML($image)) !== FALSE)
{ {
$imageTags = $doc->getElementsByTagName('img'); $imageTags = $doc->getElementsByTagName('img');
if($imageTags->length >0 ) if($imageTags->length >0 )
$src = $imageTags->item(0)->getAttribute('src'); $src = $imageTags->item(0)->getAttribute('src');
//replace image only if src has been set //replace image only if src has been set
if (!empty($src)) if (!empty($src))
$image = $src; $image = $src;
@ -215,23 +215,23 @@ class ShareYourCartWooCommerce extends ShareYourCartWordpressPlugin{
"item_name" => $product->get_title(), "item_name" => $product->get_title(),
"item_description" => $product->post->post_excerpt, "item_description" => $product->post->post_excerpt,
"item_url" => get_permalink($product_id), "item_url" => get_permalink($product_id),
"item_price" => $product->price, "item_price" => $product->price,
"item_picture_url" => $image, "item_picture_url" => $image,
"item_unique_id" => $product_id, "item_unique_id" => $product_id,
); );
} }
public function loadSessionData() { public function loadSessionData() {
return; return;
} }
private function _loadWooCommerce(){ private function _loadWooCommerce(){
// Sometimes the WooCommerce Class is not loaded... // Sometimes the WooCommerce Class is not loaded...
if(!class_exists('Woocommerce', false)){ if(!class_exists('Woocommerce', false)){
require_once(ABSPATH . 'wp-content/plugins/woocommerce/woocommerce.php'); require_once(ABSPATH . 'wp-content/plugins/woocommerce/woocommerce.php');
} }
// Important Classes Not included // Important Classes Not included
if(!function_exists('has_post_thumbnail')){ if(!function_exists('has_post_thumbnail')){
require_once(ABSPATH . 'wp-includes/post-thumbnail-template.php'); require_once(ABSPATH . 'wp-includes/post-thumbnail-template.php');

View File

@ -30,7 +30,7 @@ if(!class_exists('ShareYourCartWordpressPlugin',false)){
//if there is installed another plugin with a never version //if there is installed another plugin with a never version
//do not load this one further //do not load this one further
if(!$this->canLoad()) return; if(!$this->canLoad()) return;
//make sure we add this instance //make sure we add this instance
self::$_INSTANCES []= $this; self::$_INSTANCES []= $this;
$this->_PLUGIN_PATH = WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__)); $this->_PLUGIN_PATH = WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__));
@ -57,10 +57,10 @@ if(!class_exists('ShareYourCartWordpressPlugin',false)){
* *
*/ */
protected function getPluginVersion(){ protected function getPluginVersion(){
return self::$_VERSION; return self::$_VERSION;
} }
/** /**
* *
* Return the project's URL * Return the project's URL
@ -109,15 +109,15 @@ if(!class_exists('ShareYourCartWordpressPlugin',false)){
return $plugin; return $plugin;
} }
/** /**
* *
* Get the upload directory * Get the upload directory
* *
*/ */
public function getUploadDir(){ public function getUploadDir(){
$dir = wp_upload_dir(); $dir = wp_upload_dir();
return (!empty($dir['path']) ? $dir['path'] : parent::getUploadDir()); return (!empty($dir['path']) ? $dir['path'] : parent::getUploadDir());
} }
@ -131,14 +131,14 @@ if(!class_exists('ShareYourCartWordpressPlugin',false)){
if(substr($sql,0,12) == "CREATE TABLE"){ if(substr($sql,0,12) == "CREATE TABLE"){
require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
//if this is a create table command, use the special function which compares tables //if this is a create table command, use the special function which compares tables
dbDelta($sql); dbDelta($sql);
} else { } else {
global $wpdb; global $wpdb;
//use the normal query //use the normal query
$wpdb->query($sql); $wpdb->query($sql);
} }
@ -154,7 +154,7 @@ if(!class_exists('ShareYourCartWordpressPlugin',false)){
protected function getRow($sql){ protected function getRow($sql){
global $wpdb; global $wpdb;
//get the row as an associative array //get the row as an associative array
return $wpdb->get_row($sql,ARRAY_A); return $wpdb->get_row($sql,ARRAY_A);
} }
@ -251,7 +251,7 @@ if(!class_exists('ShareYourCartWordpressPlugin',false)){
public function deactivateHook() { public function deactivateHook() {
if(!$this->isCartActive()) return; if(!$this->isCartActive()) return;
$message = ''; $message = '';
$this->deactivate($message); $this->deactivate($message);
@ -275,7 +275,7 @@ if(!class_exists('ShareYourCartWordpressPlugin',false)){
//get the old app_key and client_id //get the old app_key and client_id
$settings = $wpdb->get_row("SELECT app_key, client_id FROM ".$wpdb->base_prefix."shareyourcart_settings LIMIT 1"); $settings = $wpdb->get_row("SELECT app_key, client_id FROM ".$wpdb->base_prefix."shareyourcart_settings LIMIT 1");
if($settings) { if($settings) {
$this->setConfigValue('appKey', $settings->app_key); $this->setConfigValue('appKey', $settings->app_key);
$this->setConfigValue('clientId', $settings->client_id); $this->setConfigValue('clientId', $settings->client_id);
} }
@ -297,7 +297,7 @@ if(!class_exists('ShareYourCartWordpressPlugin',false)){
//this hook is required by WordPress to be static //this hook is required by WordPress to be static
//so call uninstall on the first instance //so call uninstall on the first instance
if(!empty(self::$_INSTANCES)){ if(!empty(self::$_INSTANCES)){
self::$_INSTANCES[0]->uninstall(); self::$_INSTANCES[0]->uninstall();
} else { } else {
@ -315,15 +315,15 @@ if(!class_exists('ShareYourCartWordpressPlugin',false)){
//this is a single call function //this is a single call function
if(!$this->isFirstCall(__FUNCTION__)) return; if(!$this->isFirstCall(__FUNCTION__)) return;
//first, check the SDK status //first, check the SDK status
$this->checkSDKStatus(); $this->checkSDKStatus();
//see if we need to show the update notification //see if we need to show the update notification
$notification = null; $notification = null;
if($this->hasNewerVersion()) if($this->hasNewerVersion())
$notification = "<span class='update-plugins count-$warning_count'><span class='update-count'>" . number_format_i18n(1) . "</span></span>"; $notification = "<span class='update-plugins count-$warning_count'><span class='update-count'>" . number_format_i18n(1) . "</span></span>";
$page = add_menu_page( $page = add_menu_page(
__('Share your cart settings'), __('Share your cart settings'),
__('ShareYourCart').$notification, __('ShareYourCart').$notification,
@ -334,7 +334,7 @@ if(!class_exists('ShareYourCartWordpressPlugin',false)){
); );
add_action( 'admin_head-'.$page, array(&$this, 'showAdminHeader')); add_action( 'admin_head-'.$page, array(&$this, 'showAdminHeader'));
if($this->isActive()) if($this->isActive())
{ {
//show the rest of the menu ONLY if the plugin is active //show the rest of the menu ONLY if the plugin is active
$page = add_submenu_page( $page = add_submenu_page(

View File

@ -10,9 +10,9 @@
*/ */
if(!class_exists('ShareYourCartAPI',false)){ if(!class_exists('ShareYourCartAPI',false)){
class ShareYourCartAPI { class ShareYourCartAPI {
protected $SHAREYOURCART_URL = "www.shareyourcart.com"; protected $SHAREYOURCART_URL = "www.shareyourcart.com";
protected $SHAREYOURCART_SANDBOX_URL = "sandbox.shareyourcart.com"; protected $SHAREYOURCART_SANDBOX_URL = "sandbox.shareyourcart.com";
protected $SHAREYOURCART_API; protected $SHAREYOURCART_API;
@ -27,15 +27,15 @@ class ShareYourCartAPI {
protected $SHAREYOURCART_CONFIGURE; protected $SHAREYOURCART_CONFIGURE;
protected $SHAREYOURCART_BUTTON_JS; protected $SHAREYOURCART_BUTTON_JS;
protected $SHAREYOURCART_BUTTON_URL; protected $SHAREYOURCART_BUTTON_URL;
/** /**
* Constructor * Constructor
* @param null * @param null
*/ */
function __construct() { function __construct() {
$is_live = true; $is_live = true;
//check if the current object has a secret key function //check if the current object has a secret key function
//this is for backward compatibility //this is for backward compatibility
if(method_exists ($this,'getSecretKey')){ if(method_exists ($this,'getSecretKey')){
@ -43,14 +43,14 @@ class ShareYourCartAPI {
if(empty($secretKey)){ if(empty($secretKey)){
throw new Exception(SyC::t('sdk',"You must specify a valid secret key")); throw new Exception(SyC::t('sdk',"You must specify a valid secret key"));
} }
//check if the secret key is a sandbox one //check if the secret key is a sandbox one
if(strpos($secretKey,"sndbx_") === 0){ if(strpos($secretKey,"sndbx_") === 0){
$this->SHAREYOURCART_URL = $this->SHAREYOURCART_SANDBOX_URL; $this->SHAREYOURCART_URL = $this->SHAREYOURCART_SANDBOX_URL;
$is_live = false; $is_live = false;
} }
} }
$this->SHAREYOURCART_API = (isset($_SERVER['HTTPS']) && !strcasecmp($_SERVER['HTTPS'],'on') ? 'https://' : 'http://') . $this->SHAREYOURCART_URL; $this->SHAREYOURCART_API = (isset($_SERVER['HTTPS']) && !strcasecmp($_SERVER['HTTPS'],'on') ? 'https://' : 'http://') . $this->SHAREYOURCART_URL;
$this->SHAREYOURCART_REGISTER = $this->SHAREYOURCART_API.'/account/create'; $this->SHAREYOURCART_REGISTER = $this->SHAREYOURCART_API.'/account/create';
$this->SHAREYOURCART_API_REGISTER = $this->SHAREYOURCART_API.'/account/create'; $this->SHAREYOURCART_API_REGISTER = $this->SHAREYOURCART_API.'/account/create';
@ -61,21 +61,21 @@ class ShareYourCartAPI {
$this->SHAREYOURCART_API_VALIDATE = $this->SHAREYOURCART_API.'/session/validate'; $this->SHAREYOURCART_API_VALIDATE = $this->SHAREYOURCART_API.'/session/validate';
$this->SHAREYOURCART_API_STATUS = $this->SHAREYOURCART_API.'/sdk'; $this->SHAREYOURCART_API_STATUS = $this->SHAREYOURCART_API.'/sdk';
$this->SHAREYOURCART_API_TRANSLATION = $this->SHAREYOURCART_API.'/sdk/translation'; $this->SHAREYOURCART_API_TRANSLATION = $this->SHAREYOURCART_API.'/sdk/translation';
$this->SHAREYOURCART_CONFIGURE = $this->SHAREYOURCART_API.'/configure'; $this->SHAREYOURCART_CONFIGURE = $this->SHAREYOURCART_API.'/configure';
$this->SHAREYOURCART_BUTTON_JS = $this->SHAREYOURCART_API.'/js/'.($is_live ? 'button.js' : 'button_sandbox.js'); $this->SHAREYOURCART_BUTTON_JS = $this->SHAREYOURCART_API.'/js/'.($is_live ? 'button.js' : 'button_sandbox.js');
$this->SHAREYOURCART_BUTTON_URL = $this->SHAREYOURCART_API.'/button'; $this->SHAREYOURCART_BUTTON_URL = $this->SHAREYOURCART_API.'/button';
} }
/** /**
* startSession * startSession
* @param array $params * @param array $params
* @return array $data * @return array $data
*/ */
public function startSession($params) { public function startSession($params) {
//make sure the session is started //make sure the session is started
if(session_id() == '') if(session_id() == '')
session_start(); session_start();
$session = curl_init($this->SHAREYOURCART_API_CREATE); $session = curl_init($this->SHAREYOURCART_API_CREATE);
// Tell curl to use HTTP POST // Tell curl to use HTTP POST
@ -89,45 +89,45 @@ class ShareYourCartAPI {
$response = curl_exec($session); $response = curl_exec($session);
$httpCode = curl_getinfo($session, CURLINFO_HTTP_CODE); $httpCode = curl_getinfo($session, CURLINFO_HTTP_CODE);
curl_close($session); curl_close($session);
// If the operation was not succesfull, print the error // If the operation was not succesfull, print the error
if($httpCode != 200) if($httpCode != 200)
throw new Exception($response); throw new Exception($response);
// Decode the result // Decode the result
$results = json_decode($response, true); $results = json_decode($response, true);
// Find the token // Find the token
if(isset($results['token'])) { if(isset($results['token'])) {
// Link the token with the current cart ( held in session id ) // Link the token with the current cart ( held in session id )
$data = array( $data = array(
'token' => $results['token'], 'token' => $results['token'],
'session_id' => session_id(), 'session_id' => session_id(),
); );
// A token was obtained, so redirect the browser // A token was obtained, so redirect the browser
header("Location: $results[session_url]", true, 302); header("Location: $results[session_url]", true, 302);
return $data; return $data;
} }
//show the raw response received ( for debug purposes ) //show the raw response received ( for debug purposes )
throw new Exception($response); throw new Exception($response);
} }
/** /**
* make sure the coupon is valid * make sure the coupon is valid
* @param null * @param null
*/ */
public function assertCouponIsValid($token, $coupon_code, $coupon_value, $coupon_type) { public function assertCouponIsValid($token, $coupon_code, $coupon_value, $coupon_type) {
// Verifies POST information // Verifies POST information
if(!isset($token, $coupon_code, $coupon_value, $coupon_type)) { if(!isset($token, $coupon_code, $coupon_value, $coupon_type)) {
throw new Exception(SyC::t('sdk',"At least one of the parameters is missing.")); throw new Exception(SyC::t('sdk',"At least one of the parameters is missing."));
} }
// Urlencode and concatenate the POST arguments // Urlencode and concatenate the POST arguments
$params = array( $params = array(
'token' => $token, 'token' => $token,
@ -150,28 +150,28 @@ class ShareYourCartAPI {
$response = curl_exec($session); $response = curl_exec($session);
$httpCode = curl_getinfo($session, CURLINFO_HTTP_CODE); $httpCode = curl_getinfo($session, CURLINFO_HTTP_CODE);
curl_close($session); curl_close($session);
//if the operation was not succesfull, print the error //if the operation was not succesfull, print the error
if($httpCode != 200) if($httpCode != 200)
throw new Exception(SyC::t('sdk',"Coupon Invalid: {coupon}", array('{coupon}' => $response))); throw new Exception(SyC::t('sdk',"Coupon Invalid: {coupon}", array('{coupon}' => $response)));
$results = json_decode($response, true); $results = json_decode($response, true);
//if the result is not valid, print it //if the result is not valid, print it
if(!isset($results['valid']) || !($results['valid'] === true)) if(!isset($results['valid']) || !($results['valid'] === true))
throw new Exception(SyC::t('sdk',"Coupon Invalid: {coupon}", array('{coupon}' => $response))); throw new Exception(SyC::t('sdk',"Coupon Invalid: {coupon}", array('{coupon}' => $response)));
} }
/** /**
* register * register
* @param string $secretKey * @param string $secretKey
* @param string $domain * @param string $domain
* @param string $email * @param string $email
* @param string $message * @param string $message
* @return array json_decode * @return array json_decode
*/ */
public function register($secretKey, $domain, $email, &$message = null) { public function register($secretKey, $domain, $email, &$message = null) {
// Urlencode and concatenate the POST arguments // Urlencode and concatenate the POST arguments
$params = array( $params = array(
'secret_key' => $secretKey, 'secret_key' => $secretKey,
@ -193,36 +193,36 @@ class ShareYourCartAPI {
$response = curl_exec($session); $response = curl_exec($session);
$httpCode = curl_getinfo($session, CURLINFO_HTTP_CODE); $httpCode = curl_getinfo($session, CURLINFO_HTTP_CODE);
curl_close($session); curl_close($session);
// If the operation was not succesfull, return FALSE // If the operation was not succesfull, return FALSE
if($httpCode != 200) { if($httpCode != 200) {
if(isset($message)) $message = $response; if(isset($message)) $message = $response;
return false; return false;
} }
//if the caller is expecting a message //if the caller is expecting a message
//let him know what happened //let him know what happened
if(isset($message)){ if(isset($message)){
$message = SyC::t('sdk','The account has been registered'); $message = SyC::t('sdk','The account has been registered');
} }
// Return the response after decoding it // Return the response after decoding it
return json_decode($response, true); return json_decode($response, true);
} }
/** /**
* recover * recover
* @param string $secretKey * @param string $secretKey
* @param string $domain * @param string $domain
* @param string $email * @param string $email
* @param string $message * @param string $message
* @return boolean * @return boolean
*/ */
public function recover($secretKey, $domain, $email, &$message = null) { public function recover($secretKey, $domain, $email, &$message = null) {
// Urlencode and concatenate the POST arguments // Urlencode and concatenate the POST arguments
$params = array( $params = array(
'secret_key' => $secretKey, 'secret_key' => $secretKey,
@ -244,36 +244,36 @@ class ShareYourCartAPI {
$response = curl_exec($session); $response = curl_exec($session);
$httpCode = curl_getinfo($session, CURLINFO_HTTP_CODE); $httpCode = curl_getinfo($session, CURLINFO_HTTP_CODE);
curl_close($session); curl_close($session);
//if the operation was not succesfull, return FALSE //if the operation was not succesfull, return FALSE
if($httpCode != 200) { if($httpCode != 200) {
if(isset($message)) $message = $response; if(isset($message)) $message = $response;
return false; return false;
} }
//if the caller is expecting a message //if the caller is expecting a message
//let him know what happened //let him know what happened
if(isset($message)){ if(isset($message)){
$message = (!empty($response) ? $response : SyC::t('sdk',"An email has been sent with your credentials at {email}",array('{email}' => $email))); $message = (!empty($response) ? $response : SyC::t('sdk',"An email has been sent with your credentials at {email}",array('{email}' => $email)));
} }
return true; return true;
} }
/** /**
* setAccountStatus * setAccountStatus
* @param string $secretKey * @param string $secretKey
* @param string $clientId * @param string $clientId
* @param string $appKey * @param string $appKey
* @param string $activate * @param string $activate
* @param string $message * @param string $message
* @return boolean * @return boolean
*/ */
public function setAccountStatus($secretKey, $clientId, $appKey, $activate = true, &$message = null) { public function setAccountStatus($secretKey, $clientId, $appKey, $activate = true, &$message = null) {
// Urlencode and concatenate the POST arguments // Urlencode and concatenate the POST arguments
$params = array( $params = array(
'secret_key' => $secretKey, 'secret_key' => $secretKey,
@ -295,40 +295,40 @@ class ShareYourCartAPI {
$response = curl_exec($session); $response = curl_exec($session);
$httpCode = curl_getinfo($session, CURLINFO_HTTP_CODE); $httpCode = curl_getinfo($session, CURLINFO_HTTP_CODE);
curl_close($session); curl_close($session);
// Notify the caller // Notify the caller
if($httpCode != 200) { if($httpCode != 200) {
if(isset($message)) $message = $response; if(isset($message)) $message = $response;
return false; return false;
} }
//if the caller is expecting a message //if the caller is expecting a message
//let him know what happened //let him know what happened
if(isset($message)){ if(isset($message)){
$message = (!empty($response) ? $response : ($activate ? SyC::t('sdk','The account has been enabled') : SyC::t('sdk','The account has been disabled'))); $message = (!empty($response) ? $response : ($activate ? SyC::t('sdk','The account has been enabled') : SyC::t('sdk','The account has been disabled')));
} }
return true; return true;
} }
/** /**
* setAccountStatus * setAccountStatus
* @param string $secretKey * @param string $secretKey
* @param string $clientId * @param string $clientId
* @param string $appKey * @param string $appKey
* @param string $message * @param string $message
* @return array or FALSE * @return array or FALSE
*/ */
public function getSDKStatus($secretKey=null, $clientId=null, $appKey=null, &$message = null) public function getSDKStatus($secretKey=null, $clientId=null, $appKey=null, &$message = null)
{ {
$params = array(); $params = array();
if(isset($secretKey)) $params['secret_key'] = $secretKey; if(isset($secretKey)) $params['secret_key'] = $secretKey;
if(isset($clientId)) $params['client_id'] = $clientId; if(isset($clientId)) $params['client_id'] = $clientId;
if(isset($appKey)) $params['app_key'] = $appKey; if(isset($appKey)) $params['app_key'] = $appKey;
//make the API call //make the API call
$session = curl_init($this->SHAREYOURCART_API_STATUS); $session = curl_init($this->SHAREYOURCART_API_STATUS);
@ -343,18 +343,18 @@ class ShareYourCartAPI {
$response = curl_exec($session); $response = curl_exec($session);
$httpCode = curl_getinfo($session, CURLINFO_HTTP_CODE); $httpCode = curl_getinfo($session, CURLINFO_HTTP_CODE);
curl_close($session); curl_close($session);
// Notify the caller // Notify the caller
if($httpCode != 200) { if($httpCode != 200) {
if(isset($message)) $message = $response; if(isset($message)) $message = $response;
return false; return false;
} }
// Decode the result // Decode the result
return json_decode($response, true); return json_decode($response, true);
} }
/** /**
* *
* Returns an array of messages for the SDK, in the specified language * Returns an array of messages for the SDK, in the specified language
@ -363,7 +363,7 @@ class ShareYourCartAPI {
public function getSDKTranslation($lang, &$message = null) public function getSDKTranslation($lang, &$message = null)
{ {
$params = array('lang' => $lang); $params = array('lang' => $lang);
//make the API call //make the API call
$session = curl_init($this->SHAREYOURCART_API_TRANSLATION); $session = curl_init($this->SHAREYOURCART_API_TRANSLATION);
@ -378,14 +378,14 @@ class ShareYourCartAPI {
$response = curl_exec($session); $response = curl_exec($session);
$httpCode = curl_getinfo($session, CURLINFO_HTTP_CODE); $httpCode = curl_getinfo($session, CURLINFO_HTTP_CODE);
curl_close($session); curl_close($session);
// Notify the caller // Notify the caller
if($httpCode != 200) { if($httpCode != 200) {
if(isset($message)) $message = $response; if(isset($message)) $message = $response;
return false; return false;
} }
// Decode the result // Decode the result
return json_decode($response, true); return json_decode($response, true);
} }
@ -402,7 +402,7 @@ class SyC
static $_messages; static $_messages;
static $_language = 'en'; static $_language = 'en';
static $loadLanguage = array('SyC','loadFileLanguage'); //variable that holds the name of the function used to load a particular language static $loadLanguage = array('SyC','loadFileLanguage'); //variable that holds the name of the function used to load a particular language
/** /**
* *
* Change the language the SDK should be displayed in * Change the language the SDK should be displayed in
@ -410,11 +410,11 @@ class SyC
*/ */
public static function setLanguage($newLanguage = null){ public static function setLanguage($newLanguage = null){
self::$_language = $newLanguage; self::$_language = $newLanguage;
//reset the old messages, so that they are reloaded //reset the old messages, so that they are reloaded
self::$_messages = null; self::$_messages = null;
} }
/** /**
* *
* Get the language that is currently loaded * Get the language that is currently loaded
@ -423,7 +423,7 @@ class SyC
public static function getLanguage(){ public static function getLanguage(){
return self::$_language; return self::$_language;
} }
/** /**
* Return the checksum of the currently loaded translation * Return the checksum of the currently loaded translation
*/ */
@ -431,14 +431,14 @@ class SyC
{ {
//load the translation from file if not done so //load the translation from file if not done so
if(!isset(self::$_messages)){ if(!isset(self::$_messages)){
//load the language //load the language
self::$_messages = call_user_func(self::$loadLanguage,self::$_language,$category); self::$_messages = call_user_func(self::$loadLanguage,self::$_language,$category);
} }
return md5(json_encode(self::$_messages)); return md5(json_encode(self::$_messages));
} }
/** /**
* Reload the language * Reload the language
*/ */
@ -446,29 +446,29 @@ class SyC
{ {
self::$_messages = null; self::$_messages = null;
} }
/* /*
* Translate the specified message * Translate the specified message
* *
*/ */
public static function t($category,$message,$params=array()) public static function t($category,$message,$params=array())
{ {
//load the translation from file if not done so //load the translation from file if not done so
if(!isset(self::$_messages)){ if(!isset(self::$_messages)){
//load the language //load the language
self::$_messages = call_user_func(self::$loadLanguage,self::$_language,$category); self::$_messages = call_user_func(self::$loadLanguage,self::$_language,$category);
} }
//check if the text has a valid translation //check if the text has a valid translation
if(isset(self::$_messages[$message]) && !empty(self::$_messages[$message])){ if(isset(self::$_messages[$message]) && !empty(self::$_messages[$message])){
$message = self::$_messages[$message]; $message = self::$_messages[$message];
} }
//return the translated message, with the parameters replaced //return the translated message, with the parameters replaced
return $params!==array() ? strtr($message,$params) : $message; return $params!==array() ? strtr($message,$params) : $message;
} }
/** /**
* *
* change the language loader method * change the language loader method
@ -479,13 +479,13 @@ class SyC
//make sure the loader is ok //make sure the loader is ok
if(!is_callable($loader)) if(!is_callable($loader))
throw new Exception(SyC::t('sdk',"The language loader is not a valid callback")); throw new Exception(SyC::t('sdk',"The language loader is not a valid callback"));
self::$loadLanguage = $loader; self::$loadLanguage = $loader;
//reset the old messages, so that they are reloaded with the new loader //reset the old messages, so that they are reloaded with the new loader
self::$_messages = null; self::$_messages = null;
} }
/** /**
* *
* Function to load a language from the hard-drive. * Function to load a language from the hard-drive.
@ -495,24 +495,24 @@ class SyC
{ {
//The language is the folder name, and the category is the name of the file //The language is the folder name, and the category is the name of the file
$messageFile = dirname(__FILE__).DIRECTORY_SEPARATOR.'messages'.DIRECTORY_SEPARATOR.$lang.DIRECTORY_SEPARATOR.$category.'.php'; $messageFile = dirname(__FILE__).DIRECTORY_SEPARATOR.'messages'.DIRECTORY_SEPARATOR.$lang.DIRECTORY_SEPARATOR.$category.'.php';
$messages = null; $messages = null;
if(is_file($messageFile)) if(is_file($messageFile))
{ {
$messages=include($messageFile); $messages=include($messageFile);
} }
//make sure we have an array for this variable //make sure we have an array for this variable
if(!is_array($messages)) $messages=array(); if(!is_array($messages)) $messages=array();
return $messages; return $messages;
} }
public static function relativepath($from, $to, $ps = '/' ,$ds = DIRECTORY_SEPARATOR) public static function relativepath($from, $to, $ps = '/' ,$ds = DIRECTORY_SEPARATOR)
{ {
$arFrom = explode($ds, rtrim($from, $ds)); $arFrom = explode($ds, rtrim($from, $ds));
$arTo = explode($ds, rtrim($to, $ds)); $arTo = explode($ds, rtrim($to, $ds));
while(count($arFrom) && count($arTo) && ($arFrom[0] == $arTo[0])) while(count($arFrom) && count($arTo) && ($arFrom[0] == $arTo[0]))
{ {
array_shift($arFrom); array_shift($arFrom);
@ -581,7 +581,7 @@ class SyC
$length = strlen($needle); $length = strlen($needle);
return (substr($haystack, 0, $length) === $needle); return (substr($haystack, 0, $length) === $needle);
} }
/** /**
* returns TRUE if haystack ends with needle * returns TRUE if haystack ends with needle
*/ */

View File

@ -20,19 +20,19 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
private static $_SDK_VERSION = '1.9'; //the first one is the SDK main version, while the second one is it's revision private static $_SDK_VERSION = '1.9'; //the first one is the SDK main version, while the second one is it's revision
protected static $_DB_VERSION = '1.1'; protected static $_DB_VERSION = '1.1';
protected $SDK_ANALYTICS = true; protected $SDK_ANALYTICS = true;
/** /**
* Constructor * Constructor
* @param null * @param null
*/ */
function __construct() { function __construct() {
//set exception handler //set exception handler
if(set_exception_handler(array(&$this,'UncaughtExceptionHandler')) !== null) if(set_exception_handler(array(&$this,'UncaughtExceptionHandler')) !== null)
restore_exception_handler(); //if there allready was an exception handler, revert back to it restore_exception_handler(); //if there allready was an exception handler, revert back to it
parent::__construct(); parent::__construct();
//now, add the api version to the button_js, in order to force users to download the latest //now, add the api version to the button_js, in order to force users to download the latest
//JS file //JS file
if(!$this->isDebugMode()){ if(!$this->isDebugMode()){
@ -41,12 +41,12 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
$this->SHAREYOURCART_BUTTON_JS = $this->SHAREYOURCART_API.'/js/button.dev.js'; $this->SHAREYOURCART_BUTTON_JS = $this->SHAREYOURCART_API.'/js/button.dev.js';
} }
$this->SHAREYOURCART_BUTTON_URL .= '?client_id='. $this->getClientId(); $this->SHAREYOURCART_BUTTON_URL .= '?client_id='. $this->getClientId();
//set the language & it's loader //set the language & it's loader
SyC::setLanguageLoader(array(&$this,'loadLanguage')); SyC::setLanguageLoader(array(&$this,'loadLanguage'));
SyC::setLanguage($this->getConfigValue('lang')); SyC::setLanguage($this->getConfigValue('lang'));
} }
/** /**
* Execute NonQuery SQL * Execute NonQuery SQL
* @param string action * @param string action
@ -96,10 +96,10 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
* @return boolean / array * @return boolean / array
*/ */
protected function getCurrentProductDetails(){ protected function getCurrentProductDetails(){
return FALSE; return FALSE;
} }
/** /**
* *
* Return TRUE if this page describes a single product, otherwise FALSE * Return TRUE if this page describes a single product, otherwise FALSE
@ -115,7 +115,7 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
public function isOutOfStock(){ public function isOutOfStock(){
return FALSE; return FALSE;
} }
/** /**
* *
* Return the URL to be called when the button is pressed * Return the URL to be called when the button is pressed
@ -159,7 +159,7 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
* *
*/ */
protected abstract function applyCoupon($coupon_code); protected abstract function applyCoupon($coupon_code);
/** /**
* *
* Return the jQuery sibling selector for the product button * Return the jQuery sibling selector for the product button
@ -168,7 +168,7 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
protected function getProductButtonPosition(){ protected function getProductButtonPosition(){
return $this->getConfigValue('product_button_position'); return $this->getConfigValue('product_button_position');
} }
/** /**
* *
* Return the jQuery sibling selector for the cart button * Return the jQuery sibling selector for the cart button
@ -177,7 +177,7 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
protected function getCartButtonPosition(){ protected function getCartButtonPosition(){
return $this->getConfigValue('cart_button_position'); return $this->getConfigValue('cart_button_position');
} }
/** /**
* *
* Get the plugin version. * Get the plugin version.
@ -196,10 +196,10 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
//make sure a developer enters only a number as a version //make sure a developer enters only a number as a version
if(!is_int($minor_version = $this->getPluginVersion())) if(!is_int($minor_version = $this->getPluginVersion()))
throw new Exception(SyC::t('sdk','The Plugin Version must be an integer')); throw new Exception(SyC::t('sdk','The Plugin Version must be an integer'));
return self::$_SDK_VERSION.'.'.$minor_version; return self::$_SDK_VERSION.'.'.$minor_version;
} }
/** /**
* *
* Returns TRUE if the account is in debug mode * Returns TRUE if the account is in debug mode
@ -208,10 +208,10 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
public function isDebugMode() public function isDebugMode()
{ {
$val =$this->getConfigValue('debug'); $val =$this->getConfigValue('debug');
return !empty($val); return !empty($val);
} }
/** /**
* *
* Return TRUE if there is a newer version of the plugin * Return TRUE if there is a newer version of the plugin
@ -221,7 +221,7 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
{ {
return version_compare($this->getVersion(),$this->getConfigValue('latest_version'),'<'); return version_compare($this->getVersion(),$this->getConfigValue('latest_version'),'<');
} }
/** /**
* *
* Check if this instance can load, or not! * Check if this instance can load, or not!
@ -230,14 +230,14 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
*/ */
protected function canLoad() protected function canLoad()
{ {
$v = version_compare($this->getVersion(),$this->getConfigValue('plugin_current_version')); $v = version_compare($this->getVersion(),$this->getConfigValue('plugin_current_version'));
//first, check if this instance is the latest one, or not //first, check if this instance is the latest one, or not
if($v < 0) return false; if($v < 0) return false;
//save the latest version, for later reference //save the latest version, for later reference
if($v > 0 ) if($v > 0 )
$this->setConfigValue('plugin_current_version',$this->getVersion()); $this->setConfigValue('plugin_current_version',$this->getVersion());
return true; return true;
} }
@ -275,10 +275,10 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
$appKey = $this->getAppKey(); $appKey = $this->getAppKey();
$clientId = $this->getClientId(); $clientId = $this->getClientId();
if(!empty($appKey) && !empty($clientId)){ if(!empty($appKey) && !empty($clientId)){
$activated = $this->activate($message); $activated = $this->activate($message);
} }
//set some default value, like the button skin //set some default value, like the button skin
$skin = $this->getConfigValue('button_skin'); $skin = $this->getConfigValue('button_skin');
if(empty($skin)){ if(empty($skin)){
@ -400,11 +400,11 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
//reset the Location, as the following code might give an error //reset the Location, as the following code might give an error
//and the developer needs to be aware of it //and the developer needs to be aware of it
$headers = headers_list(); $headers = headers_list();
header('Location:'); header('Location:');
//save session details //save session details
$this->insertRow($this->getTableName('shareyourcart_tokens'), $data); $this->insertRow($this->getTableName('shareyourcart_tokens'), $data);
//we can't rely on the fact that the row has been inserted, so check! //we can't rely on the fact that the row has been inserted, so check!
if($this->getSessionId($data['token']) === null) if($this->getSessionId($data['token']) === null)
throw new Exception(SyC::t('sdk','Token cannot be saved. Check your "{table_name}" table permissions.', array('{table_name}' => $this->getTableName('shareyourcart_tokens')))); throw new Exception(SyC::t('sdk','Token cannot be saved. Check your "{table_name}" table permissions.', array('{table_name}' => $this->getTableName('shareyourcart_tokens'))));
@ -474,24 +474,24 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
* @return boolean * @return boolean
*/ */
protected function renderButton($callback_url,$position = null) { protected function renderButton($callback_url,$position = null) {
$data = array( $data = array(
'current_button_type' => $this->getConfigValue("button_type"), 'current_button_type' => $this->getConfigValue("button_type"),
'button_html' => $this->getConfigValue("button_html"), 'button_html' => $this->getConfigValue("button_html"),
'button_img' => $this->getUrl($this->getConfigValue("btn-img")), 'button_img' => $this->getUrl($this->getConfigValue("btn-img")),
'button_img_width' => $this->getConfigValue("btn-img-width"), 'button_img_width' => $this->getConfigValue("btn-img-width"),
'button_img_height' => $this->getConfigValue("btn-img-height"), 'button_img_height' => $this->getConfigValue("btn-img-height"),
'button_img_hover' => $this->getUrl($this->getConfigValue("btn-img-h")), 'button_img_hover' => $this->getUrl($this->getConfigValue("btn-img-h")),
'button_img_hover_width' => $this->getConfigValue("btn-img-h-width"), 'button_img_hover_width' => $this->getConfigValue("btn-img-h-width"),
'button_img_hover_height' => $this->getConfigValue("btn-img-h-height"), 'button_img_hover_height' => $this->getConfigValue("btn-img-h-height"),
'is_product_page' => $this->isSingleProduct(), 'is_product_page' => $this->isSingleProduct(),
'position_'.(SyC::startsWith($position,"/*before*/") ? 'before' : 'after') => $position, 'position_'.(SyC::startsWith($position,"/*before*/") ? 'before' : 'after') => $position,
); );
$output = null; $output = null;
switch ($data['current_button_type']) switch ($data['current_button_type'])
{ {
@ -545,7 +545,7 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
* *
*/ */
public function showCartButton() { public function showCartButton() {
echo $this->getCartButton(); echo $this->getCartButton();
} }
@ -607,11 +607,11 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
* @return boolean * @return boolean
*/ */
public function getAdminHeader() { public function getAdminHeader() {
//this is a single call function //this is a single call function
if (!$this->isFirstCall(__FUNCTION__)) if (!$this->isFirstCall(__FUNCTION__))
return; return;
//check the SDK status //check the SDK status
$this->checkSDKStatus(true); //force a check, as the admin might have changed the language in the configure page, so we need to sync with it $this->checkSDKStatus(true); //force a check, as the admin might have changed the language in the configure page, so we need to sync with it
@ -642,7 +642,7 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
$status_message = ''; //this is to be used for good messages $status_message = ''; //this is to be used for good messages
$error_message = ''; //this is to be used for bad messages $error_message = ''; //this is to be used for bad messages
$refresh = false; $refresh = false;
//check if this is a post for this particular page //check if this is a post for this particular page
if ($_SERVER['REQUEST_METHOD'] == 'POST' && if ($_SERVER['REQUEST_METHOD'] == 'POST' &&
!empty($_POST['syc-account-form'])) { !empty($_POST['syc-account-form'])) {
@ -661,42 +661,42 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
//the account did not activate, so show the error //the account did not activate, so show the error
$error_message = $message; $error_message = $message;
} }
//since we might have changed the status, REFRESH //since we might have changed the status, REFRESH
$refresh = true; $refresh = true;
} }
//the user decided to disable the API //the user decided to disable the API
else if ($_SERVER['REQUEST_METHOD'] == 'POST' && else if ($_SERVER['REQUEST_METHOD'] == 'POST' &&
!empty($_POST['disable-API'])){ !empty($_POST['disable-API'])){
$message = ''; $message = '';
if($this->deactivate($message) == true) { if($this->deactivate($message) == true) {
$status_message = $message; $status_message = $message;
} else { } else {
$error_message = $message; $error_message = $message;
} }
//since we might have changed the status, REFRESH //since we might have changed the status, REFRESH
$refresh = true; $refresh = true;
} }
//the user decided to activate the API //the user decided to activate the API
else if ($_SERVER['REQUEST_METHOD'] == 'POST' && else if ($_SERVER['REQUEST_METHOD'] == 'POST' &&
!empty($_POST['enable-API'])){ !empty($_POST['enable-API'])){
$message = ''; $message = '';
if($this->activate($message) == true) { if($this->activate($message) == true) {
$status_message = $message; $status_message = $message;
} else { } else {
$error_message = $message; $error_message = $message;
} }
//since we might have changed the status, REFRESH //since we might have changed the status, REFRESH
$refresh = true; $refresh = true;
} }
//check if the user want's to recover his account //check if the user want's to recover his account
else if (@$_REQUEST['syc-account'] === 'recover'){ else if (@$_REQUEST['syc-account'] === 'recover'){
@ -708,22 +708,22 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
//try to recover if the user posted the form //try to recover if the user posted the form
$show_form = !$this->recover($this->getSecretKey(), @$_REQUEST['domain'], @$_REQUEST['email'], $status_message); $show_form = !$this->recover($this->getSecretKey(), @$_REQUEST['domain'], @$_REQUEST['email'], $status_message);
} }
//if we need to show the form, the recovery failed //if we need to show the form, the recovery failed
if($show_form) if($show_form)
{ {
//if there is a message, put the form on a new line //if there is a message, put the form on a new line
$error_message = $status_message; $error_message = $status_message;
$status_message = $this->renderView('account-recover-partial'); $status_message = $this->renderView('account-recover-partial');
} }
else else
{ {
//Refresh in order to get rid of the GET parameter //Refresh in order to get rid of the GET parameter
$refresh = true; $refresh = true;
} }
} }
else if (@$_REQUEST['syc-account'] === 'create'){ else if (@$_REQUEST['syc-account'] === 'create'){
//by default, show the form if we are here //by default, show the form if we are here
$show_form = true; $show_form = true;
if($_SERVER['REQUEST_METHOD'] == 'POST' && if($_SERVER['REQUEST_METHOD'] == 'POST' &&
@ -733,14 +733,14 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
if(isset($_POST['syc-terms-agreement'])) if(isset($_POST['syc-terms-agreement']))
{ {
//try to create the account if the user posted the form //try to create the account if the user posted the form
if (!(($register = $this->register($this->getSecretKey(), @$_REQUEST['domain'], @$_REQUEST['email'], $status_message)) === false)) if (!(($register = $this->register($this->getSecretKey(), @$_REQUEST['domain'], @$_REQUEST['email'], $status_message)) === false))
{ {
$this->setConfigValue('appKey', @$register['app_key']); $this->setConfigValue('appKey', @$register['app_key']);
$this->setConfigValue('clientId', @$register['client_id']); $this->setConfigValue('clientId', @$register['client_id']);
$this->setConfigValue("account_status", "active"); $this->setConfigValue("account_status", "active");
$show_form = false; //no need to show the register form anymore $show_form = false; //no need to show the register form anymore
//since we might have changed the status, REFRESH //since we might have changed the status, REFRESH
$refresh = true; $refresh = true;
} }
@ -751,7 +751,7 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
$status_message = SyC::t('sdk',"Error. You must agree with the terms and conditions bellow"); $status_message = SyC::t('sdk',"Error. You must agree with the terms and conditions bellow");
} }
} }
//if we need to show the form //if we need to show the form
if($show_form) if($show_form)
{ {
@ -760,10 +760,10 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
$status_message = $this->renderView('account-create-partial'); $status_message = $this->renderView('account-create-partial');
} }
} }
//make sure there is a session variable setup //make sure there is a session variable setup
@session_start(); @session_start();
//since switching the API status has a great impact on how the UI looks, refresh the page //since switching the API status has a great impact on how the UI looks, refresh the page
//just to make sure the UI is using the latest value //just to make sure the UI is using the latest value
if($refresh) if($refresh)
@ -775,14 +775,14 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
else else
{ {
//load the variables, if any //load the variables, if any
//if there is a status message //if there is a status message
if(!empty($_SESSION['_syc_status_message'])) if(!empty($_SESSION['_syc_status_message']))
{ {
$status_message = $_SESSION['_syc_status_message']; $status_message = $_SESSION['_syc_status_message'];
unset($_SESSION['_syc_status_message']); unset($_SESSION['_syc_status_message']);
} }
//if there is an error message //if there is an error message
if(!empty($_SESSION['_syc_error_message'])) if(!empty($_SESSION['_syc_error_message']))
{ {
@ -790,7 +790,7 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
unset($_SESSION['_syc_error_message']); unset($_SESSION['_syc_error_message']);
} }
} }
// Display the view // Display the view
return $this->renderView('admin-page',array( return $this->renderView('admin-page',array(
'html' => $html, 'html' => $html,
@ -830,7 +830,7 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
//set the button position //set the button position
$this->setConfigValue("button_position", $_POST['button_position']); $this->setConfigValue("button_position", $_POST['button_position']);
//set the button height //set the button height
$this->setConfigValue("dont_set_height", empty($_POST['show_on_single_row'])); $this->setConfigValue("dont_set_height", empty($_POST['show_on_single_row']));
@ -842,7 +842,7 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
//set the show' //set the show'
$this->setConfigValue("hide_on_checkout", empty($_POST['show_on_checkout'])); $this->setConfigValue("hide_on_checkout", empty($_POST['show_on_checkout']));
//set button position //set button position
$this->setConfigValue("product_button_position",$_POST['product_button_position']); $this->setConfigValue("product_button_position",$_POST['product_button_position']);
$this->setConfigValue("cart_button_position",$_POST['cart_button_position']); $this->setConfigValue("cart_button_position",$_POST['cart_button_position']);
@ -851,13 +851,13 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
$target_path = $this->getUploadDir(); $target_path = $this->getUploadDir();
if(!SyC::endsWith($target_path,'/')) $target_path .= '/'; //make sure that the path has a / in it's end if(!SyC::endsWith($target_path,'/')) $target_path .= '/'; //make sure that the path has a / in it's end
$target_path = $target_path . 'button-img.png'; $target_path = $target_path . 'button-img.png';
if(file_exists($target_path)) unlink($target_path); if(file_exists($target_path)) unlink($target_path);
list($width, $height, $type, $attr) = getimagesize($_FILES['button-img']['tmp_name']); list($width, $height, $type, $attr) = getimagesize($_FILES['button-img']['tmp_name']);
if (move_uploaded_file($_FILES['button-img']['tmp_name'], $target_path)) if (move_uploaded_file($_FILES['button-img']['tmp_name'], $target_path))
{ {
//set the button img //set the button img
@ -879,7 +879,7 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
$target_path = $target_path . 'btn-img-hover.png'; $target_path = $target_path . 'btn-img-hover.png';
if(file_exists($target_path)) unlink($target_path); if(file_exists($target_path)) unlink($target_path);
list($width, $height, $type, $attr) = getimagesize($_FILES['button-img-hover']['tmp_name']); list($width, $height, $type, $attr) = getimagesize($_FILES['button-img-hover']['tmp_name']);
if(move_uploaded_file($_FILES['button-img-hover']['tmp_name'], $target_path)) if(move_uploaded_file($_FILES['button-img-hover']['tmp_name'], $target_path))
@ -911,7 +911,7 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
'button_html' => $this->getConfigValue("button_html"), 'button_html' => $this->getConfigValue("button_html"),
'button_img' => $this->getUrl($this->getConfigValue("btn-img")), 'button_img' => $this->getUrl($this->getConfigValue("btn-img")),
'button_img_hover' => $this->getUrl($this->getConfigValue("btn-img-h")), 'button_img_hover' => $this->getUrl($this->getConfigValue("btn-img-h")),
'html' => $html, 'html' => $html,
'show_header' => $show_header, 'show_header' => $show_header,
'show_footer' => $show_footer, 'show_footer' => $show_footer,
@ -928,7 +928,7 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
public function getUploadDir(){ public function getUploadDir(){
return dirname(_FILE_). "/img/"; return dirname(_FILE_). "/img/";
} }
/** /**
* showDocumentation * showDocumentation
* @param null * @param null
@ -953,13 +953,13 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
//render the view //render the view
return $this->renderView('documentation',array( return $this->renderView('documentation',array(
'action_url' => $this->getButtonCallbackURL(), 'action_url' => $this->getButtonCallbackURL(),
'html' => $html, 'html' => $html,
'show_header' => $show_header, 'show_header' => $show_header,
'show_footer' => $show_footer, 'show_footer' => $show_footer,
)); ));
} }
/** /**
* show the update notification * show the update notification
* @param null * @param null
@ -967,7 +967,7 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
public function showUpdateNotification(){ public function showUpdateNotification(){
echo $this->getUpdateNotification(); echo $this->getUpdateNotification();
} }
/** /**
* get the update notification * get the update notification
* @param null * @param null
@ -1005,7 +1005,7 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
header("HTTP/1.0 403"); header("HTTP/1.0 403");
echo $e->getMessage(); echo $e->getMessage();
if($this->isDebugMode()){ if($this->isDebugMode()){
echo $e->getTraceAsString(); echo $e->getTraceAsString();
} }
@ -1065,21 +1065,21 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
$sql .= "PRIMARY KEY ($primaryKey));"; $sql .= "PRIMARY KEY ($primaryKey));";
$this->executeNonQuery($sql); $this->executeNonQuery($sql);
//we can't relly on the fact that the table has been properly created, so check it! //we can't relly on the fact that the table has been properly created, so check it!
if(!$this->existsTable($tableName)) if(!$this->existsTable($tableName))
throw new Exception(SyC::t('sdk','Cannot create table "{table_name}". Check your database permissions or manually run the following SQL command and try again:<br /><strong>{sql}</strong>', array('{table_name}' => $tableName,'{sql}' => nl2br($sql)))); throw new Exception(SyC::t('sdk','Cannot create table "{table_name}". Check your database permissions or manually run the following SQL command and try again:<br /><strong>{sql}</strong>', array('{table_name}' => $tableName,'{sql}' => nl2br($sql))));
} }
/** /**
* *
* existsTable * existsTable
* @return TRUE if the table exists, otherwise false * @return TRUE if the table exists, otherwise false
*/ */
protected function existsTable($tableName){ protected function existsTable($tableName){
$table_details = $this->getRow("show tables like '$tableName'"); $table_details = $this->getRow("show tables like '$tableName'");
//if there are table details, it means the table exists //if there are table details, it means the table exists
return !empty($table_details); return !empty($table_details);
} }
@ -1093,26 +1093,26 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
$sql = "DROP TABLE $tableName"; $sql = "DROP TABLE $tableName";
$this->executeNonQuery($sql); $this->executeNonQuery($sql);
//we can't relly on the fact that the table has been properly droped, so check it! //we can't relly on the fact that the table has been properly droped, so check it!
if($this->existsTable($tableName)) if($this->existsTable($tableName))
throw new Exception(SyC::t('sdk','Cannot drop table "{table_name}". Check your database permissions or manually run the following SQL command and try again:<br /><strong>{sql}</strong>', array('{table_name}' => $tableName, '{sql}' => nl2br($sql)))); throw new Exception(SyC::t('sdk','Cannot drop table "{table_name}". Check your database permissions or manually run the following SQL command and try again:<br /><strong>{sql}</strong>', array('{table_name}' => $tableName, '{sql}' => nl2br($sql))));
} }
/** /**
* *
* Render the specified views. we use special variable names here to avoid conflict when extracting data * Render the specified views. we use special variable names here to avoid conflict when extracting data
* *
*/ */
protected function renderView($_viewName_, $_data_=NULL, $_return_=true){ protected function renderView($_viewName_, $_data_=NULL, $_return_=true){
//get information about the Top Parent class //get information about the Top Parent class
$_reflection_ = new ReflectionClass(get_class($this)); $_reflection_ = new ReflectionClass(get_class($this));
$_viewFile_ = dirname($_reflection_->getFileName())."/views/$_viewName_.php"; $_viewFile_ = dirname($_reflection_->getFileName())."/views/$_viewName_.php";
//check if there is a file in the specified location //check if there is a file in the specified location
if(!file_exists($_viewFile_)){ if(!file_exists($_viewFile_)){
//the view has not been overrided, so use the SDK one //the view has not been overrided, so use the SDK one
$_viewFile_ = dirname(__FILE__) . "/views/$_viewName_.php"; $_viewFile_ = dirname(__FILE__) . "/views/$_viewName_.php";
} }
@ -1122,7 +1122,7 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
extract($_data_,EXTR_PREFIX_SAME,'data'); extract($_data_,EXTR_PREFIX_SAME,'data');
else else
$data=$_data_; $data=$_data_;
//render the view //render the view
if($_return_) if($_return_)
{ {
@ -1134,21 +1134,21 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
else else
require($_viewFile_); require($_viewFile_);
} }
/** /**
* *
* This function is used to make sure that the created url returns a proper scheme * This function is used to make sure that the created url returns a proper scheme
* *
*/ */
protected function getUrl($file){ protected function getUrl($file){
//if there is no file, return an empty string //if there is no file, return an empty string
if(empty($file)) return $file; if(empty($file)) return $file;
//test if the files is a url, as one migt send it that way //test if the files is a url, as one migt send it that way
$parts = parse_url($file); $parts = parse_url($file);
$is_url = is_array($parts) && isset($parts['scheme']); $is_url = is_array($parts) && isset($parts['scheme']);
//if this is not a url, create one for it //if this is not a url, create one for it
if(!$is_url) if(!$is_url)
{ {
@ -1160,19 +1160,19 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
{ {
$url = $file; $url = $file;
} }
//do it here. the problem is loading an insecure object over a secure page, so check for this situation //do it here. the problem is loading an insecure object over a secure page, so check for this situation
if( (isset($_SERVER['HTTPS']) && !strcasecmp($_SERVER['HTTPS'],'on')) && //the page is a secure one if( (isset($_SERVER['HTTPS']) && !strcasecmp($_SERVER['HTTPS'],'on')) && //the page is a secure one
SyC::startsWith($url,'http://') //the created url is an insecure one, adjust it SyC::startsWith($url,'http://') //the created url is an insecure one, adjust it
) )
{ {
$url = "https://".substr($url, 7); $url = "https://".substr($url, 7);
} }
return $url; return $url;
} }
/** /**
* *
@ -1181,39 +1181,39 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
* *
*/ */
public function checkSDKStatus($force = false) { public function checkSDKStatus($force = false) {
//call the API at most only once every 5 minutes, not sooner //call the API at most only once every 5 minutes, not sooner
if(!$force && (time()-$this->getConfigValue('api_last_check')) < 5*60) if(!$force && (time()-$this->getConfigValue('api_last_check')) < 5*60)
return; return;
//set the latest check time //set the latest check time
$this->setConfigValue('api_last_check',time()); $this->setConfigValue('api_last_check',time());
//get an update from the API //get an update from the API
$message = ''; $message = '';
if(is_array($result = $this->getSDKStatus($this->getSecretKey(), $this->getClientId(), $this->getAppKey(), $message))) if(is_array($result = $this->getSDKStatus($this->getSecretKey(), $this->getClientId(), $this->getAppKey(), $message)))
{ {
//save the data //save the data
$this->setConfigValue('api_version', @$result['api_version']); $this->setConfigValue('api_version', @$result['api_version']);
$this->setConfigValue('latest_version', @$result['plugin_latest_version']); $this->setConfigValue('latest_version', @$result['plugin_latest_version']);
$this->setConfigValue('download_url', @$result['plugin_download_url']); $this->setConfigValue('download_url', @$result['plugin_download_url']);
$this->setConfigValue('debug', @$result['debug']); $this->setConfigValue('debug', @$result['debug']);
//set the current language the SDK should be displayed in //set the current language the SDK should be displayed in
if(isset($result['lang'])){ if(isset($result['lang'])){
$this->setConfigValue('lang', $result['lang']); $this->setConfigValue('lang', $result['lang']);
SyC::setLanguage($result['lang']); SyC::setLanguage($result['lang']);
//check if there is a new translation available for this language //check if there is a new translation available for this language
if(!empty($result['lang_checksum']) && $result['lang_checksum'] != SyC::getLanguageChecksum()){ if(!empty($result['lang_checksum']) && $result['lang_checksum'] != SyC::getLanguageChecksum()){
//download the translation //download the translation
$messages = $this->getSDKTranslation(SyC::getLanguage()); $messages = $this->getSDKTranslation(SyC::getLanguage());
//save the translation //save the translation
$this->setConfigValue('messages', $messages); $this->setConfigValue('messages', $messages);
//reset the loaded messages so that the new ones are being used //reset the loaded messages so that the new ones are being used
SyC::reloadLanguage(); SyC::reloadLanguage();
} }
@ -1221,9 +1221,9 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
}else{ }else{
//simply log the error, for now! //simply log the error, for now!
error_log(print_r($message,true)); error_log(print_r($message,true));
} }
} }
/** /**
* *
* Language loader ( from the DB ) * Language loader ( from the DB )
@ -1233,18 +1233,18 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
{ {
//see if we have the language saved in the db //see if we have the language saved in the db
$messages = $this->getConfigValue('messages'); $messages = $this->getConfigValue('messages');
if(empty($messages)) //no language is saved, so revert to the file one if(empty($messages)) //no language is saved, so revert to the file one
{ {
$messages = SyC::loadFileLanguage($lang,$category); $messages = SyC::loadFileLanguage($lang,$category);
} }
//make sure we have an array for this variable //make sure we have an array for this variable
if(!is_array($messages)) $messages=array(); if(!is_array($messages)) $messages=array();
return $messages; return $messages;
} }
/* /*
* *
* Call to see if the function was called once, or not * Call to see if the function was called once, or not
@ -1258,7 +1258,7 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
self::$_SINGLE_FUNCTIONS_CALLS[$functionName] = true; self::$_SINGLE_FUNCTIONS_CALLS[$functionName] = true;
return true; return true;
} }
/** /**
* *
* User to catch any unhandled exceptions and print them nicelly * User to catch any unhandled exceptions and print them nicelly
@ -1267,7 +1267,7 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
public function UncaughtExceptionHandler(Exception $e) { public function UncaughtExceptionHandler(Exception $e) {
//@header("HTTP/1.0 403"); //@header("HTTP/1.0 403");
echo $e->getMessage(); echo $e->getMessage();
if($this->isDebugMode()){ if($this->isDebugMode()){
echo $e->getTraceAsString(); echo $e->getTraceAsString();
} }

View File

@ -5,10 +5,10 @@
$_reflection_ = new ReflectionClass(get_class($this)); $_reflection_ = new ReflectionClass(get_class($this));
$_file_ = dirname($_reflection_->getFileName())."/css/admin-style.css"; $_file_ = dirname($_reflection_->getFileName())."/css/admin-style.css";
//check if there is a file in the specified location //check if there is a file in the specified location
if(file_exists($_file_)):?> if(file_exists($_file_)):?>
<link rel="stylesheet" type="text/css" href="<?php echo $this->getUrl($_file_); ?>" /> <link rel="stylesheet" type="text/css" href="<?php echo $this->getUrl($_file_); ?>" />
<?php endif; ?> <?php endif; ?>
@ -29,10 +29,10 @@ if(file_exists($_file_)):?>
window.onload = function() { window.onload = function() {
document.getElementById('syc-form').addEventListener('submit', changetext, false); document.getElementById('syc-form').addEventListener('submit', changetext, false);
}; };
var changetext = function(){ var changetext = function(){
var textarea = document.getElementById('syc_button_textarea').value; var textarea = document.getElementById('syc_button_textarea').value;
document.getElementById('syc_button_textarea').value = encodeURIComponent(textarea); document.getElementById('syc_button_textarea').value = encodeURIComponent(textarea);
} }
</script> </script>

View File

@ -1,4 +1,4 @@
<?php if(!class_exists('ShareYourCartBase',false)) die('Access Denied'); <?php if(!class_exists('ShareYourCartBase',false)) die('Access Denied');
$admin_base_url = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); $admin_base_url = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
@ -8,7 +8,7 @@ if($refresh)
//recreate the url ( but before that make sure there is no syc-account parameter in it ) //recreate the url ( but before that make sure there is no syc-account parameter in it )
unset($_GET['syc-account']); unset($_GET['syc-account']);
$url = $admin_base_url.'?'.http_build_query($_GET,'','&'); $url = $admin_base_url.'?'.http_build_query($_GET,'','&');
@header("HTTP/1.1 302 Found"); @header("HTTP/1.1 302 Found");
@header("Location: $url"); @header("Location: $url");
echo "<meta http-equiv=\"refresh\" content=\"0; url=$url\">"; //it can happen that the headers have allready been sent, so use the html version as well echo "<meta http-equiv=\"refresh\" content=\"0; url=$url\">"; //it can happen that the headers have allready been sent, so use the html version as well
@ -20,15 +20,15 @@ if($refresh)
</script> </script>
<div class="wrap"> <div class="wrap">
<?php if($show_header):?> <?php if($show_header):?>
<?php echo $this->getUpdateNotification(); ?> <?php echo $this->getUpdateNotification(); ?>
<h2> <h2>
<a href="http://www.shareyourcart.com" target="_blank" title="Shareyourcart" class="shareyourcart-logo" onclick=" if(_gaq) _gaq.push(['_trackPageview', '/admin-view/logo-click']);"> <a href="http://www.shareyourcart.com" target="_blank" title="Shareyourcart" class="shareyourcart-logo" onclick=" if(_gaq) _gaq.push(['_trackPageview', '/admin-view/logo-click']);">
<img src="<?php echo $this->getUrl(dirname(__FILE__).'/../img/shareyourcart-logo.png'); ?>"/> <img src="<?php echo $this->getUrl(dirname(__FILE__).'/../img/shareyourcart-logo.png'); ?>"/>
</a> </a>
<div class="syc-slogan"><?php echo SyC::t('sdk','Increase your social media exposure by 10%!'); ?></div> <div class="syc-slogan"><?php echo SyC::t('sdk','Increase your social media exposure by 10%!'); ?></div>
<?php <?php
if(isset($this->adminFix)) echo "<br /><br /><br /><br /><br />"; if(isset($this->adminFix)) echo "<br /><br /><br /><br /><br />";
else echo "<br class=\"clr\" /> "; else echo "<br class=\"clr\" /> ";
@ -38,29 +38,29 @@ if($refresh)
<?php if(!empty($status_message) || !empty($error_message)): ?> <?php if(!empty($status_message) || !empty($error_message)): ?>
<div class="updated settings-error"><p><strong> <div class="updated settings-error"><p><strong>
<?php <?php
$message = @$error_message; $message = @$error_message;
//is there a status message? //is there a status message?
if(!empty($status_message)) if(!empty($status_message))
{ {
//put the status message on a new line //put the status message on a new line
if(!empty($message)) $message .= "<br /><br />"; if(!empty($message)) $message .= "<br /><br />";
$message .= $status_message; $message .= $status_message;
} }
echo $message; echo $message;
?> ?>
</strong></p></div> </strong></p></div>
<?php endif; ?> <?php endif; ?>
<p><?php echo SyC::t('sdk','{brand} helps you get more customers by motivating satisfied customers to talk with their friends about your products. Each customer that promotes your products, via social media, will receive a coupon that they can apply to their shopping cart in order to get a small discount.',array('{brand}' => '<a href="http://www.shareyourcart.com" target="_blank" title="Shareyourcart&trade;" onclick=" if(_gaq) _gaq.push([\'_trackPageview\', \'/admin-view/logo-click\']);">ShareYourCart&trade;</a>')); ?></p> <p><?php echo SyC::t('sdk','{brand} helps you get more customers by motivating satisfied customers to talk with their friends about your products. Each customer that promotes your products, via social media, will receive a coupon that they can apply to their shopping cart in order to get a small discount.',array('{brand}' => '<a href="http://www.shareyourcart.com" target="_blank" title="Shareyourcart&trade;" onclick=" if(_gaq) _gaq.push([\'_trackPageview\', \'/admin-view/logo-click\']);">ShareYourCart&trade;</a>')); ?></p>
<br /> <br />
<div id="acount-options"> <div id="acount-options">
<form method="POST" name="account-form"> <form method="POST" name="account-form">
<fieldset> <fieldset>
<div class="api-status" align="right"> <div class="api-status" align="right">
<?php echo SyC::t('sdk','API Status:'); ?> <?php echo SyC::t('sdk','API Status:'); ?>
<?php if($this->isActive()) : ?> <?php if($this->isActive()) : ?>
@ -74,7 +74,7 @@ if($refresh)
<?php else :?> <?php else :?>
<input type="submit" value="<?php echo SyC::t('sdk','Enable'); ?>" name="enable-API" class="api-button" onclick=" if(_gaq) _gaq.push(['_trackPageview', '/admin-view/enable-click']);" /> <input type="submit" value="<?php echo SyC::t('sdk','Enable'); ?>" name="enable-API" class="api-button" onclick=" if(_gaq) _gaq.push(['_trackPageview', '/admin-view/enable-click']);" />
<?php endif;?> <?php endif;?>
</div> </div>
<table class="form-table-api" name="shareyourcart_settings"> <table class="form-table-api" name="shareyourcart_settings">
<tr> <tr>
<th scope="row"><?php echo SyC::t('sdk','Client ID'); ?></th> <th scope="row"><?php echo SyC::t('sdk','Client ID'); ?></th>
@ -90,34 +90,34 @@ if($refresh)
</tr> </tr>
</table> </table>
<?php echo $html;?> <?php echo $html;?>
<div class="submit"><input type="submit" name="syc-account-form" class="button" value="<?php echo SyC::t('sdk','Save'); ?>" onclick=" if(_gaq) _gaq.push(['_trackPageview', '/admin-view/save-click']);"></div> <div class="submit"><input type="submit" name="syc-account-form" class="button" value="<?php echo SyC::t('sdk','Save'); ?>" onclick=" if(_gaq) _gaq.push(['_trackPageview', '/admin-view/save-click']);"></div>
</fieldset> </fieldset>
</form> </form>
</div> </div>
<?php if($this->isActive()): //show the configure part only if it is active ?> <?php if($this->isActive()): //show the configure part only if it is active ?>
<br/> <br/>
<fieldset> <fieldset>
<p><?php echo SyC::t('sdk','You can choose how much of a discount to give (in fixed amount, percentage, or free shipping) and to which social media channels it should it be applied. You can also define what the advertisement should say, so that it fully benefits your sales.'); ?></p> <p><?php echo SyC::t('sdk','You can choose how much of a discount to give (in fixed amount, percentage, or free shipping) and to which social media channels it should it be applied. You can also define what the advertisement should say, so that it fully benefits your sales.'); ?></p>
<br /> <br />
<form action="<?php echo $this->SHAREYOURCART_CONFIGURE; ?>" method="POST" id="configure-form" target="_blank"> <form action="<?php echo $this->SHAREYOURCART_CONFIGURE; ?>" method="POST" id="configure-form" target="_blank">
<div class="configure-button-container" align="center"> <div class="configure-button-container" align="center">
<input type="submit" value="<?php echo SyC::t('sdk','Configure'); ?>" id="configure-button" class="shareyourcart-button-orange" onclick=" if(_gaq) _gaq.push(['_trackPageview', '/admin-view/configure-click']);" /> <input type="submit" value="<?php echo SyC::t('sdk','Configure'); ?>" id="configure-button" class="shareyourcart-button-orange" onclick=" if(_gaq) _gaq.push(['_trackPageview', '/admin-view/configure-click']);" />
<input type="hidden" name="app_key" value="<?php echo $this->getAppKey(); ?>" /> <input type="hidden" name="app_key" value="<?php echo $this->getAppKey(); ?>" />
<input type="hidden" name="client_id" value="<?php echo $this->getClientId(); ?>" /> <input type="hidden" name="client_id" value="<?php echo $this->getClientId(); ?>" />
<input type="hidden" name="email" value="<?php echo $this->getAdminEmail(); ?>" /> <input type="hidden" name="email" value="<?php echo $this->getAdminEmail(); ?>" />
</div> </div>
</form> </form>
</fieldset> </fieldset>
<?php if($show_footer):?> <?php if($show_footer):?>
<br /> <br />
<h2><?php echo SyC::t('sdk','Contact'); ?></h2> <h2><?php echo SyC::t('sdk','Contact'); ?></h2>
<p><?php echo SyC::t('sdk',"If you've got 30 seconds, we'd {link-1} love to know what ideal outcome you'd like ShareYourCart to help bring to your business</a>, or if you have a private question, you can {link-2} contact us directly</a>", array('{link-1}' => '<a href="http://shareyourcart.uservoice.com" target="_blank" title="forum" class="api-link" onclick=" if(_gaq) _gaq.push([\'_trackPageview\', \'/admin/documentation/forum-click\']);">', '{link-2}' => '<a href="http://www.shareyourcart.com/contact" target="_blank" class="api-link" onclick=" if(_gaq) _gaq.push([\'_trackPageview\', \'/admin/documentation/contact-click\']);">')); ?></p> <p><?php echo SyC::t('sdk',"If you've got 30 seconds, we'd {link-1} love to know what ideal outcome you'd like ShareYourCart to help bring to your business</a>, or if you have a private question, you can {link-2} contact us directly</a>", array('{link-1}' => '<a href="http://shareyourcart.uservoice.com" target="_blank" title="forum" class="api-link" onclick=" if(_gaq) _gaq.push([\'_trackPageview\', \'/admin/documentation/forum-click\']);">', '{link-2}' => '<a href="http://www.shareyourcart.com/contact" target="_blank" class="api-link" onclick=" if(_gaq) _gaq.push([\'_trackPageview\', \'/admin/documentation/contact-click\']);">')); ?></p>
<br /> <br />
<?php endif; ?> <?php endif; ?>
<?php endif; //show only if the cart is active ?> <?php endif; //show only if the cart is active ?>
</div> </div>

View File

@ -1,6 +1,6 @@
<?php <?php
if(!class_exists('ShareYourCartBase',false)) die('Access Denied'); if(!class_exists('ShareYourCartBase',false)) die('Access Denied');
// If only the hover is uploaded // If only the hover is uploaded
if((!$button_img or !$button_img_width or !$button_img_height) and ($button_img_hover and $button_img_hover_width and $button_img_hover_height)) { if((!$button_img or !$button_img_width or !$button_img_height) and ($button_img_hover and $button_img_hover_width and $button_img_hover_height)) {
$button_img = $button_img_hover; $button_img = $button_img_hover;
@ -10,9 +10,9 @@
$button_img_hover_width = null; $button_img_hover_width = null;
$button_img_hover_height = null; $button_img_hover_height = null;
} }
$callbackDataAttr = ''; $callbackDataAttr = '';
if(isset($callback_url) && !empty($callback_url)) { if(isset($callback_url) && !empty($callback_url)) {
$callbackDataAttr = 'data-syc-callback_url="' . $callback_url .'"'; $callbackDataAttr = 'data-syc-callback_url="' . $callback_url .'"';
} }
@ -30,7 +30,7 @@
height: <?php echo $button_img_height; ?>px; height: <?php echo $button_img_height; ?>px;
text-indent: -9999px; text-indent: -9999px;
} }
<?php <?php
if($button_img_hover and $button_img_hover_width and $button_img_hover_height) { if($button_img_hover and $button_img_hover_width and $button_img_hover_height) {
?> ?>

View File

@ -5,15 +5,15 @@
</script> </script>
<div class="wrap"> <div class="wrap">
<?php if($show_header):?> <?php if($show_header):?>
<?php echo $this->getUpdateNotification(); ?> <?php echo $this->getUpdateNotification(); ?>
<h2> <h2>
<a href="http://www.shareyourcart.com" target="_blank" title="Shareyourcart" class="shareyourcart-logo" onclick=" if(_gaq) _gaq.push(['_trackPageview', '/admin/button-settings-view/logo-click']);"> <a href="http://www.shareyourcart.com" target="_blank" title="Shareyourcart" class="shareyourcart-logo" onclick=" if(_gaq) _gaq.push(['_trackPageview', '/admin/button-settings-view/logo-click']);">
<img src="<?php echo $this->getUrl(dirname(__FILE__).'/../img/shareyourcart-logo.png'); ?>"/> <img src="<?php echo $this->getUrl(dirname(__FILE__).'/../img/shareyourcart-logo.png'); ?>"/>
</a> </a>
<div class="syc-slogan"><?php echo SyC::t('sdk','Increase your social media exposure by 10%!'); ?></div> <div class="syc-slogan"><?php echo SyC::t('sdk','Increase your social media exposure by 10%!'); ?></div>
<br clear="all" /> <br clear="all" />
</h2> </h2>
<?php endif; ?> <?php endif; ?>
@ -23,14 +23,14 @@
</strong></p></div> </strong></p></div>
<?php endif; ?> <?php endif; ?>
<div id="visual-options"> <div id="visual-options">
<form method="POST" enctype="multipart/form-data" id="syc-form"> <form method="POST" enctype="multipart/form-data" id="syc-form">
<fieldset> <fieldset>
<div class="buttonOption"> <div class="buttonOption">
<input class="buttonOptionRadio" type="radio" value="1" id="button_type_1" <?php if ($current_button_type == '1'||$current_button_type == '') echo 'checked' ?> name="button_type" onclick=" if(_gaq) _gaq.push(['_trackPageview', '/admin/button-settings-view/default-click']);" /> <input class="buttonOptionRadio" type="radio" value="1" id="button_type_1" <?php if ($current_button_type == '1'||$current_button_type == '') echo 'checked' ?> name="button_type" onclick=" if(_gaq) _gaq.push(['_trackPageview', '/admin/button-settings-view/default-click']);" />
<label class="buttonOptionLabel" for="button_type_1"><?php echo SyC::t('sdk','Use Standard Button'); ?></label> <label class="buttonOptionLabel" for="button_type_1"><?php echo SyC::t('sdk','Use Standard Button'); ?></label>
<br /><br /> <br /><br />
<table class="form-table shareyourcart_button_standard" name="shareyourcart_button_standard"> <table class="form-table shareyourcart_button_standard" name="shareyourcart_button_standard">
<tr align="center"> <tr align="center">
@ -43,7 +43,7 @@
<option name="blue" <?php echo $current_skin == 'blue' ? 'selected="selected"' : ''; ?> value="blue"><?php echo SyC::t('sdk','Blue'); ?></option> <option name="blue" <?php echo $current_skin == 'blue' ? 'selected="selected"' : ''; ?> value="blue"><?php echo SyC::t('sdk','Blue'); ?></option>
<option name="light" <?php echo $current_skin == 'light' ? 'selected="selected"' : ''; ?> value="light"><?php echo SyC::t('sdk','Light'); ?></option> <option name="light" <?php echo $current_skin == 'light' ? 'selected="selected"' : ''; ?> value="light"><?php echo SyC::t('sdk','Light'); ?></option>
<option name="dark" <?php echo $current_skin == 'dark' ? 'selected="selected"' : ''; ?> value="dark"><?php echo SyC::t('sdk','Dark'); ?></option> <option name="dark" <?php echo $current_skin == 'dark' ? 'selected="selected"' : ''; ?> value="dark"><?php echo SyC::t('sdk','Dark'); ?></option>
</select> </select>
</td> </td>
</tr> </tr>
<tr align="center"> <tr align="center">
@ -54,14 +54,14 @@
<select name="button_position" id="button_position" onclick=" if(_gaq) _gaq.push(['_trackPageview', '/admin/button-settings-view/button-position-click']);"> <select name="button_position" id="button_position" onclick=" if(_gaq) _gaq.push(['_trackPageview', '/admin/button-settings-view/button-position-click']);">
<option name="normal" <?php echo $current_position == 'normal' ? 'selected="selected"' : ''; ?> value="normal"><?php echo SyC::t('sdk','Normal'); ?></option> <option name="normal" <?php echo $current_position == 'normal' ? 'selected="selected"' : ''; ?> value="normal"><?php echo SyC::t('sdk','Normal'); ?></option>
<option name="floating" <?php echo $current_position == 'floating' ? 'selected="selected"' : ''; ?> value="floating"><?php echo SyC::t('sdk','Floating'); ?></option> <option name="floating" <?php echo $current_position == 'floating' ? 'selected="selected"' : ''; ?> value="floating"><?php echo SyC::t('sdk','Floating'); ?></option>
</select> </select>
</td> </td>
</tr> </tr>
<!-- <tr align="center"> since we switched to <a> on the button, this does not seem to be needed anymore <!-- <tr align="center"> since we switched to <a> on the button, this does not seem to be needed anymore
<td> <td>
<input class="buttonCheckbox" name="show_on_single_row" <?php echo $show_on_single_row ? 'checked="checked"' : ''; ?> type='checkbox' onclick=" if(_gaq) _gaq.push(['_trackPageview', '/admin/button-settings-view/toggle-show-on-single-row-click']);"><?php echo SyC::t('sdk','Check this if you want the button to be shown on it\'s own row'); ?></input> <input class="buttonCheckbox" name="show_on_single_row" <?php echo $show_on_single_row ? 'checked="checked"' : ''; ?> type='checkbox' onclick=" if(_gaq) _gaq.push(['_trackPageview', '/admin/button-settings-view/toggle-show-on-single-row-click']);"><?php echo SyC::t('sdk','Check this if you want the button to be shown on it\'s own row'); ?></input>
</td> </td>
</tr> --> </tr> -->
</table> </table>
</div> </div>
@ -82,7 +82,7 @@
<input type="hidden" name="MAX_FILE_SIZE" value="100000000000" /> <input type="hidden" name="MAX_FILE_SIZE" value="100000000000" />
<input type="file" accept="image/gif, image/jpeg, image/jpg, image/png" name="button-img" id="button-img" onclick=" if(_gaq) _gaq.push(['_trackPageview', '/admin/button-settings-view/upload-normal-img-click']);" /> <input type="file" accept="image/gif, image/jpeg, image/jpg, image/png" name="button-img" id="button-img" onclick=" if(_gaq) _gaq.push(['_trackPageview', '/admin/button-settings-view/upload-normal-img-click']);" />
</td> </td>
</tr> </tr>
<tr align="center"> <tr align="center">
<th><label><?php echo SyC::t('sdk','Hover image:'); ?></label></th> <th><label><?php echo SyC::t('sdk','Hover image:'); ?></label></th>
@ -96,27 +96,27 @@
<input type="hidden" name="MAX_FILE_SIZE" value="100000000000" /> <input type="hidden" name="MAX_FILE_SIZE" value="100000000000" />
<input type="file" accept="image/gif, image/jpeg, image/jpg, image/png" name="button-img-hover" id="button-img-hover" onclick=" if(_gaq) _gaq.push(['_trackPageview', '/admin/button-settings-view/upload-hover-img-click']);" /> <input type="file" accept="image/gif, image/jpeg, image/jpg, image/png" name="button-img-hover" id="button-img-hover" onclick=" if(_gaq) _gaq.push(['_trackPageview', '/admin/button-settings-view/upload-hover-img-click']);" />
</td> </td>
</tr> </tr>
</table> </table>
</div> </div>
<div class="buttonOption last"> <div class="buttonOption last">
<input class="buttonOptionRadio" type="radio" value="3" id="button_type_3" name="button_type" <?php if ($current_button_type == '3') echo 'checked' ?> onclick=" if(_gaq) _gaq.push(['_trackPageview', '/admin/button-settings-view/custom-button-click']);"/> <input class="buttonOptionRadio" type="radio" value="3" id="button_type_3" name="button_type" <?php if ($current_button_type == '3') echo 'checked' ?> onclick=" if(_gaq) _gaq.push(['_trackPageview', '/admin/button-settings-view/custom-button-click']);"/>
<label class="buttonOptionLabel" for="button_type_3"><?php echo SyC::t('sdk','Build your own HTML button'); ?></label> <label class="buttonOptionLabel" for="button_type_3"><?php echo SyC::t('sdk','Build your own HTML button'); ?></label>
<table class="form-table shareyourcart_button_html" name="shareyourcart_button_html"> <table class="form-table shareyourcart_button_html" name="shareyourcart_button_html">
<tr> <tr>
<td> <td>
<textarea id="syc_button_textarea" class="buttonTextarea" rows="7" cols="56" name="button_html"><?php echo ($button_html!=''?$button_html:'<button>'.SyC::t('sdk','Get a {value} discount',array('{value}' => '<div class="shareyourcart-discount"></div>')).'</button>'); ?></textarea> <textarea id="syc_button_textarea" class="buttonTextarea" rows="7" cols="56" name="button_html"><?php echo ($button_html!=''?$button_html:'<button>'.SyC::t('sdk','Get a {value} discount',array('{value}' => '<div class="shareyourcart-discount"></div>')).'</button>'); ?></textarea>
</td> </td>
</tr> </tr>
</table> </table>
<?php echo $html; ?> <?php echo $html; ?>
</div> </div>
<br clear="all" /> <br clear="all" />
<hr /> <hr />
<br /> <br />
<table class="form-table table-small" name="shareyourcart_settings"> <table class="form-table table-small" name="shareyourcart_settings">
@ -125,7 +125,7 @@
<td> <td>
<input class="buttonCheckbox" name="show_on_product" <?php echo $show_on_product ? 'checked="checked"' : ''; ?> type='checkbox' onclick=" if(_gaq) _gaq.push(['_trackPageview', '/admin/button-settings-view/toggle-show-on-product-click']);"><?php echo SyC::t('sdk','Product page'); ?></input> <input class="buttonCheckbox" name="show_on_product" <?php echo $show_on_product ? 'checked="checked"' : ''; ?> type='checkbox' onclick=" if(_gaq) _gaq.push(['_trackPageview', '/admin/button-settings-view/toggle-show-on-product-click']);"><?php echo SyC::t('sdk','Product page'); ?></input>
<br /> <br />
<input class="buttonCheckbox" name="show_on_checkout" <?php echo $show_on_checkout ? 'checked="checked"' : ''; ?> type='checkbox' onclick=" if(_gaq) _gaq.push(['_trackPageview', '/admin/button-settings-view/toggle-show-on-checkout-click']);"><?php echo SyC::t('sdk','Checkout page'); ?></input> <input class="buttonCheckbox" name="show_on_checkout" <?php echo $show_on_checkout ? 'checked="checked"' : ''; ?> type='checkbox' onclick=" if(_gaq) _gaq.push(['_trackPageview', '/admin/button-settings-view/toggle-show-on-checkout-click']);"><?php echo SyC::t('sdk','Checkout page'); ?></input>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -141,13 +141,13 @@
</td> </td>
</tr> </tr>
</table> </table>
<div class="submit"><input type="submit" class="button" name="syc-visual-form" id="syc-visual-form" value="<?php echo SyC::t('sdk','Save'); ?>" onclick=" if(_gaq) _gaq.push(['_trackPageview', '/admin/button-settings-view/save-click']);"></div> <div class="submit"><input type="submit" class="button" name="syc-visual-form" id="syc-visual-form" value="<?php echo SyC::t('sdk','Save'); ?>" onclick=" if(_gaq) _gaq.push(['_trackPageview', '/admin/button-settings-view/save-click']);"></div>
</fieldset> </fieldset>
<br /> <br />
</form> </form>
</div> </div>
<?php if($show_footer):?> <?php if($show_footer):?>

View File

@ -5,28 +5,28 @@
</script> </script>
<div class="wrap"> <div class="wrap">
<?php if($show_header):?> <?php if($show_header):?>
<?php echo $this->getUpdateNotification(); ?> <?php echo $this->getUpdateNotification(); ?>
<h2> <h2>
<a href="http://www.shareyourcart.com" target="_blank" title="Shareyourcart" class="shareyourcart-logo" onclick=" if(_gaq) _gaq.push(['_trackPageview', '/admin/documentation/logo-click']);"> <a href="http://www.shareyourcart.com" target="_blank" title="Shareyourcart" class="shareyourcart-logo" onclick=" if(_gaq) _gaq.push(['_trackPageview', '/admin/documentation/logo-click']);">
<img src="<?php echo $this->getUrl(dirname(__FILE__).'/../img/shareyourcart-logo.png'); ?>"/> <img src="<?php echo $this->getUrl(dirname(__FILE__).'/../img/shareyourcart-logo.png'); ?>"/>
</a> </a>
<div class="syc-slogan"><?php echo SyC::t('sdk','Increase your social media exposure by 10%!'); ?></div> <div class="syc-slogan"><?php echo SyC::t('sdk','Increase your social media exposure by 10%!'); ?></div>
<br clear="all" /> <br clear="all" />
</h2> </h2>
<?php endif; ?> <?php endif; ?>
<div id="doc-content"> <div id="doc-content">
<h2><?php echo SyC::t('sdk','Standard Button'); ?></h2> <h2><?php echo SyC::t('sdk','Standard Button'); ?></h2>
<p><?php echo SyC::t('sdk','In order to see the {brand} button on a <strong>post</strong> or <strong>page</strong> you can use the following shortcode:', array( '{brand}' => '<a href="http://www.shareyourcart.com" target="_blank" title="Shareyourcart&trade;" onclick=" if(_gaq) _gaq.push([\'_trackPageview\', \'/admin/documentation/logo-click\']);">ShareYourCart&trade;</a>')); ?></p> <p><?php echo SyC::t('sdk','In order to see the {brand} button on a <strong>post</strong> or <strong>page</strong> you can use the following shortcode:', array( '{brand}' => '<a href="http://www.shareyourcart.com" target="_blank" title="Shareyourcart&trade;" onclick=" if(_gaq) _gaq.push([\'_trackPageview\', \'/admin/documentation/logo-click\']);">ShareYourCart&trade;</a>')); ?></p>
<pre><code>[shareyourcart]</code></pre> <pre><code>[shareyourcart]</code></pre>
<p><?php echo SyC::t('sdk','If you want to use the {brand} button directly in a <strong>theme</strong> or <strong>page template</strong> you have to use the following function call:', array('{brand}' => '<a href="http://www.shareyourcart.com" target="_blank" title="Shareyourcart&trade;" onclick=" if(_gaq) _gaq.push([\'_trackPageview\', \'/admin/documentation/logo-click\']);">ShareYourCart&trade;</a>')); ?></p> <p><?php echo SyC::t('sdk','If you want to use the {brand} button directly in a <strong>theme</strong> or <strong>page template</strong> you have to use the following function call:', array('{brand}' => '<a href="http://www.shareyourcart.com" target="_blank" title="Shareyourcart&trade;" onclick=" if(_gaq) _gaq.push([\'_trackPageview\', \'/admin/documentation/logo-click\']);">ShareYourCart&trade;</a>')); ?></p>
<pre><code>echo do_shortcode('[shareyourcart]');</code></pre> <pre><code>echo do_shortcode('[shareyourcart]');</code></pre>
<h3><?php echo SyC::t('sdk','Remarks'); ?></h3> <h3><?php echo SyC::t('sdk','Remarks'); ?></h3>
<ol> <ol>
<?php if (!(isset($action_url) && !empty($action_url))): //if no shopping cart is active ?> <?php if (!(isset($action_url) && !empty($action_url))): //if no shopping cart is active ?>
<li><p><?php echo SyC::t('sdk','For the button to work, you need to specify the following properties in the meta description area'); ?></p> <li><p><?php echo SyC::t('sdk','For the button to work, you need to specify the following properties in the meta description area'); ?></p>
<pre><code><?php echo SyC::htmlIndent(nl2br(htmlspecialchars('<html xmlns="http://www.w3.org/1999/xhtml" <pre><code><?php echo SyC::htmlIndent(nl2br(htmlspecialchars('<html xmlns="http://www.w3.org/1999/xhtml"
@ -37,8 +37,8 @@
<meta property="syc:price" content="$10" /> <meta property="syc:price" content="$10" />
<meta property="og:description" <meta property="og:description"
content=" content="
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Proin feugiat nunc quis nibh congue luctus. Proin feugiat nunc quis nibh congue luctus.
Maecenas ac est nec turpis fermentum imperdiet. Maecenas ac est nec turpis fermentum imperdiet.
"/> "/>
... ...
@ -55,23 +55,23 @@
</ul> </ul>
</li> </li>
</ol> </ol>
<h2><?php echo SyC::t('sdk','Custom Button'); ?></h2> <h2><?php echo SyC::t('sdk','Custom Button'); ?></h2>
<p><?php echo SyC::t('sdk','If you want to fully style the {brand} button, use instead the following HTML code', array('{brand}' => '<a href="http://www.shareyourcart.com" target="_blank" title="Shareyourcart&trade;" onclick=" if(_gaq) _gaq.push([\'_trackPageview\', \'/admin/documentation/logo-click\']);">ShareYourCart&trade;</a>')); ?></p> <p><?php echo SyC::t('sdk','If you want to fully style the {brand} button, use instead the following HTML code', array('{brand}' => '<a href="http://www.shareyourcart.com" target="_blank" title="Shareyourcart&trade;" onclick=" if(_gaq) _gaq.push([\'_trackPageview\', \'/admin/documentation/logo-click\']);">ShareYourCart&trade;</a>')); ?></p>
<?php $custom_button = '<button class="shareyourcart-button" data-syc-layout="custom"'; <?php $custom_button = '<button class="shareyourcart-button" data-syc-layout="custom"';
if (isset($action_url) && !empty($action_url)){ if (isset($action_url) && !empty($action_url)){
//if there is no action url, it means none of the supported shopping carts are active, //if there is no action url, it means none of the supported shopping carts are active,
//so there would be no need for the callback attribute //so there would be no need for the callback attribute
$custom_button .= ' data-syc-callback_url="'.$action_url.'" '; $custom_button .= ' data-syc-callback_url="'.$action_url.'" ';
} }
$custom_button .= '> $custom_button .= '>
Get a <div class="shareyourcart-discount" ></div> discount Get a <div class="shareyourcart-discount" ></div> discount
</button>'; ?> </button>'; ?>
<pre><code><?php echo SyC::htmlIndent(nl2br(htmlspecialchars($custom_button))); ?></code></pre> <pre><code><?php echo SyC::htmlIndent(nl2br(htmlspecialchars($custom_button))); ?></code></pre>
<?php if (isset($action_url) && !empty($action_url)): //only show if a known shopping cart is active ?> <?php if (isset($action_url) && !empty($action_url)): //only show if a known shopping cart is active ?>
<h3><?php echo SyC::t('sdk','Remarks'); ?></h3> <h3><?php echo SyC::t('sdk','Remarks'); ?></h3>
<p><?php echo SyC::t('sdk','If you want to use the {brand} button on a product\'s page, you need to <strong>append</strong> {product-property} to the {callback-url} value, where {product-property} is the product\'s id', array('{brand}' => '<a href="http://www.shareyourcart.com" target="_blank" title="Shareyourcart&trade;" onclick=" if(_gaq) _gaq.push([\'_trackPageview\', \'/admin/documentation/logo-click\']);">ShareYourCart&trade;</a>', '{product-property}' => '<code>&p=&lt;product_id&gt;</code>', '{callback-url}' => '<strong>data-syc-callback_url</strong>')); ?></p> <p><?php echo SyC::t('sdk','If you want to use the {brand} button on a product\'s page, you need to <strong>append</strong> {product-property} to the {callback-url} value, where {product-property} is the product\'s id', array('{brand}' => '<a href="http://www.shareyourcart.com" target="_blank" title="Shareyourcart&trade;" onclick=" if(_gaq) _gaq.push([\'_trackPageview\', \'/admin/documentation/logo-click\']);">ShareYourCart&trade;</a>', '{product-property}' => '<code>&p=&lt;product_id&gt;</code>', '{callback-url}' => '<strong>data-syc-callback_url</strong>')); ?></p>

View File

@ -4,14 +4,14 @@
<link rel="stylesheet" href="<?php echo $this->getUrl(dirname(__FILE__).'/../css/ie.css'); ?>" type="text/css"/> <link rel="stylesheet" href="<?php echo $this->getUrl(dirname(__FILE__).'/../css/ie.css'); ?>" type="text/css"/>
<![endif]--> <![endif]-->
<?php //check if there is a style outside of the SDK, and include that one as well <?php //check if there is a style outside of the SDK, and include that one as well
$_reflection_ = new ReflectionClass(get_class($this)); $_reflection_ = new ReflectionClass(get_class($this));
$_file_ = dirname($_reflection_->getFileName())."/css/style.css"; $_file_ = dirname($_reflection_->getFileName())."/css/style.css";
//check if there is a file in the specified location //check if there is a file in the specified location
if(file_exists($_file_)):?> if(file_exists($_file_)):?>
<link rel="stylesheet" type="text/css" href="<?php echo $this->getUrl($_file_); ?>" /> <link rel="stylesheet" type="text/css" href="<?php echo $this->getUrl($_file_); ?>" />
<?php endif; ?> <?php endif; ?>

View File

@ -4,10 +4,10 @@
window.onload = function() { window.onload = function() {
document.getElementById('syc-form').addEventListener('submit', changetext, false); document.getElementById('syc-form').addEventListener('submit', changetext, false);
}; };
var changetext = function(){ var changetext = function(){
var textarea = document.getElementById('syc_button_textarea').value; var textarea = document.getElementById('syc_button_textarea').value;
document.getElementById('syc_button_textarea').value = encodeURIComponent(textarea); document.getElementById('syc_button_textarea').value = encodeURIComponent(textarea);
} }
</script> </script>

View File

@ -7,13 +7,13 @@ $wcIntegration = $html; //the object is sent under the $html parameter
//since this is a post, and is related to recovering or creating a new account, perform some special operations //since this is a post, and is related to recovering or creating a new account, perform some special operations
if ($refresh || ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty( $_REQUEST['syc-account'] ))){ if ($refresh || ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty( $_REQUEST['syc-account'] ))){
$redirect = remove_query_arg( 'saved' ); $redirect = remove_query_arg( 'saved' );
$redirect = remove_query_arg( 'wc_error', $redirect ); $redirect = remove_query_arg( 'wc_error', $redirect );
$redirect = remove_query_arg( 'wc_message', $redirect ); $redirect = remove_query_arg( 'wc_message', $redirect );
//remove the syc-account argument only if the SDK commanded as such //remove the syc-account argument only if the SDK commanded as such
if($refresh) $redirect = remove_query_arg( 'syc-account', $redirect ); if($refresh) $redirect = remove_query_arg( 'syc-account', $redirect );
if ( !empty($error_message) ) $redirect = add_query_arg( 'wc_error', urlencode( esc_attr( $error_message ) ), $redirect ); if ( !empty($error_message) ) $redirect = add_query_arg( 'wc_error', urlencode( esc_attr( $error_message ) ), $redirect );
wp_safe_redirect( $redirect ); wp_safe_redirect( $redirect );
@ -26,62 +26,62 @@ if ($refresh || ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty( $_REQUEST['syc-
<?php if ( $show_header ) : ?> <?php if ( $show_header ) : ?>
<?php echo $this->getUpdateNotification(); ?> <?php echo $this->getUpdateNotification(); ?>
<?php if ( ! $this->getClientId() && ! $this->getAppKey() ) : //show the get started message ?> <?php if ( ! $this->getClientId() && ! $this->getAppKey() ) : //show the get started message ?>
<div id="wc_get_started"> <div id="wc_get_started">
<span class="main"><?php _e('Setup your ShareYourCart account', 'woocommerce'); ?></span> <span class="main"><?php _e('Setup your ShareYourCart account', 'woocommerce'); ?></span>
<span><?php echo $wcIntegration->method_description; ?></span> <span><?php echo $wcIntegration->method_description; ?></span>
<p><a href="<?php echo add_query_arg( 'syc-account', 'create', admin_url( 'admin.php?page=woocommerce&tab=integration&section=shareyourcart' ) ); ?>" class="button button-primary"><?php _e('Create an account', 'woocommerce'); ?></a> <a href="<?php echo add_query_arg( 'syc-account', 'recover', admin_url( 'admin.php?page=woocommerce&tab=integration&section=shareyourcart' ) ); ?>" class="button"><?php _e('Can\'t access your account?', 'woocommerce'); ?></a></p> <p><a href="<?php echo add_query_arg( 'syc-account', 'create', admin_url( 'admin.php?page=woocommerce&tab=integration&section=shareyourcart' ) ); ?>" class="button button-primary"><?php _e('Create an account', 'woocommerce'); ?></a> <a href="<?php echo add_query_arg( 'syc-account', 'recover', admin_url( 'admin.php?page=woocommerce&tab=integration&section=shareyourcart' ) ); ?>" class="button"><?php _e('Can\'t access your account?', 'woocommerce'); ?></a></p>
</div> </div>
<?php else: ?> <?php else: ?>
<h3> <h3>
<a href="http://www.shareyourcart.com" target="_blank" title="Shareyourcart" class="shareyourcart-logo"> <a href="http://www.shareyourcart.com" target="_blank" title="Shareyourcart" class="shareyourcart-logo">
<img src="<?php echo $this->createUrl(dirname(__FILE__).'/../sdk/img/shareyourcart-logo.png'); ?>"/> <img src="<?php echo $this->createUrl(dirname(__FILE__).'/../sdk/img/shareyourcart-logo.png'); ?>"/>
</a> </a>
</h3> </h3>
<?php echo wpautop( $wcIntegration->method_description );?> <?php echo wpautop( $wcIntegration->method_description );?>
<?php endif; ?> <?php endif; ?>
<?php endif; ?> <?php endif; ?>
<?php if(!empty($status_message) || !empty($error_message)): ?> <?php if(!empty($status_message) || !empty($error_message)): ?>
<div class="updated settings-error"><p><strong> <div class="updated settings-error"><p><strong>
<?php <?php
$message = @$error_message; $message = @$error_message;
//is there a status message? //is there a status message?
if(!empty($status_message)) if(!empty($status_message))
{ {
//put the status message on a new line //put the status message on a new line
if(!empty($message)) $message .= "<br /><br />"; if(!empty($message)) $message .= "<br /><br />";
$message .= $status_message; $message .= $status_message;
} }
echo $message; echo $message;
?> ?>
</strong></p></div> </strong></p></div>
<?php endif; ?> <?php endif; ?>
<h3>Account Options</h3> <h3>Account Options</h3>
<div id="acount-options"> <div id="acount-options">
<table class="form-table"> <table class="form-table">
<tr valign="top"> <tr valign="top">
<th class="titledesc" scope="row"> <th class="titledesc" scope="row">
<?php echo SyC::t('sdk','API Status:'); ?> <?php echo SyC::t('sdk','API Status:'); ?>
<?php if ( $this->isActive() ) echo SyC::t('sdk','Enabled'); else echo SyC::t('sdk','Disabled'); ?> <?php if ( $this->isActive() ) echo SyC::t('sdk','Enabled'); else echo SyC::t('sdk','Disabled'); ?>
</th> </th>
<td class="forminp"> <td class="forminp">
<?php if($this->isActive()) : ?> <?php if($this->isActive()) : ?>
<input class="button" type="submit" value="<?php echo SyC::t('sdk','Disable'); ?>" name="disable-API" /> <input class="button" type="submit" value="<?php echo SyC::t('sdk','Disable'); ?>" name="disable-API" />
<?php else :?> <?php else :?>
<input class="button" type="submit" value="<?php echo SyC::t('sdk','Enable'); ?>" name="enable-API" /> <input class="button" type="submit" value="<?php echo SyC::t('sdk','Enable'); ?>" name="enable-API" />
<?php endif;?> <?php endif;?>
</td> </td>
</tr> </tr>
<tr valign="top"> <tr valign="top">
@ -96,19 +96,19 @@ if ($refresh || ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty( $_REQUEST['syc-
<tr valign="top"> <tr valign="top">
<th class="titledesc" scope="row"><?php echo SyC::t('sdk','Configuration'); ?></th> <th class="titledesc" scope="row"><?php echo SyC::t('sdk','Configuration'); ?></th>
<td> <td>
<a href="<?php echo $this->SHAREYOURCART_CONFIGURE; ?>?app_key=<?php echo $this->getAppKey(); ?>&amp;client_id=<?php echo $this->getClientId(); ?>&amp;email=<?php echo $this->getAdminEmail(); ?>" class="button" target="_blank"><?php _e('Configure', 'woocommerce'); ?></a> <a href="<?php echo $this->SHAREYOURCART_CONFIGURE; ?>?app_key=<?php echo $this->getAppKey(); ?>&amp;client_id=<?php echo $this->getClientId(); ?>&amp;email=<?php echo $this->getAdminEmail(); ?>" class="button" target="_blank"><?php _e('Configure', 'woocommerce'); ?></a>
<p class="description"><?php echo SyC::t('sdk','You can choose how much of a discount to give (in fixed amount, percentage, or free shipping) and to which social media channels it should it be applied. You can also define what the advertisement should say, so that it fully benefits your sales.'); ?></p> <p class="description"><?php echo SyC::t('sdk','You can choose how much of a discount to give (in fixed amount, percentage, or free shipping) and to which social media channels it should it be applied. You can also define what the advertisement should say, so that it fully benefits your sales.'); ?></p>
</td> </td>
</tr> </tr>
<?php endif;?> <?php endif;?>
</table> </table>
<div class="submit"> <div class="submit">
<input type="submit" class="button button-primary" name="syc-account-form" value="<?php _e('Save changes', 'woocommerce'); ?>" /> <input type="submit" class="button button-primary" name="syc-account-form" value="<?php _e('Save changes', 'woocommerce'); ?>" />
</div> </div>
</div> </div>
</div> </div>

View File

@ -11,7 +11,7 @@
<legend class="screen-reader-text"><span><?php _e( 'Button style', 'woocommerce' ); ?></span></legend> <legend class="screen-reader-text"><span><?php _e( 'Button style', 'woocommerce' ); ?></span></legend>
<p> <p>
<label> <label>
<input type="radio" value="1" id="button_type_1" <?php if ($current_button_type == '1'||$current_button_type == '') echo 'checked' ?> name="button_type" class="tog" /> <input type="radio" value="1" id="button_type_1" <?php if ($current_button_type == '1'||$current_button_type == '') echo 'checked' ?> name="button_type" class="tog" />
<?php echo SyC::t('sdk','Use Standard Button'); ?> <?php echo SyC::t('sdk','Use Standard Button'); ?>
</label> </label>
</p> </p>
@ -37,7 +37,7 @@
</label> </label>
</li> </li>
</ul> </ul>
<p> <p>
<label> <label>
<input type="radio" value="2" id="button_type_2" name="button_type" <?php if ($current_button_type == '2') echo 'checked' ?> class="tog" /> <input type="radio" value="2" id="button_type_2" name="button_type" <?php if ($current_button_type == '2') echo 'checked' ?> class="tog" />
@ -51,7 +51,7 @@
<?php if ( ! empty( $button_img ) ): ?> <?php if ( ! empty( $button_img ) ): ?>
<img src="<?php echo $button_img ?>" height="40" /><br/> <img src="<?php echo $button_img ?>" height="40" /><br/>
<?php endif; ?> <?php endif; ?>
<input type="hidden" name="MAX_FILE_SIZE" value="100000000000" /> <input type="hidden" name="MAX_FILE_SIZE" value="100000000000" />
<input type="file" accept="image/gif, image/jpeg, image/jpg, image/png" name="button-img" id="button-img" /> <input type="file" accept="image/gif, image/jpeg, image/jpg, image/png" name="button-img" id="button-img" />
</label> </label>
@ -62,13 +62,13 @@
<?php if ( ! empty( $button_img_hover ) ): ?> <?php if ( ! empty( $button_img_hover ) ): ?>
<img src="<?php echo $button_img_hover ?>" height="40" /><br/> <img src="<?php echo $button_img_hover ?>" height="40" /><br/>
<?php endif; ?> <?php endif; ?>
<input type="hidden" name="MAX_FILE_SIZE" value="100000000000" /> <input type="hidden" name="MAX_FILE_SIZE" value="100000000000" />
<input type="file" accept="image/gif, image/jpeg, image/jpg, image/png" name="button-img-hover" id="button-img-hover" /> <input type="file" accept="image/gif, image/jpeg, image/jpg, image/png" name="button-img-hover" id="button-img-hover" />
</label> </label>
</li> </li>
</ul> </ul>
<p> <p>
<label> <label>
<input type="radio" value="3" id="button_type_3" name="button_type" <?php if ($current_button_type == '3') echo 'checked' ?> class="tog" /> <input type="radio" value="3" id="button_type_3" name="button_type" <?php if ($current_button_type == '3') echo 'checked' ?> class="tog" />
@ -83,12 +83,12 @@
</label> </label>
</li> </li>
</ul> </ul>
</fieldset> </fieldset>
</td> </td>
</tr> </tr>
</table> </table>
<?php echo $html; ?> <?php echo $html; ?>
<fieldset> <fieldset>
<table class="form-table " name="shareyourcart_settings"> <table class="form-table " name="shareyourcart_settings">
<tr> <tr>
@ -96,7 +96,7 @@
<td> <td>
<input class="buttonCheckbox" name="show_on_product" <?php echo $show_on_product ? 'checked="checked"' : ''; ?> type='checkbox'><?php echo SyC::t('sdk','Product page'); ?></input> <input class="buttonCheckbox" name="show_on_product" <?php echo $show_on_product ? 'checked="checked"' : ''; ?> type='checkbox'><?php echo SyC::t('sdk','Product page'); ?></input>
<br /> <br />
<input class="buttonCheckbox" name="show_on_checkout" <?php echo $show_on_checkout ? 'checked="checked"' : ''; ?> type='checkbox'><?php echo SyC::t('sdk','Checkout page'); ?></input> <input class="buttonCheckbox" name="show_on_checkout" <?php echo $show_on_checkout ? 'checked="checked"' : ''; ?> type='checkbox'><?php echo SyC::t('sdk','Checkout page'); ?></input>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -114,10 +114,10 @@
</td> </td>
</tr> </tr>
</table> </table>
</fieldset> </fieldset>
<div class="submit"> <div class="submit">
<input type="submit" class="button button-primary" name="syc-visual-form" value="<?php _e('Save changes', 'woocommerce'); ?>" /> <input type="submit" class="button button-primary" name="syc-visual-form" value="<?php _e('Save changes', 'woocommerce'); ?>" />
</div> </div>
</div> </div>
</div> </div>

View File

@ -191,18 +191,18 @@ class WC_Flat_Rate extends WC_Shipping_Method {
$cost_per_order = ( isset( $this->cost_per_order ) && ! empty( $this->cost_per_order ) ) ? $this->cost_per_order : 0; $cost_per_order = ( isset( $this->cost_per_order ) && ! empty( $this->cost_per_order ) ) ? $this->cost_per_order : 0;
if ( $this->type == 'order' ) { if ( $this->type == 'order' ) {
$shipping_total = $this->order_shipping( $package ); $shipping_total = $this->order_shipping( $package );
if ( ! is_null( $shipping_total ) || $cost_per_order > 0 ) if ( ! is_null( $shipping_total ) || $cost_per_order > 0 )
$rate = array( $rate = array(
'id' => $this->id, 'id' => $this->id,
'label' => $this->title, 'label' => $this->title,
'cost' => $shipping_total + $cost_per_order, 'cost' => $shipping_total + $cost_per_order,
); );
} elseif ( $this->type == 'class' ) { } elseif ( $this->type == 'class' ) {
$shipping_total = $this->class_shipping( $package ); $shipping_total = $this->class_shipping( $package );
if ( ! is_null( $shipping_total ) || $cost_per_order > 0 ) if ( ! is_null( $shipping_total ) || $cost_per_order > 0 )
@ -211,28 +211,28 @@ class WC_Flat_Rate extends WC_Shipping_Method {
'label' => $this->title, 'label' => $this->title,
'cost' => $shipping_total + $cost_per_order, 'cost' => $shipping_total + $cost_per_order,
); );
} elseif ( $this->type == 'item' ) { } elseif ( $this->type == 'item' ) {
$costs = $this->item_shipping( $package ); $costs = $this->item_shipping( $package );
if ( ! is_null( $costs ) || $cost_per_order > 0 ) { if ( ! is_null( $costs ) || $cost_per_order > 0 ) {
if ( ! is_array( $costs ) ) if ( ! is_array( $costs ) )
$costs = array(); $costs = array();
$costs['order'] = $cost_per_order; $costs['order'] = $cost_per_order;
$rate = array( $rate = array(
'id' => $this->id, 'id' => $this->id,
'label' => $this->title, 'label' => $this->title,
'cost' => $costs, 'cost' => $costs,
'calc_tax' => 'per_item', 'calc_tax' => 'per_item',
); );
} }
} }
if ( ! isset( $rate ) ) if ( ! isset( $rate ) )
return; return;
@ -332,7 +332,7 @@ class WC_Flat_Rate extends WC_Shipping_Method {
} elseif ( is_null( $cost ) ) { } elseif ( is_null( $cost ) ) {
// No match // No match
return null; return null;
} }
// Shipping for whole order // Shipping for whole order
return $cost + $this->get_fee( $fee, $package['contents_cost'] ); return $cost + $this->get_fee( $fee, $package['contents_cost'] );
@ -367,9 +367,9 @@ class WC_Flat_Rate extends WC_Shipping_Method {
} }
$found_shipping_classes = array_unique( $found_shipping_classes ); $found_shipping_classes = array_unique( $found_shipping_classes );
$matched = false; $matched = false;
// For each found class, add up the costs and fees // For each found class, add up the costs and fees
foreach ( $found_shipping_classes as $shipping_class => $class_price ) { foreach ( $found_shipping_classes as $shipping_class => $class_price ) {
if ( isset( $this->flat_rates[ $shipping_class ] ) ) { if ( isset( $this->flat_rates[ $shipping_class ] ) ) {
@ -403,7 +403,7 @@ class WC_Flat_Rate extends WC_Shipping_Method {
function item_shipping( $package ) { function item_shipping( $package ) {
// Per item shipping so we pass an array of costs (per item) instead of a single value // Per item shipping so we pass an array of costs (per item) instead of a single value
$costs = array(); $costs = array();
$matched = false; $matched = false;
// Shipping per item // Shipping per item
@ -412,9 +412,9 @@ class WC_Flat_Rate extends WC_Shipping_Method {
if ( $values['quantity'] > 0 && $_product->needs_shipping() ) { if ( $values['quantity'] > 0 && $_product->needs_shipping() ) {
$shipping_class = $_product->get_shipping_class(); $shipping_class = $_product->get_shipping_class();
$fee = $cost = 0; $fee = $cost = 0;
if ( isset( $this->flat_rates[ $shipping_class ] ) ) { if ( isset( $this->flat_rates[ $shipping_class ] ) ) {
$cost = $this->flat_rates[ $shipping_class ]['cost']; $cost = $this->flat_rates[ $shipping_class ]['cost'];
$fee = $this->get_fee( $this->flat_rates[ $shipping_class ]['fee'], $_product->get_price() ); $fee = $this->get_fee( $this->flat_rates[ $shipping_class ]['fee'], $_product->get_price() );
@ -428,7 +428,7 @@ class WC_Flat_Rate extends WC_Shipping_Method {
$costs[ $item_id ] = ( ( $cost + $fee ) * $values['quantity'] ); $costs[ $item_id ] = ( ( $cost + $fee ) * $values['quantity'] );
} }
} }
if ( $matched ) if ( $matched )
return $costs; return $costs;
else else

View File

@ -191,29 +191,29 @@ class WC_Local_Delivery extends WC_Shipping_Method {
$codes[] = $this->clean( $code ); $codes[] = $this->clean( $code );
} }
} }
if ( is_array( $codes ) ) { if ( is_array( $codes ) ) {
$found_match = false; $found_match = false;
if ( in_array( $this->clean( $package['destination']['postcode'] ), $codes ) ) if ( in_array( $this->clean( $package['destination']['postcode'] ), $codes ) )
$found_match = true; $found_match = true;
// Wildcard search // Wildcard search
if ( ! $found_match ) { if ( ! $found_match ) {
$customer_postcode = $this->clean( $package['destination']['postcode'] ); $customer_postcode = $this->clean( $package['destination']['postcode'] );
$customer_postcode_length = strlen( $customer_postcode ); $customer_postcode_length = strlen( $customer_postcode );
for ( $i = 0; $i <= $customer_postcode_length; $i++ ) { for ( $i = 0; $i <= $customer_postcode_length; $i++ ) {
if ( in_array( $customer_postcode, $codes ) ) if ( in_array( $customer_postcode, $codes ) )
$found_match = true; $found_match = true;
$customer_postcode = substr( $customer_postcode, 0, -2 ) . '*'; $customer_postcode = substr( $customer_postcode, 0, -2 ) . '*';
} }
} }
if ( ! $found_match ) if ( ! $found_match )
return false; return false;
} }

Some files were not shown because too many files have changed in this diff Show More