Merge branch 'master' into fix/19404
This commit is contained in:
commit
59af63e642
|
@ -1876,7 +1876,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function has_status( $status ) {
|
public function has_status( $status ) {
|
||||||
return apply_filters( 'woocommerce_order_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status ? true : false, $this, $status );
|
return apply_filters( 'woocommerce_order_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status, $this, $status );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -273,7 +273,7 @@ abstract class WC_Payment_Gateway extends WC_Settings_API {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function has_fields() {
|
public function has_fields() {
|
||||||
return $this->has_fields ? true : false;
|
return (bool) $this->has_fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -385,7 +385,7 @@ abstract class WC_Payment_Gateway extends WC_Settings_API {
|
||||||
* @since 1.5.7
|
* @since 1.5.7
|
||||||
*/
|
*/
|
||||||
public function supports( $feature ) {
|
public function supports( $feature ) {
|
||||||
return apply_filters( 'woocommerce_payment_gateway_supports', in_array( $feature, $this->supports ) ? true : false, $feature, $this );
|
return apply_filters( 'woocommerce_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1360,7 +1360,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
||||||
* @since 2.5.0
|
* @since 2.5.0
|
||||||
*/
|
*/
|
||||||
public function supports( $feature ) {
|
public function supports( $feature ) {
|
||||||
return apply_filters( 'woocommerce_product_supports', in_array( $feature, $this->supports ) ? true : false, $feature, $this );
|
return apply_filters( 'woocommerce_product_supports', in_array( $feature, $this->supports ), $feature, $this );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1577,7 +1577,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->managing_stock() && $this->backorders_allowed() && ( $this->get_stock_quantity() - $qty_in_cart ) < 0 ? true : false;
|
return $this->managing_stock() && $this->backorders_allowed() && ( $this->get_stock_quantity() - $qty_in_cart ) < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -43,7 +43,7 @@ abstract class WC_Background_Process extends WP_Background_Process {
|
||||||
|
|
||||||
$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$table} WHERE {$column} LIKE %s", $key ) ); // @codingStandardsIgnoreLine.
|
$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$table} WHERE {$column} LIKE %s", $key ) ); // @codingStandardsIgnoreLine.
|
||||||
|
|
||||||
return ( $count > 0 ) ? false : true;
|
return ! ( $count > 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -603,7 +603,7 @@ class WC_REST_System_Status_Controller extends WC_REST_Controller {
|
||||||
'site_url' => get_option( 'siteurl' ),
|
'site_url' => get_option( 'siteurl' ),
|
||||||
'version' => WC()->version,
|
'version' => WC()->version,
|
||||||
'log_directory' => WC_LOG_DIR,
|
'log_directory' => WC_LOG_DIR,
|
||||||
'log_directory_writable' => ( @fopen( WC_LOG_DIR . 'test-log.log', 'a' ) ? true : false ),
|
'log_directory_writable' => (bool) @fopen( WC_LOG_DIR . 'test-log.log', 'a' ),
|
||||||
'wp_version' => get_bloginfo( 'version' ),
|
'wp_version' => get_bloginfo( 'version' ),
|
||||||
'wp_multisite' => is_multisite(),
|
'wp_multisite' => is_multisite(),
|
||||||
'wp_memory_limit' => $wp_memory_limit,
|
'wp_memory_limit' => $wp_memory_limit,
|
||||||
|
|
|
@ -337,7 +337,7 @@ class WC_API_Orders extends WC_API_Resource {
|
||||||
'id' => $note->comment_ID,
|
'id' => $note->comment_ID,
|
||||||
'created_at' => $this->server->format_datetime( $note->comment_date_gmt ),
|
'created_at' => $this->server->format_datetime( $note->comment_date_gmt ),
|
||||||
'note' => $note->comment_content,
|
'note' => $note->comment_content,
|
||||||
'customer_note' => get_comment_meta( $note->comment_ID, 'is_customer_note', true ) ? true : false,
|
'customer_note' => (bool) get_comment_meta( $note->comment_ID, 'is_customer_note', true ),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1269,7 +1269,7 @@ class WC_API_Orders extends WC_API_Resource {
|
||||||
'id' => $note->comment_ID,
|
'id' => $note->comment_ID,
|
||||||
'created_at' => $this->server->format_datetime( $note->comment_date_gmt ),
|
'created_at' => $this->server->format_datetime( $note->comment_date_gmt ),
|
||||||
'note' => $note->comment_content,
|
'note' => $note->comment_content,
|
||||||
'customer_note' => get_comment_meta( $note->comment_ID, 'is_customer_note', true ) ? true : false,
|
'customer_note' => (bool) get_comment_meta( $note->comment_ID, 'is_customer_note', true ),
|
||||||
);
|
);
|
||||||
|
|
||||||
return array( 'order_note' => apply_filters( 'woocommerce_api_order_note_response', $order_note, $id, $fields, $note, $order_id, $this ) );
|
return array( 'order_note' => apply_filters( 'woocommerce_api_order_note_response', $order_note, $id, $fields, $note, $order_id, $this ) );
|
||||||
|
|
|
@ -440,7 +440,7 @@ class WC_API_Products extends WC_API_Resource {
|
||||||
}
|
}
|
||||||
|
|
||||||
$product->delete( true );
|
$product->delete( true );
|
||||||
$result = $product->get_id() > 0 ? false : true;
|
$result = ! ( $product->get_id() > 0 );
|
||||||
} else {
|
} else {
|
||||||
$product->delete();
|
$product->delete();
|
||||||
$result = 'trash' === $product->get_status();
|
$result = 'trash' === $product->get_status();
|
||||||
|
|
|
@ -1316,7 +1316,7 @@ class WC_API_Orders extends WC_API_Resource {
|
||||||
'id' => $note->comment_ID,
|
'id' => $note->comment_ID,
|
||||||
'created_at' => $this->server->format_datetime( $note->comment_date_gmt ),
|
'created_at' => $this->server->format_datetime( $note->comment_date_gmt ),
|
||||||
'note' => $note->comment_content,
|
'note' => $note->comment_content,
|
||||||
'customer_note' => get_comment_meta( $note->comment_ID, 'is_customer_note', true ) ? true : false,
|
'customer_note' => (bool) get_comment_meta( $note->comment_ID, 'is_customer_note', true ),
|
||||||
);
|
);
|
||||||
|
|
||||||
return array( 'order_note' => apply_filters( 'woocommerce_api_order_note_response', $order_note, $id, $fields, $note, $order_id, $this ) );
|
return array( 'order_note' => apply_filters( 'woocommerce_api_order_note_response', $order_note, $id, $fields, $note, $order_id, $this ) );
|
||||||
|
|
|
@ -499,7 +499,7 @@ class WC_API_Products extends WC_API_Resource {
|
||||||
}
|
}
|
||||||
|
|
||||||
$product->delete( true );
|
$product->delete( true );
|
||||||
$result = $product->get_id() > 0 ? false : true;
|
$result = ! ( $product->get_id() > 0 );
|
||||||
} else {
|
} else {
|
||||||
$product->delete();
|
$product->delete();
|
||||||
$result = 'trash' === $product->get_status();
|
$result = 'trash' === $product->get_status();
|
||||||
|
|
|
@ -1675,7 +1675,7 @@ class WC_REST_Products_V1_Controller extends WC_REST_Posts_Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
$product->delete( true );
|
$product->delete( true );
|
||||||
$result = $product->get_id() > 0 ? false : true;
|
$result = ! ( $product->get_id() > 0 );
|
||||||
} else {
|
} else {
|
||||||
// If we don't support trashing for this type, error out.
|
// If we don't support trashing for this type, error out.
|
||||||
if ( ! $supports_trash ) {
|
if ( ! $supports_trash ) {
|
||||||
|
|
|
@ -1,32 +1,40 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
|
||||||
exit; // Exit if accessed directly
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transactional Emails Controller
|
* Transactional Emails Controller
|
||||||
*
|
*
|
||||||
* WooCommerce Emails Class which handles the sending on transactional emails and email templates. This class loads in available emails.
|
* WooCommerce Emails Class which handles the sending on transactional emails and email templates. This class loads in available emails.
|
||||||
*
|
*
|
||||||
* @class WC_Emails
|
|
||||||
* @version 2.3.0
|
|
||||||
* @package WooCommerce/Classes/Emails
|
* @package WooCommerce/Classes/Emails
|
||||||
* @category Class
|
* @version 2.3.0
|
||||||
* @author WooThemes
|
*/
|
||||||
|
|
||||||
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emails class.
|
||||||
*/
|
*/
|
||||||
class WC_Emails {
|
class WC_Emails {
|
||||||
|
|
||||||
/** @var array Array of email notification classes */
|
/**
|
||||||
public $emails;
|
* Array of email notification classes
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $emails = array();
|
||||||
|
|
||||||
/** @var WC_Emails The single instance of the class */
|
/**
|
||||||
|
* The single instance of the class
|
||||||
|
*
|
||||||
|
* @var WC_Emails
|
||||||
|
*/
|
||||||
protected static $_instance = null;
|
protected static $_instance = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Background emailer class.
|
* Background emailer class.
|
||||||
|
*
|
||||||
|
* @var WC_Background_Emailer
|
||||||
*/
|
*/
|
||||||
protected static $background_emailer;
|
protected static $background_emailer = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main WC_Emails Instance.
|
* Main WC_Emails Instance.
|
||||||
|
@ -66,7 +74,8 @@ class WC_Emails {
|
||||||
* Hook in all transactional emails.
|
* Hook in all transactional emails.
|
||||||
*/
|
*/
|
||||||
public static function init_transactional_emails() {
|
public static function init_transactional_emails() {
|
||||||
$email_actions = apply_filters( 'woocommerce_email_actions', array(
|
$email_actions = apply_filters(
|
||||||
|
'woocommerce_email_actions', array(
|
||||||
'woocommerce_low_stock',
|
'woocommerce_low_stock',
|
||||||
'woocommerce_no_stock',
|
'woocommerce_no_stock',
|
||||||
'woocommerce_product_on_backorder',
|
'woocommerce_product_on_backorder',
|
||||||
|
@ -86,7 +95,8 @@ class WC_Emails {
|
||||||
'woocommerce_order_partially_refunded',
|
'woocommerce_order_partially_refunded',
|
||||||
'woocommerce_new_customer_note',
|
'woocommerce_new_customer_note',
|
||||||
'woocommerce_created_customer',
|
'woocommerce_created_customer',
|
||||||
) );
|
)
|
||||||
|
);
|
||||||
|
|
||||||
if ( apply_filters( 'woocommerce_defer_transactional_emails', false ) ) {
|
if ( apply_filters( 'woocommerce_defer_transactional_emails', false ) ) {
|
||||||
self::$background_emailer = new WC_Background_Emailer();
|
self::$background_emailer = new WC_Background_Emailer();
|
||||||
|
@ -107,10 +117,12 @@ class WC_Emails {
|
||||||
*/
|
*/
|
||||||
public static function queue_transactional_email() {
|
public static function queue_transactional_email() {
|
||||||
if ( is_a( self::$background_emailer, 'WC_Background_Emailer' ) ) {
|
if ( is_a( self::$background_emailer, 'WC_Background_Emailer' ) ) {
|
||||||
self::$background_emailer->push_to_queue( array(
|
self::$background_emailer->push_to_queue(
|
||||||
|
array(
|
||||||
'filter' => current_filter(),
|
'filter' => current_filter(),
|
||||||
'args' => func_get_args(),
|
'args' => func_get_args(),
|
||||||
) );
|
)
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
call_user_func_array( array( __CLASS__, 'send_transactional_email' ), func_get_args() );
|
call_user_func_array( array( __CLASS__, 'send_transactional_email' ), func_get_args() );
|
||||||
}
|
}
|
||||||
|
@ -150,19 +162,18 @@ class WC_Emails {
|
||||||
do_action_ref_array( current_filter() . '_notification', $args );
|
do_action_ref_array( current_filter() . '_notification', $args );
|
||||||
} catch ( Exception $e ) {
|
} catch ( Exception $e ) {
|
||||||
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
|
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
|
||||||
trigger_error( 'Transactional email triggered fatal error for callback ' . current_filter(), E_USER_WARNING );
|
trigger_error( 'Transactional email triggered fatal error for callback ' . current_filter(), E_USER_WARNING ); // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped, WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for the email class hooks in all emails that can be sent.
|
* Constructor for the email class hooks in all emails that can be sent.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->init();
|
$this->init();
|
||||||
|
|
||||||
// Email Header, Footer and content hooks
|
// Email Header, Footer and content hooks.
|
||||||
add_action( 'woocommerce_email_header', array( $this, 'email_header' ) );
|
add_action( 'woocommerce_email_header', array( $this, 'email_header' ) );
|
||||||
add_action( 'woocommerce_email_footer', array( $this, 'email_footer' ) );
|
add_action( 'woocommerce_email_footer', array( $this, 'email_footer' ) );
|
||||||
add_action( 'woocommerce_email_order_details', array( $this, 'order_downloads' ), 10, 4 );
|
add_action( 'woocommerce_email_order_details', array( $this, 'order_downloads' ), 10, 4 );
|
||||||
|
@ -171,7 +182,7 @@ class WC_Emails {
|
||||||
add_action( 'woocommerce_email_customer_details', array( $this, 'customer_details' ), 10, 3 );
|
add_action( 'woocommerce_email_customer_details', array( $this, 'customer_details' ), 10, 3 );
|
||||||
add_action( 'woocommerce_email_customer_details', array( $this, 'email_addresses' ), 20, 3 );
|
add_action( 'woocommerce_email_customer_details', array( $this, 'email_addresses' ), 20, 3 );
|
||||||
|
|
||||||
// Hooks for sending emails during store events
|
// Hooks for sending emails during store events.
|
||||||
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' ) );
|
||||||
|
@ -180,7 +191,7 @@ class WC_Emails {
|
||||||
// Hook for replacing {site_title} in email-footer.
|
// Hook for replacing {site_title} in email-footer.
|
||||||
add_filter( 'woocommerce_email_footer_text', array( $this, 'email_footer_replace_site_title' ) );
|
add_filter( 'woocommerce_email_footer_text', array( $this, 'email_footer_replace_site_title' ) );
|
||||||
|
|
||||||
// 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 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,26 +199,26 @@ class WC_Emails {
|
||||||
* Init email classes.
|
* Init email classes.
|
||||||
*/
|
*/
|
||||||
public function init() {
|
public function init() {
|
||||||
// Include email classes
|
// Include email classes.
|
||||||
include_once( dirname( __FILE__ ) . '/emails/class-wc-email.php' );
|
include_once dirname( __FILE__ ) . '/emails/class-wc-email.php';
|
||||||
|
|
||||||
$this->emails['WC_Email_New_Order'] = include( 'emails/class-wc-email-new-order.php' );
|
$this->emails['WC_Email_New_Order'] = include 'emails/class-wc-email-new-order.php';
|
||||||
$this->emails['WC_Email_Cancelled_Order'] = include( 'emails/class-wc-email-cancelled-order.php' );
|
$this->emails['WC_Email_Cancelled_Order'] = include 'emails/class-wc-email-cancelled-order.php';
|
||||||
$this->emails['WC_Email_Failed_Order'] = include( 'emails/class-wc-email-failed-order.php' );
|
$this->emails['WC_Email_Failed_Order'] = include 'emails/class-wc-email-failed-order.php';
|
||||||
$this->emails['WC_Email_Customer_On_Hold_Order'] = include( 'emails/class-wc-email-customer-on-hold-order.php' );
|
$this->emails['WC_Email_Customer_On_Hold_Order'] = include 'emails/class-wc-email-customer-on-hold-order.php';
|
||||||
$this->emails['WC_Email_Customer_Processing_Order'] = include( 'emails/class-wc-email-customer-processing-order.php' );
|
$this->emails['WC_Email_Customer_Processing_Order'] = include 'emails/class-wc-email-customer-processing-order.php';
|
||||||
$this->emails['WC_Email_Customer_Completed_Order'] = include( 'emails/class-wc-email-customer-completed-order.php' );
|
$this->emails['WC_Email_Customer_Completed_Order'] = include 'emails/class-wc-email-customer-completed-order.php';
|
||||||
$this->emails['WC_Email_Customer_Refunded_Order'] = include( 'emails/class-wc-email-customer-refunded-order.php' );
|
$this->emails['WC_Email_Customer_Refunded_Order'] = include 'emails/class-wc-email-customer-refunded-order.php';
|
||||||
$this->emails['WC_Email_Customer_Invoice'] = include( 'emails/class-wc-email-customer-invoice.php' );
|
$this->emails['WC_Email_Customer_Invoice'] = include 'emails/class-wc-email-customer-invoice.php';
|
||||||
$this->emails['WC_Email_Customer_Note'] = include( 'emails/class-wc-email-customer-note.php' );
|
$this->emails['WC_Email_Customer_Note'] = include 'emails/class-wc-email-customer-note.php';
|
||||||
$this->emails['WC_Email_Customer_Reset_Password'] = include( 'emails/class-wc-email-customer-reset-password.php' );
|
$this->emails['WC_Email_Customer_Reset_Password'] = include 'emails/class-wc-email-customer-reset-password.php';
|
||||||
$this->emails['WC_Email_Customer_New_Account'] = include( 'emails/class-wc-email-customer-new-account.php' );
|
$this->emails['WC_Email_Customer_New_Account'] = include 'emails/class-wc-email-customer-new-account.php';
|
||||||
|
|
||||||
$this->emails = apply_filters( 'woocommerce_email_classes', $this->emails );
|
$this->emails = apply_filters( 'woocommerce_email_classes', $this->emails );
|
||||||
|
|
||||||
// include css inliner
|
// include css inliner.
|
||||||
if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) {
|
if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) {
|
||||||
include_once( dirname( __FILE__ ) . '/libraries/class-emogrifier.php' );
|
include_once dirname( __FILE__ ) . '/libraries/class-emogrifier.php';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,7 +252,7 @@ class WC_Emails {
|
||||||
/**
|
/**
|
||||||
* Get the email header.
|
* Get the email header.
|
||||||
*
|
*
|
||||||
* @param mixed $email_heading heading for the email
|
* @param mixed $email_heading Heading for the email.
|
||||||
*/
|
*/
|
||||||
public function email_header( $email_heading ) {
|
public function email_header( $email_heading ) {
|
||||||
wc_get_template( 'emails/email-header.php', array( 'email_heading' => $email_heading ) );
|
wc_get_template( 'emails/email-header.php', array( 'email_heading' => $email_heading ) );
|
||||||
|
@ -280,7 +291,7 @@ class WC_Emails {
|
||||||
|
|
||||||
do_action( 'woocommerce_email_header', $email_heading, null );
|
do_action( 'woocommerce_email_header', $email_heading, null );
|
||||||
|
|
||||||
echo wpautop( wptexturize( $message ) );
|
echo wpautop( wptexturize( $message ) ); // WPCS: XSS ok.
|
||||||
|
|
||||||
do_action( 'woocommerce_email_footer', null );
|
do_action( 'woocommerce_email_footer', null );
|
||||||
|
|
||||||
|
@ -293,15 +304,15 @@ class WC_Emails {
|
||||||
/**
|
/**
|
||||||
* Send the email.
|
* Send the email.
|
||||||
*
|
*
|
||||||
* @param mixed $to
|
* @param mixed $to Receiver.
|
||||||
* @param mixed $subject
|
* @param mixed $subject Email subject.
|
||||||
* @param mixed $message
|
* @param mixed $message Message.
|
||||||
* @param string $headers (default: "Content-Type: text/html\r\n")
|
* @param string $headers Email headers (default: "Content-Type: text/html\r\n").
|
||||||
* @param string $attachments (default: "")
|
* @param string $attachments Attachments (default: "").
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function send( $to, $subject, $message, $headers = "Content-Type: text/html\r\n", $attachments = "" ) {
|
public function send( $to, $subject, $message, $headers = "Content-Type: text/html\r\n", $attachments = '' ) {
|
||||||
// Send
|
// Send.
|
||||||
$email = new WC_Email();
|
$email = new WC_Email();
|
||||||
return $email->send( $to, $subject, $message, $headers, $attachments );
|
return $email->send( $to, $subject, $message, $headers, $attachments );
|
||||||
}
|
}
|
||||||
|
@ -309,7 +320,7 @@ class WC_Emails {
|
||||||
/**
|
/**
|
||||||
* Prepare and send the customer invoice email on demand.
|
* Prepare and send the customer invoice email on demand.
|
||||||
*
|
*
|
||||||
* @param int|WC_Order $order
|
* @param int|WC_Order $order Order instance or ID.
|
||||||
*/
|
*/
|
||||||
public function customer_invoice( $order ) {
|
public function customer_invoice( $order ) {
|
||||||
$email = $this->emails['WC_Email_Customer_Invoice'];
|
$email = $this->emails['WC_Email_Customer_Invoice'];
|
||||||
|
@ -324,9 +335,9 @@ class WC_Emails {
|
||||||
/**
|
/**
|
||||||
* Customer new account welcome email.
|
* Customer new account welcome email.
|
||||||
*
|
*
|
||||||
* @param int $customer_id
|
* @param int $customer_id Customer ID.
|
||||||
* @param array $new_customer_data
|
* @param array $new_customer_data New customer data.
|
||||||
* @param bool $password_generated
|
* @param bool $password_generated If password is generated.
|
||||||
*/
|
*/
|
||||||
public function customer_new_account( $customer_id, $new_customer_data = array(), $password_generated = false ) {
|
public function customer_new_account( $customer_id, $new_customer_data = array(), $password_generated = false ) {
|
||||||
if ( ! $customer_id ) {
|
if ( ! $customer_id ) {
|
||||||
|
@ -342,16 +353,30 @@ class WC_Emails {
|
||||||
/**
|
/**
|
||||||
* Show the order details table
|
* Show the order details table
|
||||||
*
|
*
|
||||||
* @param WC_Order $order
|
* @param WC_Order $order Order instance.
|
||||||
* @param bool $sent_to_admin
|
* @param bool $sent_to_admin If should sent to admin.
|
||||||
* @param bool $plain_text
|
* @param bool $plain_text If is plain text email.
|
||||||
* @param string $email
|
* @param string $email Email address.
|
||||||
*/
|
*/
|
||||||
public function order_details( $order, $sent_to_admin = false, $plain_text = false, $email = '' ) {
|
public function order_details( $order, $sent_to_admin = false, $plain_text = false, $email = '' ) {
|
||||||
if ( $plain_text ) {
|
if ( $plain_text ) {
|
||||||
wc_get_template( 'emails/plain/email-order-details.php', array( 'order' => $order, 'sent_to_admin' => $sent_to_admin, 'plain_text' => $plain_text, 'email' => $email ) );
|
wc_get_template(
|
||||||
|
'emails/plain/email-order-details.php', array(
|
||||||
|
'order' => $order,
|
||||||
|
'sent_to_admin' => $sent_to_admin,
|
||||||
|
'plain_text' => $plain_text,
|
||||||
|
'email' => $email,
|
||||||
|
)
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
wc_get_template( 'emails/email-order-details.php', array( 'order' => $order, 'sent_to_admin' => $sent_to_admin, 'plain_text' => $plain_text, 'email' => $email ) );
|
wc_get_template(
|
||||||
|
'emails/email-order-details.php', array(
|
||||||
|
'order' => $order,
|
||||||
|
'sent_to_admin' => $sent_to_admin,
|
||||||
|
'plain_text' => $plain_text,
|
||||||
|
'email' => $email,
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -359,10 +384,10 @@ class WC_Emails {
|
||||||
* Show order downloads in a table.
|
* Show order downloads in a table.
|
||||||
*
|
*
|
||||||
* @since 3.2.0
|
* @since 3.2.0
|
||||||
* @param WC_Order $order
|
* @param WC_Order $order Order instance.
|
||||||
* @param bool $sent_to_admin
|
* @param bool $sent_to_admin If should sent to admin.
|
||||||
* @param bool $plain_text
|
* @param bool $plain_text If is plain text email.
|
||||||
* @param string $email
|
* @param string $email Email address.
|
||||||
*/
|
*/
|
||||||
public function order_downloads( $order, $sent_to_admin = false, $plain_text = false, $email = '' ) {
|
public function order_downloads( $order, $sent_to_admin = false, $plain_text = false, $email = '' ) {
|
||||||
$show_downloads = $order->has_downloadable_item() && $order->is_download_permitted() && ! $sent_to_admin;
|
$show_downloads = $order->has_downloadable_item() && $order->is_download_permitted() && ! $sent_to_admin;
|
||||||
|
@ -372,25 +397,45 @@ class WC_Emails {
|
||||||
}
|
}
|
||||||
|
|
||||||
$downloads = $order->get_downloadable_items();
|
$downloads = $order->get_downloadable_items();
|
||||||
$columns = apply_filters( 'woocommerce_email_downloads_columns', array(
|
$columns = apply_filters(
|
||||||
|
'woocommerce_email_downloads_columns', array(
|
||||||
'download-product' => __( 'Product', 'woocommerce' ),
|
'download-product' => __( 'Product', 'woocommerce' ),
|
||||||
'download-expires' => __( 'Expires', 'woocommerce' ),
|
'download-expires' => __( 'Expires', 'woocommerce' ),
|
||||||
'download-file' => __( 'Download', 'woocommerce' ),
|
'download-file' => __( 'Download', 'woocommerce' ),
|
||||||
) );
|
)
|
||||||
|
);
|
||||||
|
|
||||||
if ( $plain_text ) {
|
if ( $plain_text ) {
|
||||||
wc_get_template( 'emails/plain/email-downloads.php', array( 'order' => $order, 'sent_to_admin' => $sent_to_admin, 'plain_text' => $plain_text, 'email' => $email, 'downloads' => $downloads, 'columns' => $columns ) );
|
wc_get_template(
|
||||||
|
'emails/plain/email-downloads.php', array(
|
||||||
|
'order' => $order,
|
||||||
|
'sent_to_admin' => $sent_to_admin,
|
||||||
|
'plain_text' => $plain_text,
|
||||||
|
'email' => $email,
|
||||||
|
'downloads' => $downloads,
|
||||||
|
'columns' => $columns,
|
||||||
|
)
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
wc_get_template( 'emails/email-downloads.php', array( 'order' => $order, 'sent_to_admin' => $sent_to_admin, 'plain_text' => $plain_text, 'email' => $email, 'downloads' => $downloads, 'columns' => $columns ) );
|
wc_get_template(
|
||||||
|
'emails/email-downloads.php', array(
|
||||||
|
'order' => $order,
|
||||||
|
'sent_to_admin' => $sent_to_admin,
|
||||||
|
'plain_text' => $plain_text,
|
||||||
|
'email' => $email,
|
||||||
|
'downloads' => $downloads,
|
||||||
|
'columns' => $columns,
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add order meta to email templates.
|
* Add order meta to email templates.
|
||||||
*
|
*
|
||||||
* @param mixed $order
|
* @param WC_Order $order Order instance.
|
||||||
* @param bool $sent_to_admin (default: false)
|
* @param bool $sent_to_admin If should sent to admin.
|
||||||
* @param bool $plain_text (default: false)
|
* @param bool $plain_text If is plain text email.
|
||||||
*/
|
*/
|
||||||
public function order_meta( $order, $sent_to_admin = false, $plain_text = false ) {
|
public function order_meta( $order, $sent_to_admin = false, $plain_text = false ) {
|
||||||
$fields = apply_filters( 'woocommerce_email_order_meta_fields', array(), $sent_to_admin, $order );
|
$fields = apply_filters( 'woocommerce_email_order_meta_fields', array(), $sent_to_admin, $order );
|
||||||
|
@ -421,14 +466,14 @@ class WC_Emails {
|
||||||
|
|
||||||
foreach ( $fields as $field ) {
|
foreach ( $fields as $field ) {
|
||||||
if ( isset( $field['label'] ) && isset( $field['value'] ) && $field['value'] ) {
|
if ( isset( $field['label'] ) && isset( $field['value'] ) && $field['value'] ) {
|
||||||
echo $field['label'] . ': ' . $field['value'] . "\n";
|
echo $field['label'] . ': ' . $field['value'] . "\n"; // WPCS: XSS ok.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
foreach ( $fields as $field ) {
|
foreach ( $fields as $field ) {
|
||||||
if ( isset( $field['label'] ) && isset( $field['value'] ) && $field['value'] ) {
|
if ( isset( $field['label'] ) && isset( $field['value'] ) && $field['value'] ) {
|
||||||
echo '<p><strong>' . $field['label'] . ':</strong> ' . $field['value'] . '</p>';
|
echo '<p><strong>' . $field['label'] . ':</strong> ' . $field['value'] . '</p>'; // WPCS: XSS ok.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -437,7 +482,8 @@ class WC_Emails {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is customer detail field valid?
|
* Is customer detail field valid?
|
||||||
* @param array $field
|
*
|
||||||
|
* @param array $field Field data to check if is valid.
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function customer_detail_field_is_valid( $field ) {
|
public function customer_detail_field_is_valid( $field ) {
|
||||||
|
@ -449,10 +495,9 @@ class WC_Emails {
|
||||||
*
|
*
|
||||||
* In versions prior to 3.2 this was used for notes, phone and email but this data has moved.
|
* In versions prior to 3.2 this was used for notes, phone and email but this data has moved.
|
||||||
*
|
*
|
||||||
* @param WC_Order $order
|
* @param WC_Order $order Order instance.
|
||||||
* @param bool $sent_to_admin (default: false)
|
* @param bool $sent_to_admin If should sent to admin.
|
||||||
* @param bool $plain_text (default: false)
|
* @param bool $plain_text If is plain text email.
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
public function customer_details( $order, $sent_to_admin = false, $plain_text = false ) {
|
public function customer_details( $order, $sent_to_admin = false, $plain_text = false ) {
|
||||||
if ( ! is_a( $order, 'WC_Order' ) ) {
|
if ( ! is_a( $order, 'WC_Order' ) ) {
|
||||||
|
@ -473,23 +518,34 @@ class WC_Emails {
|
||||||
/**
|
/**
|
||||||
* Get the email addresses.
|
* Get the email addresses.
|
||||||
*
|
*
|
||||||
* @param WC_Order $order
|
* @param WC_Order $order Order instance.
|
||||||
* @param bool $sent_to_admin
|
* @param bool $sent_to_admin If should sent to admin.
|
||||||
* @param bool $plain_text
|
* @param bool $plain_text If is plain text email.
|
||||||
*/
|
*/
|
||||||
public function email_addresses( $order, $sent_to_admin = false, $plain_text = false ) {
|
public function email_addresses( $order, $sent_to_admin = false, $plain_text = false ) {
|
||||||
if ( ! is_a( $order, 'WC_Order' ) ) {
|
if ( ! is_a( $order, 'WC_Order' ) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ( $plain_text ) {
|
if ( $plain_text ) {
|
||||||
wc_get_template( 'emails/plain/email-addresses.php', array( 'order' => $order, 'sent_to_admin' => $sent_to_admin ) );
|
wc_get_template(
|
||||||
|
'emails/plain/email-addresses.php', array(
|
||||||
|
'order' => $order,
|
||||||
|
'sent_to_admin' => $sent_to_admin,
|
||||||
|
)
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
wc_get_template( 'emails/email-addresses.php', array( 'order' => $order, 'sent_to_admin' => $sent_to_admin ) );
|
wc_get_template(
|
||||||
|
'emails/email-addresses.php', array(
|
||||||
|
'order' => $order,
|
||||||
|
'sent_to_admin' => $sent_to_admin,
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get blog name formatted for emails.
|
* Get blog name formatted for emails.
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function get_blogname() {
|
private function get_blogname() {
|
||||||
|
@ -499,7 +555,7 @@ class WC_Emails {
|
||||||
/**
|
/**
|
||||||
* Low stock notification email.
|
* Low stock notification email.
|
||||||
*
|
*
|
||||||
* @param WC_Product $product
|
* @param WC_Product $product Product instance.
|
||||||
*/
|
*/
|
||||||
public function low_stock( $product ) {
|
public function low_stock( $product ) {
|
||||||
if ( 'no' === get_option( 'woocommerce_notify_low_stock', 'yes' ) ) {
|
if ( 'no' === get_option( 'woocommerce_notify_low_stock', 'yes' ) ) {
|
||||||
|
@ -507,8 +563,8 @@ class WC_Emails {
|
||||||
}
|
}
|
||||||
|
|
||||||
$subject = sprintf( '[%s] %s', $this->get_blogname(), __( 'Product low in stock', 'woocommerce' ) );
|
$subject = sprintf( '[%s] %s', $this->get_blogname(), __( 'Product low in stock', 'woocommerce' ) );
|
||||||
/* translators: 1: product name 2: items in stock */
|
|
||||||
$message = sprintf(
|
$message = sprintf(
|
||||||
|
/* translators: 1: product name 2: items in stock */
|
||||||
__( '%1$s is low in stock. There are %2$d left.', 'woocommerce' ),
|
__( '%1$s is low in stock. There are %2$d left.', 'woocommerce' ),
|
||||||
html_entity_decode( strip_tags( $product->get_formatted_name() ), ENT_QUOTES, get_bloginfo( 'charset' ) ),
|
html_entity_decode( strip_tags( $product->get_formatted_name() ), ENT_QUOTES, get_bloginfo( 'charset' ) ),
|
||||||
html_entity_decode( strip_tags( $product->get_stock_quantity() ) )
|
html_entity_decode( strip_tags( $product->get_stock_quantity() ) )
|
||||||
|
@ -526,7 +582,7 @@ class WC_Emails {
|
||||||
/**
|
/**
|
||||||
* No stock notification email.
|
* No stock notification email.
|
||||||
*
|
*
|
||||||
* @param WC_Product $product
|
* @param WC_Product $product Product instance.
|
||||||
*/
|
*/
|
||||||
public function no_stock( $product ) {
|
public function no_stock( $product ) {
|
||||||
if ( 'no' === get_option( 'woocommerce_notify_no_stock', 'yes' ) ) {
|
if ( 'no' === get_option( 'woocommerce_notify_no_stock', 'yes' ) ) {
|
||||||
|
@ -549,14 +605,16 @@ class WC_Emails {
|
||||||
/**
|
/**
|
||||||
* Backorder notification email.
|
* Backorder notification email.
|
||||||
*
|
*
|
||||||
* @param array $args
|
* @param array $args Arguments.
|
||||||
*/
|
*/
|
||||||
public function backorder( $args ) {
|
public function backorder( $args ) {
|
||||||
$args = wp_parse_args( $args, array(
|
$args = wp_parse_args(
|
||||||
|
$args, array(
|
||||||
'product' => '',
|
'product' => '',
|
||||||
'quantity' => '',
|
'quantity' => '',
|
||||||
'order_id' => '',
|
'order_id' => '',
|
||||||
) );
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$order = wc_get_order( $args['order_id'] );
|
$order = wc_get_order( $args['order_id'] );
|
||||||
if (
|
if (
|
||||||
|
@ -569,6 +627,7 @@ class WC_Emails {
|
||||||
}
|
}
|
||||||
|
|
||||||
$subject = sprintf( '[%s] %s', $this->get_blogname(), __( 'Product backorder', 'woocommerce' ) );
|
$subject = sprintf( '[%s] %s', $this->get_blogname(), __( 'Product backorder', 'woocommerce' ) );
|
||||||
|
/* translators: 1: product quantity 2: product name 3: order number */
|
||||||
$message = sprintf( __( '%1$s units of %2$s have been backordered in order #%3$s.', 'woocommerce' ), $args['quantity'], html_entity_decode( strip_tags( $args['product']->get_formatted_name() ), ENT_QUOTES, get_bloginfo( 'charset' ) ), $order->get_order_number() );
|
$message = sprintf( __( '%1$s units of %2$s have been backordered in order #%3$s.', 'woocommerce' ), $args['quantity'], html_entity_decode( strip_tags( $args['product']->get_formatted_name() ), ENT_QUOTES, get_bloginfo( 'charset' ) ), $order->get_order_number() );
|
||||||
|
|
||||||
wp_mail(
|
wp_mail(
|
||||||
|
@ -587,9 +646,9 @@ class WC_Emails {
|
||||||
* @see WC_Structured_Data::generate_order_data()
|
* @see WC_Structured_Data::generate_order_data()
|
||||||
*
|
*
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
* @param mixed $order
|
* @param WC_Order $order Order instance.
|
||||||
* @param bool $sent_to_admin (default: false)
|
* @param bool $sent_to_admin If should sent to admin.
|
||||||
* @param bool $plain_text (default: false)
|
* @param bool $plain_text If is plain text email.
|
||||||
*/
|
*/
|
||||||
public function order_schema_markup( $order, $sent_to_admin = false, $plain_text = false ) {
|
public function order_schema_markup( $order, $sent_to_admin = false, $plain_text = false ) {
|
||||||
wc_deprecated_function( 'WC_Emails::order_schema_markup', '3.0', 'WC_Structured_Data::generate_order_data' );
|
wc_deprecated_function( 'WC_Emails::order_schema_markup', '3.0', 'WC_Structured_Data::generate_order_data' );
|
||||||
|
|
|
@ -2,11 +2,8 @@
|
||||||
/**
|
/**
|
||||||
* Handle frontend scripts
|
* Handle frontend scripts
|
||||||
*
|
*
|
||||||
* @class WC_Frontend_Scripts
|
* @package WooCommerce/Classes
|
||||||
* @version 2.3.0
|
* @version 2.3.0
|
||||||
* @package WooCommerce/Classes/
|
|
||||||
* @category Class
|
|
||||||
* @author WooThemes
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
@ -14,24 +11,27 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WC_Frontend_Scripts Class.
|
* Frontend scripts class.
|
||||||
*/
|
*/
|
||||||
class WC_Frontend_Scripts {
|
class WC_Frontend_Scripts {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains an array of script handles registered by WC.
|
* Contains an array of script handles registered by WC.
|
||||||
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private static $scripts = array();
|
private static $scripts = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains an array of script handles registered by WC.
|
* Contains an array of script handles registered by WC.
|
||||||
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private static $styles = array();
|
private static $styles = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains an array of script handles localized by WC.
|
* Contains an array of script handles localized by WC.
|
||||||
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private static $wp_localize_scripts = array();
|
private static $wp_localize_scripts = array();
|
||||||
|
@ -51,7 +51,8 @@ class WC_Frontend_Scripts {
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function get_styles() {
|
public static function get_styles() {
|
||||||
return apply_filters( 'woocommerce_enqueue_styles', array(
|
return apply_filters(
|
||||||
|
'woocommerce_enqueue_styles', array(
|
||||||
'woocommerce-layout' => array(
|
'woocommerce-layout' => array(
|
||||||
'src' => self::get_asset_url( 'assets/css/woocommerce-layout.css' ),
|
'src' => self::get_asset_url( 'assets/css/woocommerce-layout.css' ),
|
||||||
'deps' => '',
|
'deps' => '',
|
||||||
|
@ -63,7 +64,7 @@ class WC_Frontend_Scripts {
|
||||||
'src' => self::get_asset_url( 'assets/css/woocommerce-smallscreen.css' ),
|
'src' => self::get_asset_url( 'assets/css/woocommerce-smallscreen.css' ),
|
||||||
'deps' => 'woocommerce-layout',
|
'deps' => 'woocommerce-layout',
|
||||||
'version' => WC_VERSION,
|
'version' => WC_VERSION,
|
||||||
'media' => 'only screen and (max-width: ' . apply_filters( 'woocommerce_style_smallscreen_breakpoint', $breakpoint = '768px' ) . ')',
|
'media' => 'only screen and (max-width: ' . apply_filters( 'woocommerce_style_smallscreen_breakpoint', '768px' ) . ')',
|
||||||
'has_rtl' => true,
|
'has_rtl' => true,
|
||||||
),
|
),
|
||||||
'woocommerce-general' => array(
|
'woocommerce-general' => array(
|
||||||
|
@ -73,14 +74,14 @@ class WC_Frontend_Scripts {
|
||||||
'media' => 'all',
|
'media' => 'all',
|
||||||
'has_rtl' => true,
|
'has_rtl' => true,
|
||||||
),
|
),
|
||||||
) );
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return asset URL.
|
* Return asset URL.
|
||||||
*
|
*
|
||||||
* @param string $path
|
* @param string $path Assets path.
|
||||||
*
|
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private static function get_asset_url( $path ) {
|
private static function get_asset_url( $path ) {
|
||||||
|
@ -91,12 +92,11 @@ class WC_Frontend_Scripts {
|
||||||
* Register a script for use.
|
* Register a script for use.
|
||||||
*
|
*
|
||||||
* @uses wp_register_script()
|
* @uses wp_register_script()
|
||||||
* @access private
|
* @param string $handle Name of the script. Should be unique.
|
||||||
* @param string $handle
|
* @param string $path Full URL of the script, or path of the script relative to the WordPress root directory.
|
||||||
* @param string $path
|
* @param string[] $deps An array of registered script handles this script depends on.
|
||||||
* @param string[] $deps
|
* @param string $version String specifying script version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added.
|
||||||
* @param string $version
|
* @param boolean $in_footer Whether to enqueue the script before </body> instead of in the <head>. Default 'false'.
|
||||||
* @param boolean $in_footer
|
|
||||||
*/
|
*/
|
||||||
private static function register_script( $handle, $path, $deps = array( 'jquery' ), $version = WC_VERSION, $in_footer = true ) {
|
private static function register_script( $handle, $path, $deps = array( 'jquery' ), $version = WC_VERSION, $in_footer = true ) {
|
||||||
self::$scripts[] = $handle;
|
self::$scripts[] = $handle;
|
||||||
|
@ -107,15 +107,14 @@ class WC_Frontend_Scripts {
|
||||||
* Register and enqueue a script for use.
|
* Register and enqueue a script for use.
|
||||||
*
|
*
|
||||||
* @uses wp_enqueue_script()
|
* @uses wp_enqueue_script()
|
||||||
* @access private
|
* @param string $handle Name of the script. Should be unique.
|
||||||
* @param string $handle
|
* @param string $path Full URL of the script, or path of the script relative to the WordPress root directory.
|
||||||
* @param string $path
|
* @param string[] $deps An array of registered script handles this script depends on.
|
||||||
* @param string[] $deps
|
* @param string $version String specifying script version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added.
|
||||||
* @param string $version
|
* @param boolean $in_footer Whether to enqueue the script before </body> instead of in the <head>. Default 'false'.
|
||||||
* @param boolean $in_footer
|
|
||||||
*/
|
*/
|
||||||
private static function enqueue_script( $handle, $path = '', $deps = array( 'jquery' ), $version = WC_VERSION, $in_footer = true ) {
|
private static function enqueue_script( $handle, $path = '', $deps = array( 'jquery' ), $version = WC_VERSION, $in_footer = true ) {
|
||||||
if ( ! in_array( $handle, self::$scripts ) && $path ) {
|
if ( ! in_array( $handle, self::$scripts, true ) && $path ) {
|
||||||
self::register_script( $handle, $path, $deps, $version, $in_footer );
|
self::register_script( $handle, $path, $deps, $version, $in_footer );
|
||||||
}
|
}
|
||||||
wp_enqueue_script( $handle );
|
wp_enqueue_script( $handle );
|
||||||
|
@ -125,13 +124,12 @@ class WC_Frontend_Scripts {
|
||||||
* Register a style for use.
|
* Register a style for use.
|
||||||
*
|
*
|
||||||
* @uses wp_register_style()
|
* @uses wp_register_style()
|
||||||
* @access private
|
* @param string $handle Name of the stylesheet. Should be unique.
|
||||||
* @param string $handle
|
* @param string $path Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
|
||||||
* @param string $path
|
* @param string[] $deps An array of registered stylesheet handles this stylesheet depends on.
|
||||||
* @param string[] $deps
|
* @param string $version String specifying stylesheet version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added.
|
||||||
* @param string $version
|
* @param string $media The media for which this stylesheet has been defined. Accepts media types like 'all', 'print' and 'screen', or media queries like '(orientation: portrait)' and '(max-width: 640px)'.
|
||||||
* @param string $media
|
* @param boolean $has_rtl If has RTL version to load too.
|
||||||
* @param boolean $has_rtl
|
|
||||||
*/
|
*/
|
||||||
private static function register_style( $handle, $path, $deps = array(), $version = WC_VERSION, $media = 'all', $has_rtl = false ) {
|
private static function register_style( $handle, $path, $deps = array(), $version = WC_VERSION, $media = 'all', $has_rtl = false ) {
|
||||||
self::$styles[] = $handle;
|
self::$styles[] = $handle;
|
||||||
|
@ -146,16 +144,15 @@ class WC_Frontend_Scripts {
|
||||||
* Register and enqueue a styles for use.
|
* Register and enqueue a styles for use.
|
||||||
*
|
*
|
||||||
* @uses wp_enqueue_style()
|
* @uses wp_enqueue_style()
|
||||||
* @access private
|
* @param string $handle Name of the stylesheet. Should be unique.
|
||||||
* @param string $handle
|
* @param string $path Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
|
||||||
* @param string $path
|
* @param string[] $deps An array of registered stylesheet handles this stylesheet depends on.
|
||||||
* @param string[] $deps
|
* @param string $version String specifying stylesheet version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added.
|
||||||
* @param string $version
|
* @param string $media The media for which this stylesheet has been defined. Accepts media types like 'all', 'print' and 'screen', or media queries like '(orientation: portrait)' and '(max-width: 640px)'.
|
||||||
* @param string $media
|
* @param boolean $has_rtl If has RTL version to load too.
|
||||||
* @param boolean $has_rtl
|
|
||||||
*/
|
*/
|
||||||
private static function enqueue_style( $handle, $path = '', $deps = array(), $version = WC_VERSION, $media = 'all', $has_rtl = false ) {
|
private static function enqueue_style( $handle, $path = '', $deps = array(), $version = WC_VERSION, $media = 'all', $has_rtl = false ) {
|
||||||
if ( ! in_array( $handle, self::$styles ) && $path ) {
|
if ( ! in_array( $handle, self::$styles, true ) && $path ) {
|
||||||
self::register_style( $handle, $path, $deps, $version, $media, $has_rtl );
|
self::register_style( $handle, $path, $deps, $version, $media, $has_rtl );
|
||||||
}
|
}
|
||||||
wp_enqueue_style( $handle );
|
wp_enqueue_style( $handle );
|
||||||
|
@ -400,12 +397,13 @@ class WC_Frontend_Scripts {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Global frontend scripts
|
// Global frontend scripts.
|
||||||
self::enqueue_script( 'woocommerce' );
|
self::enqueue_script( 'woocommerce' );
|
||||||
self::enqueue_script( 'wc-cart-fragments' );
|
self::enqueue_script( 'wc-cart-fragments' );
|
||||||
|
|
||||||
// CSS Styles
|
// CSS Styles.
|
||||||
if ( $enqueue_styles = self::get_styles() ) {
|
$enqueue_styles = self::get_styles();
|
||||||
|
if ( $enqueue_styles ) {
|
||||||
foreach ( $enqueue_styles as $handle => $args ) {
|
foreach ( $enqueue_styles as $handle => $args ) {
|
||||||
if ( ! isset( $args['has_rtl'] ) ) {
|
if ( ! isset( $args['has_rtl'] ) ) {
|
||||||
$args['has_rtl'] = false;
|
$args['has_rtl'] = false;
|
||||||
|
@ -418,12 +416,18 @@ class WC_Frontend_Scripts {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Localize a WC script once.
|
* Localize a WC script once.
|
||||||
* @access private
|
*
|
||||||
* @since 2.3.0 this needs less wp_script_is() calls due to https://core.trac.wordpress.org/ticket/28404 being added in WP 4.0.
|
* @since 2.3.0 this needs less wp_script_is() calls due to https://core.trac.wordpress.org/ticket/28404 being added in WP 4.0.
|
||||||
* @param string $handle
|
* @param string $handle Script handle the data will be attached to.
|
||||||
*/
|
*/
|
||||||
private static function localize_script( $handle ) {
|
private static function localize_script( $handle ) {
|
||||||
if ( ! in_array( $handle, self::$wp_localize_scripts ) && wp_script_is( $handle ) && ( $data = self::get_script_data( $handle ) ) ) {
|
if ( ! in_array( $handle, self::$wp_localize_scripts, true ) && wp_script_is( $handle ) ) {
|
||||||
|
$data = self::get_script_data( $handle );
|
||||||
|
|
||||||
|
if ( ! $data ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$name = str_replace( '-', '_', $handle ) . '_params';
|
$name = str_replace( '-', '_', $handle ) . '_params';
|
||||||
self::$wp_localize_scripts[] = $handle;
|
self::$wp_localize_scripts[] = $handle;
|
||||||
wp_localize_script( $handle, $name, apply_filters( $name, $data ) );
|
wp_localize_script( $handle, $name, apply_filters( $name, $data ) );
|
||||||
|
@ -432,8 +436,8 @@ class WC_Frontend_Scripts {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return data for script handles.
|
* Return data for script handles.
|
||||||
* @access private
|
*
|
||||||
* @param string $handle
|
* @param string $handle Script handle the data will be attached to.
|
||||||
* @return array|bool
|
* @return array|bool
|
||||||
*/
|
*/
|
||||||
private static function get_script_data( $handle ) {
|
private static function get_script_data( $handle ) {
|
||||||
|
@ -443,22 +447,23 @@ class WC_Frontend_Scripts {
|
||||||
case 'woocommerce':
|
case 'woocommerce':
|
||||||
$params = array(
|
$params = array(
|
||||||
'ajax_url' => WC()->ajax_url(),
|
'ajax_url' => WC()->ajax_url(),
|
||||||
'wc_ajax_url' => WC_AJAX::get_endpoint( "%%endpoint%%" ),
|
'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case 'wc-geolocation':
|
case 'wc-geolocation':
|
||||||
$params = array(
|
$params = array(
|
||||||
'wc_ajax_url' => WC_AJAX::get_endpoint( "%%endpoint%%" ),
|
'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
|
||||||
'home_url' => home_url(),
|
'home_url' => home_url(),
|
||||||
'is_available' => ! ( is_cart() || is_account_page() || is_checkout() || is_customize_preview() ) ? '1' : '0',
|
'is_available' => ! ( is_cart() || is_account_page() || is_checkout() || is_customize_preview() ) ? '1' : '0',
|
||||||
'hash' => isset( $_GET['v'] ) ? wc_clean( $_GET['v'] ) : '',
|
'hash' => isset( $_GET['v'] ) ? wc_clean( wp_unslash( $_GET['v'] ) ) : '', // WPCS: input var ok, CSRF ok.
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case 'wc-single-product':
|
case 'wc-single-product':
|
||||||
$params = array(
|
$params = array(
|
||||||
'i18n_required_rating_text' => esc_attr__( 'Please select a rating', 'woocommerce' ),
|
'i18n_required_rating_text' => esc_attr__( 'Please select a rating', 'woocommerce' ),
|
||||||
'review_rating_required' => get_option( 'woocommerce_review_rating_required' ),
|
'review_rating_required' => get_option( 'woocommerce_review_rating_required' ),
|
||||||
'flexslider' => apply_filters( 'woocommerce_single_product_carousel_options', array(
|
'flexslider' => apply_filters(
|
||||||
|
'woocommerce_single_product_carousel_options', array(
|
||||||
'rtl' => is_rtl(),
|
'rtl' => is_rtl(),
|
||||||
'animation' => 'slide',
|
'animation' => 'slide',
|
||||||
'smoothHeight' => true,
|
'smoothHeight' => true,
|
||||||
|
@ -468,29 +473,32 @@ class WC_Frontend_Scripts {
|
||||||
'animationSpeed' => 500,
|
'animationSpeed' => 500,
|
||||||
'animationLoop' => false, // Breaks photoswipe pagination if true.
|
'animationLoop' => false, // Breaks photoswipe pagination if true.
|
||||||
'allowOneSlide' => false,
|
'allowOneSlide' => false,
|
||||||
) ),
|
)
|
||||||
|
),
|
||||||
'zoom_enabled' => apply_filters( 'woocommerce_single_product_zoom_enabled', get_theme_support( 'wc-product-gallery-zoom' ) ),
|
'zoom_enabled' => apply_filters( 'woocommerce_single_product_zoom_enabled', get_theme_support( 'wc-product-gallery-zoom' ) ),
|
||||||
'zoom_options' => apply_filters( 'woocommerce_single_product_zoom_options', array() ),
|
'zoom_options' => apply_filters( 'woocommerce_single_product_zoom_options', array() ),
|
||||||
'photoswipe_enabled' => apply_filters( 'woocommerce_single_product_photoswipe_enabled', get_theme_support( 'wc-product-gallery-lightbox' ) ),
|
'photoswipe_enabled' => apply_filters( 'woocommerce_single_product_photoswipe_enabled', get_theme_support( 'wc-product-gallery-lightbox' ) ),
|
||||||
'photoswipe_options' => apply_filters( 'woocommerce_single_product_photoswipe_options', array(
|
'photoswipe_options' => apply_filters(
|
||||||
|
'woocommerce_single_product_photoswipe_options', array(
|
||||||
'shareEl' => false,
|
'shareEl' => false,
|
||||||
'closeOnScroll' => false,
|
'closeOnScroll' => false,
|
||||||
'history' => false,
|
'history' => false,
|
||||||
'hideAnimationDuration' => 0,
|
'hideAnimationDuration' => 0,
|
||||||
'showAnimationDuration' => 0,
|
'showAnimationDuration' => 0,
|
||||||
) ),
|
)
|
||||||
|
),
|
||||||
'flexslider_enabled' => apply_filters( 'woocommerce_single_product_flexslider_enabled', get_theme_support( 'wc-product-gallery-slider' ) ),
|
'flexslider_enabled' => apply_filters( 'woocommerce_single_product_flexslider_enabled', get_theme_support( 'wc-product-gallery-slider' ) ),
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case 'wc-checkout':
|
case 'wc-checkout':
|
||||||
$params = array(
|
$params = array(
|
||||||
'ajax_url' => WC()->ajax_url(),
|
'ajax_url' => WC()->ajax_url(),
|
||||||
'wc_ajax_url' => WC_AJAX::get_endpoint( "%%endpoint%%" ),
|
'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
|
||||||
'update_order_review_nonce' => wp_create_nonce( 'update-order-review' ),
|
'update_order_review_nonce' => wp_create_nonce( 'update-order-review' ),
|
||||||
'apply_coupon_nonce' => wp_create_nonce( 'apply-coupon' ),
|
'apply_coupon_nonce' => wp_create_nonce( 'apply-coupon' ),
|
||||||
'remove_coupon_nonce' => wp_create_nonce( 'remove-coupon' ),
|
'remove_coupon_nonce' => wp_create_nonce( 'remove-coupon' ),
|
||||||
'option_guest_checkout' => get_option( 'woocommerce_enable_guest_checkout' ),
|
'option_guest_checkout' => get_option( 'woocommerce_enable_guest_checkout' ),
|
||||||
'checkout_url' => WC_AJAX::get_endpoint( "checkout" ),
|
'checkout_url' => WC_AJAX::get_endpoint( 'checkout' ),
|
||||||
'is_checkout' => is_page( wc_get_page_id( 'checkout' ) ) && empty( $wp->query_vars['order-pay'] ) && ! isset( $wp->query_vars['order-received'] ) ? 1 : 0,
|
'is_checkout' => is_page( wc_get_page_id( 'checkout' ) ) && empty( $wp->query_vars['order-pay'] ) && ! isset( $wp->query_vars['order-received'] ) ? 1 : 0,
|
||||||
'debug_mode' => defined( 'WP_DEBUG' ) && WP_DEBUG,
|
'debug_mode' => defined( 'WP_DEBUG' ) && WP_DEBUG,
|
||||||
'i18n_checkout_error' => esc_attr__( 'Error processing checkout. Please try again.', 'woocommerce' ),
|
'i18n_checkout_error' => esc_attr__( 'Error processing checkout. Please try again.', 'woocommerce' ),
|
||||||
|
@ -498,24 +506,24 @@ class WC_Frontend_Scripts {
|
||||||
break;
|
break;
|
||||||
case 'wc-address-i18n':
|
case 'wc-address-i18n':
|
||||||
$params = array(
|
$params = array(
|
||||||
'locale' => json_encode( WC()->countries->get_country_locale() ),
|
'locale' => wp_json_encode( WC()->countries->get_country_locale() ),
|
||||||
'locale_fields' => json_encode( WC()->countries->get_country_locale_field_selectors() ),
|
'locale_fields' => wp_json_encode( WC()->countries->get_country_locale_field_selectors() ),
|
||||||
'i18n_required_text' => esc_attr__( 'required', 'woocommerce' ),
|
'i18n_required_text' => esc_attr__( 'required', 'woocommerce' ),
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case 'wc-cart':
|
case 'wc-cart':
|
||||||
$params = array(
|
$params = array(
|
||||||
'ajax_url' => WC()->ajax_url(),
|
'ajax_url' => WC()->ajax_url(),
|
||||||
'wc_ajax_url' => WC_AJAX::get_endpoint( "%%endpoint%%" ),
|
'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
|
||||||
'update_shipping_method_nonce' => wp_create_nonce( "update-shipping-method" ),
|
'update_shipping_method_nonce' => wp_create_nonce( 'update-shipping-method' ),
|
||||||
'apply_coupon_nonce' => wp_create_nonce( "apply-coupon" ),
|
'apply_coupon_nonce' => wp_create_nonce( 'apply-coupon' ),
|
||||||
'remove_coupon_nonce' => wp_create_nonce( "remove-coupon" ),
|
'remove_coupon_nonce' => wp_create_nonce( 'remove-coupon' ),
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case 'wc-cart-fragments':
|
case 'wc-cart-fragments':
|
||||||
$params = array(
|
$params = array(
|
||||||
'ajax_url' => WC()->ajax_url(),
|
'ajax_url' => WC()->ajax_url(),
|
||||||
'wc_ajax_url' => WC_AJAX::get_endpoint( "%%endpoint%%" ),
|
'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
|
||||||
'cart_hash_key' => apply_filters( 'woocommerce_cart_hash_key', 'wc_cart_hash_' . md5( get_current_blog_id() . '_' . get_site_url( get_current_blog_id(), '/' ) ) ),
|
'cart_hash_key' => apply_filters( 'woocommerce_cart_hash_key', 'wc_cart_hash_' . md5( get_current_blog_id() . '_' . get_site_url( get_current_blog_id(), '/' ) ) ),
|
||||||
'fragment_name' => apply_filters( 'woocommerce_cart_fragment_name', 'wc_fragments_' . md5( get_current_blog_id() . '_' . get_site_url( get_current_blog_id(), '/' ) ) ),
|
'fragment_name' => apply_filters( 'woocommerce_cart_fragment_name', 'wc_fragments_' . md5( get_current_blog_id() . '_' . get_site_url( get_current_blog_id(), '/' ) ) ),
|
||||||
);
|
);
|
||||||
|
@ -523,7 +531,7 @@ class WC_Frontend_Scripts {
|
||||||
case 'wc-add-to-cart':
|
case 'wc-add-to-cart':
|
||||||
$params = array(
|
$params = array(
|
||||||
'ajax_url' => WC()->ajax_url(),
|
'ajax_url' => WC()->ajax_url(),
|
||||||
'wc_ajax_url' => WC_AJAX::get_endpoint( "%%endpoint%%" ),
|
'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
|
||||||
'i18n_view_cart' => esc_attr__( 'View cart', 'woocommerce' ),
|
'i18n_view_cart' => esc_attr__( 'View cart', 'woocommerce' ),
|
||||||
'cart_url' => apply_filters( 'woocommerce_add_to_cart_redirect', wc_get_cart_url() ),
|
'cart_url' => apply_filters( 'woocommerce_add_to_cart_redirect', wc_get_cart_url() ),
|
||||||
'is_cart' => is_cart(),
|
'is_cart' => is_cart(),
|
||||||
|
@ -531,11 +539,11 @@ class WC_Frontend_Scripts {
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case 'wc-add-to-cart-variation':
|
case 'wc-add-to-cart-variation':
|
||||||
// We also need the wp.template for this script :)
|
// We also need the wp.template for this script :).
|
||||||
wc_get_template( 'single-product/add-to-cart/variation.php' );
|
wc_get_template( 'single-product/add-to-cart/variation.php' );
|
||||||
|
|
||||||
$params = array(
|
$params = array(
|
||||||
'wc_ajax_url' => WC_AJAX::get_endpoint( "%%endpoint%%" ),
|
'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
|
||||||
'i18n_no_matching_variations_text' => esc_attr__( 'Sorry, no products matched your selection. Please choose a different combination.', 'woocommerce' ),
|
'i18n_no_matching_variations_text' => esc_attr__( 'Sorry, no products matched your selection. Please choose a different combination.', 'woocommerce' ),
|
||||||
'i18n_make_a_selection_text' => esc_attr__( 'Please select some product options before adding this product to your cart.', 'woocommerce' ),
|
'i18n_make_a_selection_text' => esc_attr__( 'Please select some product options before adding this product to your cart.', 'woocommerce' ),
|
||||||
'i18n_unavailable_text' => esc_attr__( 'Sorry, this product is unavailable. Please choose a different combination.', 'woocommerce' ),
|
'i18n_unavailable_text' => esc_attr__( 'Sorry, this product is unavailable. Please choose a different combination.', 'woocommerce' ),
|
||||||
|
@ -543,7 +551,7 @@ class WC_Frontend_Scripts {
|
||||||
break;
|
break;
|
||||||
case 'wc-country-select':
|
case 'wc-country-select':
|
||||||
$params = array(
|
$params = array(
|
||||||
'countries' => json_encode( array_merge( WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states() ) ),
|
'countries' => wp_json_encode( array_merge( WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states() ) ),
|
||||||
'i18n_select_state_text' => esc_attr__( 'Select an option…', 'woocommerce' ),
|
'i18n_select_state_text' => esc_attr__( 'Select an option…', 'woocommerce' ),
|
||||||
'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'woocommerce' ),
|
'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'woocommerce' ),
|
||||||
'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'woocommerce' ),
|
'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'woocommerce' ),
|
||||||
|
|
|
@ -1,28 +1,32 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
|
||||||
exit; // Exit if accessed directly
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WooCommerce Payment Gateways class
|
* WooCommerce Payment Gateways
|
||||||
*
|
*
|
||||||
* Loads payment gateways via hooks for use in the store.
|
* Loads payment gateways via hooks for use in the store.
|
||||||
*
|
*
|
||||||
* @class WC_Payment_Gateways
|
|
||||||
* @version 2.2.0
|
* @version 2.2.0
|
||||||
* @package WooCommerce/Classes/Payment
|
* @package WooCommerce/Classes/Payment
|
||||||
* @category Class
|
*/
|
||||||
* @author WooThemes
|
|
||||||
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Payment gateways class.
|
||||||
*/
|
*/
|
||||||
class WC_Payment_Gateways {
|
class WC_Payment_Gateways {
|
||||||
|
|
||||||
/** @var array Array of payment gateway classes. */
|
/**
|
||||||
public $payment_gateways;
|
* Payment gateway classes.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $payment_gateways = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var WC_Payment_Gateways The single instance of the class
|
* The single instance of the class.
|
||||||
* @since 2.1
|
*
|
||||||
|
* @var WC_Payment_Gateways
|
||||||
|
* @since 2.1.0
|
||||||
*/
|
*/
|
||||||
protected static $_instance = null;
|
protected static $_instance = null;
|
||||||
|
|
||||||
|
@ -32,7 +36,6 @@ class WC_Payment_Gateways {
|
||||||
* Ensures only one instance of WC_Payment_Gateways is loaded or can be loaded.
|
* Ensures only one instance of WC_Payment_Gateways is loaded or can be loaded.
|
||||||
*
|
*
|
||||||
* @since 2.1
|
* @since 2.1
|
||||||
* @static
|
|
||||||
* @return WC_Payment_Gateways Main instance
|
* @return WC_Payment_Gateways Main instance
|
||||||
*/
|
*/
|
||||||
public static function instance() {
|
public static function instance() {
|
||||||
|
@ -81,7 +84,7 @@ class WC_Payment_Gateways {
|
||||||
/**
|
/**
|
||||||
* Simplify Commerce is @deprecated in 2.6.0. Only load when enabled.
|
* Simplify Commerce is @deprecated in 2.6.0. Only load when enabled.
|
||||||
*/
|
*/
|
||||||
if ( ! class_exists( 'WC_Gateway_Simplify_Commerce_Loader' ) && in_array( WC()->countries->get_base_country(), apply_filters( 'woocommerce_gateway_simplify_commerce_supported_countries', array( 'US', 'IE' ) ) ) ) {
|
if ( ! class_exists( 'WC_Gateway_Simplify_Commerce_Loader' ) && in_array( WC()->countries->get_base_country(), apply_filters( 'woocommerce_gateway_simplify_commerce_supported_countries', array( 'US', 'IE' ) ), true ) ) {
|
||||||
$simplify_options = get_option( 'woocommerce_simplify_commerce_settings', array() );
|
$simplify_options = get_option( 'woocommerce_simplify_commerce_settings', array() );
|
||||||
|
|
||||||
if ( ! empty( $simplify_options['enabled'] ) && 'yes' === $simplify_options['enabled'] ) {
|
if ( ! empty( $simplify_options['enabled'] ) && 'yes' === $simplify_options['enabled'] ) {
|
||||||
|
@ -93,22 +96,22 @@ class WC_Payment_Gateways {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter
|
// Filter.
|
||||||
$load_gateways = apply_filters( 'woocommerce_payment_gateways', $load_gateways );
|
$load_gateways = apply_filters( 'woocommerce_payment_gateways', $load_gateways );
|
||||||
|
|
||||||
// Get sort order option
|
// Get sort order option.
|
||||||
$ordering = (array) get_option( 'woocommerce_gateway_order' );
|
$ordering = (array) get_option( 'woocommerce_gateway_order' );
|
||||||
$order_end = 999;
|
$order_end = 999;
|
||||||
|
|
||||||
// Load gateways in order
|
// Load gateways in order.
|
||||||
foreach ( $load_gateways as $gateway ) {
|
foreach ( $load_gateways as $gateway ) {
|
||||||
$load_gateway = is_string( $gateway ) ? new $gateway() : $gateway;
|
$load_gateway = is_string( $gateway ) ? new $gateway() : $gateway;
|
||||||
|
|
||||||
if ( isset( $ordering[ $load_gateway->id ] ) && is_numeric( $ordering[ $load_gateway->id ] ) ) {
|
if ( isset( $ordering[ $load_gateway->id ] ) && is_numeric( $ordering[ $load_gateway->id ] ) ) {
|
||||||
// Add in position
|
// Add in position.
|
||||||
$this->payment_gateways[ $ordering[ $load_gateway->id ] ] = $load_gateway;
|
$this->payment_gateways[ $ordering[ $load_gateway->id ] ] = $load_gateway;
|
||||||
} else {
|
} else {
|
||||||
// Add to end of the array
|
// Add to end of the array.
|
||||||
$this->payment_gateways[ $order_end ] = $load_gateway;
|
$this->payment_gateways[ $order_end ] = $load_gateway;
|
||||||
$order_end++;
|
$order_end++;
|
||||||
}
|
}
|
||||||
|
@ -119,12 +122,13 @@ class WC_Payment_Gateways {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get gateways.
|
* Get gateways.
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function payment_gateways() {
|
public function payment_gateways() {
|
||||||
$_available_gateways = array();
|
$_available_gateways = array();
|
||||||
|
|
||||||
if ( sizeof( $this->payment_gateways ) > 0 ) {
|
if ( count( $this->payment_gateways ) > 0 ) {
|
||||||
foreach ( $this->payment_gateways as $gateway ) {
|
foreach ( $this->payment_gateways as $gateway ) {
|
||||||
$_available_gateways[ $gateway->id ] = $gateway;
|
$_available_gateways[ $gateway->id ] = $gateway;
|
||||||
}
|
}
|
||||||
|
@ -135,6 +139,7 @@ class WC_Payment_Gateways {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get array of registered gateway ids
|
* Get array of registered gateway ids
|
||||||
|
*
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
* @return array of strings
|
* @return array of strings
|
||||||
*/
|
*/
|
||||||
|
@ -169,7 +174,7 @@ class WC_Payment_Gateways {
|
||||||
* @param array $gateways Available payment gateways.
|
* @param array $gateways Available payment gateways.
|
||||||
*/
|
*/
|
||||||
public function set_current_gateway( $gateways ) {
|
public function set_current_gateway( $gateways ) {
|
||||||
// Be on the defensive
|
// Be on the defensive.
|
||||||
if ( ! is_array( $gateways ) || empty( $gateways ) ) {
|
if ( ! is_array( $gateways ) || empty( $gateways ) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -190,7 +195,7 @@ class WC_Payment_Gateways {
|
||||||
$current_gateway = current( $gateways );
|
$current_gateway = current( $gateways );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure we can make a call to set_current() without triggering an error
|
// Ensure we can make a call to set_current() without triggering an error.
|
||||||
if ( $current_gateway && is_callable( array( $current_gateway, 'set_current' ) ) ) {
|
if ( $current_gateway && is_callable( array( $current_gateway, 'set_current' ) ) ) {
|
||||||
$current_gateway->set_current();
|
$current_gateway->set_current();
|
||||||
}
|
}
|
||||||
|
@ -200,10 +205,10 @@ class WC_Payment_Gateways {
|
||||||
* Save options in admin.
|
* Save options in admin.
|
||||||
*/
|
*/
|
||||||
public function process_admin_options() {
|
public function process_admin_options() {
|
||||||
$gateway_order = isset( $_POST['gateway_order'] ) ? $_POST['gateway_order'] : '';
|
$gateway_order = isset( $_POST['gateway_order'] ) ? wc_clean( wp_unslash( $_POST['gateway_order'] ) ) : ''; // WPCS: input var ok, CSRF ok.
|
||||||
$order = array();
|
$order = array();
|
||||||
|
|
||||||
if ( is_array( $gateway_order ) && sizeof( $gateway_order ) > 0 ) {
|
if ( is_array( $gateway_order ) && count( $gateway_order ) > 0 ) {
|
||||||
$loop = 0;
|
$loop = 0;
|
||||||
foreach ( $gateway_order as $gateway_id ) {
|
foreach ( $gateway_order as $gateway_id ) {
|
||||||
$order[ esc_attr( $gateway_id ) ] = $loop;
|
$order[ esc_attr( $gateway_id ) ] = $loop;
|
||||||
|
|
|
@ -1,19 +1,18 @@
|
||||||
<?php
|
<?php
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WooCommerce Payment Tokens.
|
* WooCommerce Payment Tokens
|
||||||
*
|
*
|
||||||
* An API for storing and managing tokens for gateways and customers.
|
* An API for storing and managing tokens for gateways and customers.
|
||||||
*
|
*
|
||||||
* @class WC_Payment_Tokens
|
* @package WooCommerce/Classes
|
||||||
* @version 3.0.0
|
* @version 3.0.0
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
* @package WooCommerce/Classes
|
*/
|
||||||
* @category Class
|
|
||||||
* @author WooThemes
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Payment tokens class.
|
||||||
*/
|
*/
|
||||||
class WC_Payment_Tokens {
|
class WC_Payment_Tokens {
|
||||||
|
|
||||||
|
@ -21,16 +20,25 @@ class WC_Payment_Tokens {
|
||||||
* Gets valid tokens from the database based on user defined criteria.
|
* Gets valid tokens from the database based on user defined criteria.
|
||||||
*
|
*
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
* @param array $args
|
* @param array $args Query argyments {
|
||||||
|
* Array of query parameters.
|
||||||
|
*
|
||||||
|
* @type string $token_id Token ID.
|
||||||
|
* @type string $user_id User ID.
|
||||||
|
* @type string $gateway_id Gateway ID.
|
||||||
|
* @type string $type Token type.
|
||||||
|
* }
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function get_tokens( $args ) {
|
public static function get_tokens( $args ) {
|
||||||
$args = wp_parse_args( $args, array(
|
$args = wp_parse_args(
|
||||||
|
$args, array(
|
||||||
'token_id' => '',
|
'token_id' => '',
|
||||||
'user_id' => '',
|
'user_id' => '',
|
||||||
'gateway_id' => '',
|
'gateway_id' => '',
|
||||||
'type' => '',
|
'type' => '',
|
||||||
) );
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$data_store = WC_Data_Store::load( 'payment-token' );
|
$data_store = WC_Data_Store::load( 'payment-token' );
|
||||||
$token_results = $data_store->get_tokens( $args );
|
$token_results = $data_store->get_tokens( $args );
|
||||||
|
@ -52,19 +60,21 @@ class WC_Payment_Tokens {
|
||||||
* Returns an array of payment token objects associated with the passed customer ID.
|
* Returns an array of payment token objects associated with the passed customer ID.
|
||||||
*
|
*
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
* @param int $customer_id Customer ID
|
* @param int $customer_id Customer ID.
|
||||||
* @param string $gateway_id Optional Gateway ID for getting tokens for a specific gateway
|
* @param string $gateway_id Optional Gateway ID for getting tokens for a specific gateway.
|
||||||
* @return array Array of token objects
|
* @return array Array of token objects.
|
||||||
*/
|
*/
|
||||||
public static function get_customer_tokens( $customer_id, $gateway_id = '' ) {
|
public static function get_customer_tokens( $customer_id, $gateway_id = '' ) {
|
||||||
if ( $customer_id < 1 ) {
|
if ( $customer_id < 1 ) {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
$tokens = self::get_tokens( array(
|
$tokens = self::get_tokens(
|
||||||
|
array(
|
||||||
'user_id' => $customer_id,
|
'user_id' => $customer_id,
|
||||||
'gateway_id' => $gateway_id,
|
'gateway_id' => $gateway_id,
|
||||||
) );
|
)
|
||||||
|
);
|
||||||
|
|
||||||
return apply_filters( 'woocommerce_get_customer_payment_tokens', $tokens, $customer_id, $gateway_id );
|
return apply_filters( 'woocommerce_get_customer_payment_tokens', $tokens, $customer_id, $gateway_id );
|
||||||
}
|
}
|
||||||
|
@ -73,7 +83,7 @@ class WC_Payment_Tokens {
|
||||||
* Returns a customers default token or NULL if there is no default token.
|
* Returns a customers default token or NULL if there is no default token.
|
||||||
*
|
*
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
* @param int $customer_id
|
* @param int $customer_id Customer ID.
|
||||||
* @return WC_Payment_Token|null
|
* @return WC_Payment_Token|null
|
||||||
*/
|
*/
|
||||||
public static function get_customer_default_token( $customer_id ) {
|
public static function get_customer_default_token( $customer_id ) {
|
||||||
|
@ -95,8 +105,8 @@ class WC_Payment_Tokens {
|
||||||
* Returns an array of payment token objects associated with the passed order ID.
|
* Returns an array of payment token objects associated with the passed order ID.
|
||||||
*
|
*
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
* @param int $order_id Order ID
|
* @param int $order_id Order ID.
|
||||||
* @return array Array of token objects
|
* @return array Array of token objects.
|
||||||
*/
|
*/
|
||||||
public static function get_order_tokens( $order_id ) {
|
public static function get_order_tokens( $order_id ) {
|
||||||
$order = wc_get_order( $order_id );
|
$order = wc_get_order( $order_id );
|
||||||
|
@ -111,9 +121,11 @@ class WC_Payment_Tokens {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
$tokens = self::get_tokens( array(
|
$tokens = self::get_tokens(
|
||||||
|
array(
|
||||||
'token_id' => $token_ids,
|
'token_id' => $token_ids,
|
||||||
) );
|
)
|
||||||
|
);
|
||||||
|
|
||||||
return apply_filters( 'woocommerce_get_order_payment_tokens', $tokens, $order_id );
|
return apply_filters( 'woocommerce_get_order_payment_tokens', $tokens, $order_id );
|
||||||
}
|
}
|
||||||
|
@ -123,17 +135,16 @@ class WC_Payment_Tokens {
|
||||||
*
|
*
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
*
|
*
|
||||||
* @param int $token_id Token ID
|
* @param int $token_id Token ID.
|
||||||
* @param object $token_result
|
* @param object $token_result Token result.
|
||||||
*
|
* @return null|WC_Payment_Token Returns a valid payment token or null if no token can be found.
|
||||||
* @return null|WC_Payment_Token Returns a valid payment token or null if no token can be found
|
|
||||||
*/
|
*/
|
||||||
public static function get( $token_id, $token_result = null ) {
|
public static function get( $token_id, $token_result = null ) {
|
||||||
$data_store = WC_Data_Store::load( 'payment-token' );
|
$data_store = WC_Data_Store::load( 'payment-token' );
|
||||||
|
|
||||||
if ( is_null( $token_result ) ) {
|
if ( is_null( $token_result ) ) {
|
||||||
$token_result = $data_store->get_token_by_id( $token_id );
|
$token_result = $data_store->get_token_by_id( $token_id );
|
||||||
// Still empty? Token doesn't exist? Don't continue
|
// Still empty? Token doesn't exist? Don't continue.
|
||||||
if ( empty( $token_result ) ) {
|
if ( empty( $token_result ) ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -157,8 +168,9 @@ class WC_Payment_Tokens {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a payment token from the database by ID.
|
* Remove a payment token from the database by ID.
|
||||||
|
*
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
* @param WC_Payment_Token $token_id Token ID
|
* @param WC_Payment_Token $token_id Token ID.
|
||||||
*/
|
*/
|
||||||
public static function delete( $token_id ) {
|
public static function delete( $token_id ) {
|
||||||
$type = self::get_token_type_by_id( $token_id );
|
$type = self::get_token_type_by_id( $token_id );
|
||||||
|
@ -173,8 +185,8 @@ class WC_Payment_Tokens {
|
||||||
* Loops through all of a users payment tokens and sets is_default to false for all but a specific token.
|
* Loops through all of a users payment tokens and sets is_default to false for all but a specific token.
|
||||||
*
|
*
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
* @param int $user_id User to set a default for
|
* @param int $user_id User to set a default for.
|
||||||
* @param int $token_id The ID of the token that should be default
|
* @param int $token_id The ID of the token that should be default.
|
||||||
*/
|
*/
|
||||||
public static function set_users_default( $user_id, $token_id ) {
|
public static function set_users_default( $user_id, $token_id ) {
|
||||||
$data_store = WC_Data_Store::load( 'payment-token' );
|
$data_store = WC_Data_Store::load( 'payment-token' );
|
||||||
|
@ -193,8 +205,8 @@ class WC_Payment_Tokens {
|
||||||
* Returns what type (credit card, echeck, etc) of token a token is by ID.
|
* Returns what type (credit card, echeck, etc) of token a token is by ID.
|
||||||
*
|
*
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
* @param int $token_id Token ID
|
* @param int $token_id Token ID.
|
||||||
* @return string Type
|
* @return string Type.
|
||||||
*/
|
*/
|
||||||
public static function get_token_type_by_id( $token_id ) {
|
public static function get_token_type_by_id( $token_id ) {
|
||||||
$data_store = WC_Data_Store::load( 'payment-token' );
|
$data_store = WC_Data_Store::load( 'payment-token' );
|
||||||
|
|
|
@ -1,19 +1,17 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
|
||||||
exit; // Exit if accessed directly
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Post Data.
|
* Post Data
|
||||||
*
|
*
|
||||||
* Standardises certain post data on save.
|
* Standardises certain post data on save.
|
||||||
*
|
*
|
||||||
* @class WC_Post_Data
|
|
||||||
* @version 2.2.0
|
|
||||||
* @package WooCommerce/Classes/Data
|
* @package WooCommerce/Classes/Data
|
||||||
* @category Class
|
* @version 2.2.0
|
||||||
* @author WooThemes
|
*/
|
||||||
|
|
||||||
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post data class.
|
||||||
*/
|
*/
|
||||||
class WC_Post_Data {
|
class WC_Post_Data {
|
||||||
|
|
||||||
|
@ -45,7 +43,7 @@ class WC_Post_Data {
|
||||||
add_filter( 'wp_insert_post_data', array( __CLASS__, 'wp_insert_post_data' ) );
|
add_filter( 'wp_insert_post_data', array( __CLASS__, 'wp_insert_post_data' ) );
|
||||||
add_filter( 'oembed_response_data', array( __CLASS__, 'filter_oembed_response_data' ), 10, 2 );
|
add_filter( 'oembed_response_data', array( __CLASS__, 'filter_oembed_response_data' ), 10, 2 );
|
||||||
|
|
||||||
// Status transitions
|
// Status transitions.
|
||||||
add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
|
add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
|
||||||
add_action( 'wp_trash_post', array( __CLASS__, 'trash_post' ) );
|
add_action( 'wp_trash_post', array( __CLASS__, 'trash_post' ) );
|
||||||
add_action( 'untrashed_post', array( __CLASS__, 'untrash_post' ) );
|
add_action( 'untrashed_post', array( __CLASS__, 'untrash_post' ) );
|
||||||
|
@ -59,15 +57,19 @@ class WC_Post_Data {
|
||||||
/**
|
/**
|
||||||
* Link to parent products when getting permalink for variation.
|
* Link to parent products when getting permalink for variation.
|
||||||
*
|
*
|
||||||
* @param string $permalink
|
* @param string $permalink Permalink.
|
||||||
* @param object $post
|
* @param WP_Post $post Post data.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function variation_post_link( $permalink, $post ) {
|
public static function variation_post_link( $permalink, $post ) {
|
||||||
if ( isset( $post->ID, $post->post_type ) && 'product_variation' === $post->post_type && ( $variation = wc_get_product( $post->ID ) ) && $variation->get_parent_id() ) {
|
if ( isset( $post->ID, $post->post_type ) && 'product_variation' === $post->post_type ) {
|
||||||
|
$variation = wc_get_product( $post->ID );
|
||||||
|
|
||||||
|
if ( $variation && $variation->get_parent_id() ) {
|
||||||
return $variation->get_permalink();
|
return $variation->get_permalink();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return $permalink;
|
return $permalink;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +87,8 @@ class WC_Post_Data {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sync a product.
|
* Sync a product.
|
||||||
* @param int $product_id
|
*
|
||||||
|
* @param int $product_id Product ID.
|
||||||
*/
|
*/
|
||||||
public static function deferred_product_sync( $product_id ) {
|
public static function deferred_product_sync( $product_id ) {
|
||||||
$product = wc_get_product( $product_id );
|
$product = wc_get_product( $product_id );
|
||||||
|
@ -98,18 +101,18 @@ class WC_Post_Data {
|
||||||
/**
|
/**
|
||||||
* Delete transients when terms are set.
|
* Delete transients when terms are set.
|
||||||
*
|
*
|
||||||
* @param int $object_id
|
* @param int $object_id Object ID.
|
||||||
* @param mixed $terms
|
* @param mixed $terms An array of object terms.
|
||||||
* @param array $tt_ids
|
* @param array $tt_ids An array of term taxonomy IDs.
|
||||||
* @param string $taxonomy
|
* @param string $taxonomy Taxonomy slug.
|
||||||
* @param mixed $append
|
* @param mixed $append Whether to append new terms to the old terms.
|
||||||
* @param array $old_tt_ids
|
* @param array $old_tt_ids Old array of term taxonomy IDs.
|
||||||
*/
|
*/
|
||||||
public static function set_object_terms( $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids ) {
|
public static function set_object_terms( $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids ) {
|
||||||
foreach ( array_merge( $tt_ids, $old_tt_ids ) as $id ) {
|
foreach ( array_merge( $tt_ids, $old_tt_ids ) as $id ) {
|
||||||
delete_transient( 'wc_ln_count_' . md5( sanitize_key( $taxonomy ) . sanitize_key( $id ) ) );
|
delete_transient( 'wc_ln_count_' . md5( sanitize_key( $taxonomy ) . sanitize_key( $id ) ) );
|
||||||
}
|
}
|
||||||
if ( in_array( get_post_type( $object_id ), array( 'product', 'product_variation' ) ) ) {
|
if ( in_array( get_post_type( $object_id ), array( 'product', 'product_variation' ), true ) ) {
|
||||||
self::delete_product_query_transients();
|
self::delete_product_query_transients();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,12 +120,12 @@ class WC_Post_Data {
|
||||||
/**
|
/**
|
||||||
* When a post status changes.
|
* When a post status changes.
|
||||||
*
|
*
|
||||||
* @param string $new_status
|
* @param string $new_status New status.
|
||||||
* @param string $old_status
|
* @param string $old_status Old status.
|
||||||
* @param object $post
|
* @param WP_Post $post Post data.
|
||||||
*/
|
*/
|
||||||
public static function transition_post_status( $new_status, $old_status, $post ) {
|
public static function transition_post_status( $new_status, $old_status, $post ) {
|
||||||
if ( ( 'publish' === $new_status || 'publish' === $old_status ) && in_array( $post->post_type, array( 'product', 'product_variation' ) ) ) {
|
if ( ( 'publish' === $new_status || 'publish' === $old_status ) && in_array( $post->post_type, array( 'product', 'product_variation' ), true ) ) {
|
||||||
self::delete_product_query_transients();
|
self::delete_product_query_transients();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,20 +134,22 @@ class WC_Post_Data {
|
||||||
* Delete product view transients when needed e.g. when post status changes, or visibility/stock status is modified.
|
* Delete product view transients when needed e.g. when post status changes, or visibility/stock status is modified.
|
||||||
*/
|
*/
|
||||||
public static function delete_product_query_transients() {
|
public static function delete_product_query_transients() {
|
||||||
// Increments the transient version to invalidate cache
|
// Increments the transient version to invalidate cache.
|
||||||
WC_Cache_Helper::get_transient_version( 'product_query', true );
|
WC_Cache_Helper::get_transient_version( 'product_query', true );
|
||||||
|
|
||||||
// If not using an external caching system, we can clear the transients out manually and avoid filling our DB
|
// If not using an external caching system, we can clear the transients out manually and avoid filling our DB.
|
||||||
if ( ! wp_using_ext_object_cache() ) {
|
if ( ! wp_using_ext_object_cache() ) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
$wpdb->query( "
|
$wpdb->query(
|
||||||
|
"
|
||||||
DELETE FROM `$wpdb->options`
|
DELETE FROM `$wpdb->options`
|
||||||
WHERE `option_name` LIKE ('\_transient\_wc\_uf\_pid\_%')
|
WHERE `option_name` LIKE ('\_transient\_wc\_uf\_pid\_%')
|
||||||
OR `option_name` LIKE ('\_transient\_timeout\_wc\_uf\_pid\_%')
|
OR `option_name` LIKE ('\_transient\_timeout\_wc\_uf\_pid\_%')
|
||||||
OR `option_name` LIKE ('\_transient\_wc\_products\_will\_display\_%')
|
OR `option_name` LIKE ('\_transient\_wc\_products\_will\_display\_%')
|
||||||
OR `option_name` LIKE ('\_transient\_timeout\_wc\_products\_will\_display\_%')
|
OR `option_name` LIKE ('\_transient\_timeout\_wc\_products\_will\_display\_%')
|
||||||
" );
|
"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,9 +157,9 @@ class WC_Post_Data {
|
||||||
* Handle type changes.
|
* Handle type changes.
|
||||||
*
|
*
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
* @param WC_Product $product
|
* @param WC_Product $product Product data.
|
||||||
* @param string $from
|
* @param string $from Origin type.
|
||||||
* @param string $to
|
* @param string $to New type.
|
||||||
*/
|
*/
|
||||||
public static function product_type_changed( $product, $from, $to ) {
|
public static function product_type_changed( $product, $from, $to ) {
|
||||||
if ( 'variable' === $from && 'variable' !== $to ) {
|
if ( 'variable' === $from && 'variable' !== $to ) {
|
||||||
|
@ -166,9 +171,10 @@ class WC_Post_Data {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When editing a term, check for product attributes.
|
* When editing a term, check for product attributes.
|
||||||
* @param id $term_id
|
*
|
||||||
* @param id $tt_id
|
* @param int $term_id Term ID.
|
||||||
* @param string $taxonomy
|
* @param int $tt_id Term taxonomy ID.
|
||||||
|
* @param string $taxonomy Taxonomy slug.
|
||||||
*/
|
*/
|
||||||
public static function edit_term( $term_id, $tt_id, $taxonomy ) {
|
public static function edit_term( $term_id, $tt_id, $taxonomy ) {
|
||||||
if ( strpos( $taxonomy, 'pa_' ) === 0 ) {
|
if ( strpos( $taxonomy, 'pa_' ) === 0 ) {
|
||||||
|
@ -180,9 +186,10 @@ class WC_Post_Data {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When a term is edited, check for product attributes and update variations.
|
* When a term is edited, check for product attributes and update variations.
|
||||||
* @param id $term_id
|
*
|
||||||
* @param id $tt_id
|
* @param int $term_id Term ID.
|
||||||
* @param string $taxonomy
|
* @param int $tt_id Term taxonomy ID.
|
||||||
|
* @param string $taxonomy Taxonomy slug.
|
||||||
*/
|
*/
|
||||||
public static function edited_term( $term_id, $tt_id, $taxonomy ) {
|
public static function edited_term( $term_id, $tt_id, $taxonomy ) {
|
||||||
if ( ! is_null( self::$editing_term ) && strpos( $taxonomy, 'pa_' ) === 0 ) {
|
if ( ! is_null( self::$editing_term ) && strpos( $taxonomy, 'pa_' ) === 0 ) {
|
||||||
|
@ -201,23 +208,22 @@ class WC_Post_Data {
|
||||||
/**
|
/**
|
||||||
* Ensure floats are correctly converted to strings based on PHP locale.
|
* Ensure floats are correctly converted to strings based on PHP locale.
|
||||||
*
|
*
|
||||||
* @param null $check
|
* @param null $check Whether to allow updating metadata for the given type.
|
||||||
* @param int $object_id
|
* @param int $object_id Object ID.
|
||||||
* @param string $meta_key
|
* @param string $meta_key Meta key.
|
||||||
* @param mixed $meta_value
|
* @param mixed $meta_value Meta value. Must be serializable if non-scalar.
|
||||||
* @param mixed $prev_value
|
* @param mixed $prev_value If specified, only update existing metadata entries with the specified value. Otherwise, update all entries.
|
||||||
* @return null|bool
|
* @return null|bool
|
||||||
*/
|
*/
|
||||||
public static function update_order_item_metadata( $check, $object_id, $meta_key, $meta_value, $prev_value ) {
|
public static function update_order_item_metadata( $check, $object_id, $meta_key, $meta_value, $prev_value ) {
|
||||||
if ( ! empty( $meta_value ) && is_float( $meta_value ) ) {
|
if ( ! empty( $meta_value ) && is_float( $meta_value ) ) {
|
||||||
|
|
||||||
// Convert float to string
|
// Convert float to string.
|
||||||
$meta_value = wc_float_to_string( $meta_value );
|
$meta_value = wc_float_to_string( $meta_value );
|
||||||
|
|
||||||
// Update meta value with new string
|
// Update meta value with new string.
|
||||||
update_metadata( 'order_item', $object_id, $meta_key, $meta_value, $prev_value );
|
update_metadata( 'order_item', $object_id, $meta_key, $meta_value, $prev_value );
|
||||||
|
|
||||||
// Return
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return $check;
|
return $check;
|
||||||
|
@ -226,28 +232,27 @@ class WC_Post_Data {
|
||||||
/**
|
/**
|
||||||
* Ensure floats are correctly converted to strings based on PHP locale.
|
* Ensure floats are correctly converted to strings based on PHP locale.
|
||||||
*
|
*
|
||||||
* @param null $check
|
* @param null $check Whether to allow updating metadata for the given type.
|
||||||
* @param int $object_id
|
* @param int $object_id Object ID.
|
||||||
* @param string $meta_key
|
* @param string $meta_key Meta key.
|
||||||
* @param mixed $meta_value
|
* @param mixed $meta_value Meta value. Must be serializable if non-scalar.
|
||||||
* @param mixed $prev_value
|
* @param mixed $prev_value If specified, only update existing metadata entries with the specified value. Otherwise, update all entries.
|
||||||
* @return null|bool
|
* @return null|bool
|
||||||
*/
|
*/
|
||||||
public static function update_post_metadata( $check, $object_id, $meta_key, $meta_value, $prev_value ) {
|
public static function update_post_metadata( $check, $object_id, $meta_key, $meta_value, $prev_value ) {
|
||||||
// Delete product cache if someone uses meta directly.
|
// Delete product cache if someone uses meta directly.
|
||||||
if ( in_array( get_post_type( $object_id ), array( 'product', 'product_variation' ) ) ) {
|
if ( in_array( get_post_type( $object_id ), array( 'product', 'product_variation' ), true ) ) {
|
||||||
wp_cache_delete( 'product-' . $object_id, 'products' );
|
wp_cache_delete( 'product-' . $object_id, 'products' );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! empty( $meta_value ) && is_float( $meta_value ) && in_array( get_post_type( $object_id ), array_merge( wc_get_order_types(), array( 'shop_coupon', 'product', 'product_variation' ) ) ) ) {
|
if ( ! empty( $meta_value ) && is_float( $meta_value ) && in_array( get_post_type( $object_id ), array_merge( wc_get_order_types(), array( 'shop_coupon', 'product', 'product_variation' ) ), true ) ) {
|
||||||
|
|
||||||
// Convert float to string
|
// Convert float to string.
|
||||||
$meta_value = wc_float_to_string( $meta_value );
|
$meta_value = wc_float_to_string( $meta_value );
|
||||||
|
|
||||||
// Update meta value with new string
|
// Update meta value with new string.
|
||||||
update_metadata( 'post', $object_id, $meta_key, $meta_value, $prev_value );
|
update_metadata( 'post', $object_id, $meta_key, $meta_value, $prev_value );
|
||||||
|
|
||||||
// Return
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return $check;
|
return $check;
|
||||||
|
@ -255,10 +260,11 @@ class WC_Post_Data {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When setting stock level, ensure the stock status is kept in sync.
|
* When setting stock level, ensure the stock status is kept in sync.
|
||||||
* @param int $meta_id
|
*
|
||||||
* @param int $object_id
|
* @param int $meta_id Meta ID.
|
||||||
* @param string $meta_key
|
* @param int $object_id Object ID.
|
||||||
* @param mixed $meta_value
|
* @param string $meta_key Meta key.
|
||||||
|
* @param mixed $meta_value Meta value.
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
public static function sync_product_stock_status( $meta_id, $object_id, $meta_key, $meta_value ) {}
|
public static function sync_product_stock_status( $meta_id, $object_id, $meta_key, $meta_value ) {}
|
||||||
|
@ -267,7 +273,7 @@ class WC_Post_Data {
|
||||||
* Forces the order posts to have a title in a certain format (containing the date).
|
* Forces the order posts to have a title in a certain format (containing the date).
|
||||||
* Forces certain product data based on the product's type, e.g. grouped products cannot have a parent.
|
* Forces certain product data based on the product's type, e.g. grouped products cannot have a parent.
|
||||||
*
|
*
|
||||||
* @param array $data
|
* @param array $data An array of slashed post data.
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function wp_insert_post_data( $data ) {
|
public static function wp_insert_post_data( $data ) {
|
||||||
|
@ -277,8 +283,8 @@ class WC_Post_Data {
|
||||||
$order_title .= ' – ' . date_i18n( 'F j, Y @ h:i A', strtotime( $data['post_date'] ) );
|
$order_title .= ' – ' . date_i18n( 'F j, Y @ h:i A', strtotime( $data['post_date'] ) );
|
||||||
}
|
}
|
||||||
$data['post_title'] = $order_title;
|
$data['post_title'] = $order_title;
|
||||||
} elseif ( 'product' === $data['post_type'] && isset( $_POST['product-type'] ) ) {
|
} elseif ( 'product' === $data['post_type'] && isset( $_POST['product-type'] ) ) { // WPCS: input var ok, CSRF ok.
|
||||||
$product_type = stripslashes( $_POST['product-type'] );
|
$product_type = wc_clean( wp_unslash( $_POST['product-type'] ) ); // WPCS: input var ok, CSRF ok.
|
||||||
switch ( $product_type ) {
|
switch ( $product_type ) {
|
||||||
case 'grouped':
|
case 'grouped':
|
||||||
case 'variable':
|
case 'variable':
|
||||||
|
@ -301,7 +307,7 @@ class WC_Post_Data {
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function filter_oembed_response_data( $data, $post ) {
|
public static function filter_oembed_response_data( $data, $post ) {
|
||||||
if ( in_array( $post->post_type, array( 'shop_order', 'shop_coupon' ) ) ) {
|
if ( in_array( $post->post_type, array( 'shop_order', 'shop_coupon' ), true ) ) {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
|
@ -310,7 +316,7 @@ class WC_Post_Data {
|
||||||
/**
|
/**
|
||||||
* Removes variations etc belonging to a deleted post, and clears transients.
|
* Removes variations etc belonging to a deleted post, and clears transients.
|
||||||
*
|
*
|
||||||
* @param mixed $id ID of post being deleted
|
* @param mixed $id ID of post being deleted.
|
||||||
*/
|
*/
|
||||||
public static function delete_post( $id ) {
|
public static function delete_post( $id ) {
|
||||||
if ( ! current_user_can( 'delete_posts' ) || ! $id ) {
|
if ( ! current_user_can( 'delete_posts' ) || ! $id ) {
|
||||||
|
@ -323,8 +329,9 @@ class WC_Post_Data {
|
||||||
case 'product':
|
case 'product':
|
||||||
$data_store = WC_Data_Store::load( 'product-variable' );
|
$data_store = WC_Data_Store::load( 'product-variable' );
|
||||||
$data_store->delete_variations( $id, true );
|
$data_store->delete_variations( $id, true );
|
||||||
|
$parent_id = wp_get_post_parent_id( $id );
|
||||||
|
|
||||||
if ( $parent_id = wp_get_post_parent_id( $id ) ) {
|
if ( $parent_id ) {
|
||||||
wc_delete_product_transients( $parent_id );
|
wc_delete_product_transients( $parent_id );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -346,9 +353,9 @@ class WC_Post_Data {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* woocommerce_trash_post function.
|
* Trash post.
|
||||||
*
|
*
|
||||||
* @param mixed $id
|
* @param mixed $id Post ID.
|
||||||
*/
|
*/
|
||||||
public static function trash_post( $id ) {
|
public static function trash_post( $id ) {
|
||||||
if ( ! $id ) {
|
if ( ! $id ) {
|
||||||
|
@ -358,7 +365,7 @@ class WC_Post_Data {
|
||||||
$post_type = get_post_type( $id );
|
$post_type = get_post_type( $id );
|
||||||
|
|
||||||
// If this is an order, trash any refunds too.
|
// If this is an order, trash any refunds too.
|
||||||
if ( in_array( $post_type, wc_get_order_types( 'order-count' ) ) ) {
|
if ( in_array( $post_type, wc_get_order_types( 'order-count' ), true ) ) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
$refunds = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = 'shop_order_refund' AND post_parent = %d", $id ) );
|
$refunds = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = 'shop_order_refund' AND post_parent = %d", $id ) );
|
||||||
|
@ -377,9 +384,9 @@ class WC_Post_Data {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* woocommerce_untrash_post function.
|
* Untrash post.
|
||||||
*
|
*
|
||||||
* @param mixed $id
|
* @param mixed $id Post ID.
|
||||||
*/
|
*/
|
||||||
public static function untrash_post( $id ) {
|
public static function untrash_post( $id ) {
|
||||||
if ( ! $id ) {
|
if ( ! $id ) {
|
||||||
|
@ -388,7 +395,7 @@ class WC_Post_Data {
|
||||||
|
|
||||||
$post_type = get_post_type( $id );
|
$post_type = get_post_type( $id );
|
||||||
|
|
||||||
if ( in_array( $post_type, wc_get_order_types( 'order-count' ) ) ) {
|
if ( in_array( $post_type, wc_get_order_types( 'order-count' ), true ) ) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
$refunds = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = 'shop_order_refund' AND post_parent = %d", $id ) );
|
$refunds = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = 'shop_order_refund' AND post_parent = %d", $id ) );
|
||||||
|
@ -411,10 +418,10 @@ class WC_Post_Data {
|
||||||
* Before deleting an order, do some cleanup.
|
* Before deleting an order, do some cleanup.
|
||||||
*
|
*
|
||||||
* @since 3.2.0
|
* @since 3.2.0
|
||||||
* @param int $order_id
|
* @param int $order_id Order ID.
|
||||||
*/
|
*/
|
||||||
public static function before_delete_order( $order_id ) {
|
public static function before_delete_order( $order_id ) {
|
||||||
if ( in_array( get_post_type( $order_id ), wc_get_order_types() ) ) {
|
if ( in_array( get_post_type( $order_id ), wc_get_order_types(), true ) ) {
|
||||||
// Clean up user.
|
// Clean up user.
|
||||||
$order = wc_get_order( $order_id );
|
$order = wc_get_order( $order_id );
|
||||||
|
|
||||||
|
@ -444,20 +451,22 @@ class WC_Post_Data {
|
||||||
/**
|
/**
|
||||||
* Remove item meta on permanent deletion.
|
* Remove item meta on permanent deletion.
|
||||||
*
|
*
|
||||||
* @param int $postid
|
* @param int $postid Post ID.
|
||||||
*/
|
*/
|
||||||
public static function delete_order_items( $postid ) {
|
public static function delete_order_items( $postid ) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
if ( in_array( get_post_type( $postid ), wc_get_order_types() ) ) {
|
if ( in_array( get_post_type( $postid ), wc_get_order_types(), true ) ) {
|
||||||
do_action( 'woocommerce_delete_order_items', $postid );
|
do_action( 'woocommerce_delete_order_items', $postid );
|
||||||
|
|
||||||
$wpdb->query( "
|
$wpdb->query(
|
||||||
|
"
|
||||||
DELETE {$wpdb->prefix}woocommerce_order_items, {$wpdb->prefix}woocommerce_order_itemmeta
|
DELETE {$wpdb->prefix}woocommerce_order_items, {$wpdb->prefix}woocommerce_order_itemmeta
|
||||||
FROM {$wpdb->prefix}woocommerce_order_items
|
FROM {$wpdb->prefix}woocommerce_order_items
|
||||||
JOIN {$wpdb->prefix}woocommerce_order_itemmeta ON {$wpdb->prefix}woocommerce_order_items.order_item_id = {$wpdb->prefix}woocommerce_order_itemmeta.order_item_id
|
JOIN {$wpdb->prefix}woocommerce_order_itemmeta ON {$wpdb->prefix}woocommerce_order_items.order_item_id = {$wpdb->prefix}woocommerce_order_itemmeta.order_item_id
|
||||||
WHERE {$wpdb->prefix}woocommerce_order_items.order_id = '{$postid}';
|
WHERE {$wpdb->prefix}woocommerce_order_items.order_id = '{$postid}';
|
||||||
" );
|
"
|
||||||
|
); // WPCS: unprepared SQL ok.
|
||||||
|
|
||||||
do_action( 'woocommerce_deleted_order_items', $postid );
|
do_action( 'woocommerce_deleted_order_items', $postid );
|
||||||
}
|
}
|
||||||
|
@ -466,10 +475,10 @@ class WC_Post_Data {
|
||||||
/**
|
/**
|
||||||
* Remove downloadable permissions on permanent order deletion.
|
* Remove downloadable permissions on permanent order deletion.
|
||||||
*
|
*
|
||||||
* @param int $postid
|
* @param int $postid Post ID.
|
||||||
*/
|
*/
|
||||||
public static function delete_order_downloadable_permissions( $postid ) {
|
public static function delete_order_downloadable_permissions( $postid ) {
|
||||||
if ( in_array( get_post_type( $postid ), wc_get_order_types() ) ) {
|
if ( in_array( get_post_type( $postid ), wc_get_order_types(), true ) ) {
|
||||||
do_action( 'woocommerce_delete_order_downloadable_permissions', $postid );
|
do_action( 'woocommerce_delete_order_downloadable_permissions', $postid );
|
||||||
|
|
||||||
$data_store = WC_Data_Store::load( 'customer-download' );
|
$data_store = WC_Data_Store::load( 'customer-download' );
|
||||||
|
@ -483,9 +492,9 @@ class WC_Post_Data {
|
||||||
* Update changed downloads.
|
* Update changed downloads.
|
||||||
*
|
*
|
||||||
* @deprecated 3.3.0 No action is necessary on changes to download paths since download_id is no longer based on file hash.
|
* @deprecated 3.3.0 No action is necessary on changes to download paths since download_id is no longer based on file hash.
|
||||||
* @param int $product_id product identifier
|
* @param int $product_id Product ID.
|
||||||
* @param int $variation_id optional product variation identifier
|
* @param int $variation_id Variation ID. Optional product variation identifier.
|
||||||
* @param array $downloads newly set files
|
* @param array $downloads Newly set files.
|
||||||
*/
|
*/
|
||||||
public static function process_product_file_download_paths( $product_id, $variation_id, $downloads ) {
|
public static function process_product_file_download_paths( $product_id, $variation_id, $downloads ) {
|
||||||
wc_deprecated_function( __FUNCTION__, '3.3' );
|
wc_deprecated_function( __FUNCTION__, '3.3' );
|
||||||
|
@ -493,10 +502,11 @@ class WC_Post_Data {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flush meta cache for CRUD objects on direct update.
|
* Flush meta cache for CRUD objects on direct update.
|
||||||
* @param int $meta_id
|
*
|
||||||
* @param int $object_id
|
* @param int $meta_id Meta ID.
|
||||||
* @param string $meta_key
|
* @param int $object_id Object ID.
|
||||||
* @param string $meta_value
|
* @param string $meta_key Meta key.
|
||||||
|
* @param string $meta_value Meta value.
|
||||||
*/
|
*/
|
||||||
public static function flush_object_meta_cache( $meta_id, $object_id, $meta_key, $meta_value ) {
|
public static function flush_object_meta_cache( $meta_id, $object_id, $meta_key, $meta_value ) {
|
||||||
WC_Cache_Helper::incr_cache_prefix( 'object_' . $object_id );
|
WC_Cache_Helper::incr_cache_prefix( 'object_' . $object_id );
|
||||||
|
|
|
@ -4,21 +4,16 @@
|
||||||
*
|
*
|
||||||
* Registers post types and taxonomies.
|
* Registers post types and taxonomies.
|
||||||
*
|
*
|
||||||
* @class WC_Post_types
|
|
||||||
* @version 2.5.0
|
|
||||||
* @package WooCommerce/Classes/Products
|
* @package WooCommerce/Classes/Products
|
||||||
* @category Class
|
* @version 2.5.0
|
||||||
* @author WooThemes
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
defined( 'ABSPATH' ) || exit;
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WC_Post_types Class.
|
* Post types Class.
|
||||||
*/
|
*/
|
||||||
class WC_Post_types {
|
class WC_Post_Types {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook in methods.
|
* Hook in methods.
|
||||||
|
@ -50,33 +45,41 @@ class WC_Post_types {
|
||||||
|
|
||||||
$permalinks = wc_get_permalink_structure();
|
$permalinks = wc_get_permalink_structure();
|
||||||
|
|
||||||
register_taxonomy( 'product_type',
|
register_taxonomy(
|
||||||
|
'product_type',
|
||||||
apply_filters( 'woocommerce_taxonomy_objects_product_type', array( 'product' ) ),
|
apply_filters( 'woocommerce_taxonomy_objects_product_type', array( 'product' ) ),
|
||||||
apply_filters( 'woocommerce_taxonomy_args_product_type', array(
|
apply_filters(
|
||||||
|
'woocommerce_taxonomy_args_product_type', array(
|
||||||
'hierarchical' => false,
|
'hierarchical' => false,
|
||||||
'show_ui' => false,
|
'show_ui' => false,
|
||||||
'show_in_nav_menus' => false,
|
'show_in_nav_menus' => false,
|
||||||
'query_var' => is_admin(),
|
'query_var' => is_admin(),
|
||||||
'rewrite' => false,
|
'rewrite' => false,
|
||||||
'public' => false,
|
'public' => false,
|
||||||
) )
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
register_taxonomy( 'product_visibility',
|
register_taxonomy(
|
||||||
|
'product_visibility',
|
||||||
apply_filters( 'woocommerce_taxonomy_objects_product_visibility', array( 'product', 'product_variation' ) ),
|
apply_filters( 'woocommerce_taxonomy_objects_product_visibility', array( 'product', 'product_variation' ) ),
|
||||||
apply_filters( 'woocommerce_taxonomy_args_product_visibility', array(
|
apply_filters(
|
||||||
|
'woocommerce_taxonomy_args_product_visibility', array(
|
||||||
'hierarchical' => false,
|
'hierarchical' => false,
|
||||||
'show_ui' => false,
|
'show_ui' => false,
|
||||||
'show_in_nav_menus' => false,
|
'show_in_nav_menus' => false,
|
||||||
'query_var' => is_admin(),
|
'query_var' => is_admin(),
|
||||||
'rewrite' => false,
|
'rewrite' => false,
|
||||||
'public' => false,
|
'public' => false,
|
||||||
) )
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
register_taxonomy( 'product_cat',
|
register_taxonomy(
|
||||||
|
'product_cat',
|
||||||
apply_filters( 'woocommerce_taxonomy_objects_product_cat', array( 'product' ) ),
|
apply_filters( 'woocommerce_taxonomy_objects_product_cat', array( 'product' ) ),
|
||||||
apply_filters( 'woocommerce_taxonomy_args_product_cat', array(
|
apply_filters(
|
||||||
|
'woocommerce_taxonomy_args_product_cat', array(
|
||||||
'hierarchical' => true,
|
'hierarchical' => true,
|
||||||
'update_count_callback' => '_wc_term_recount',
|
'update_count_callback' => '_wc_term_recount',
|
||||||
'label' => __( 'Categories', 'woocommerce' ),
|
'label' => __( 'Categories', 'woocommerce' ),
|
||||||
|
@ -107,12 +110,15 @@ class WC_Post_types {
|
||||||
'with_front' => false,
|
'with_front' => false,
|
||||||
'hierarchical' => true,
|
'hierarchical' => true,
|
||||||
),
|
),
|
||||||
) )
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
register_taxonomy( 'product_tag',
|
register_taxonomy(
|
||||||
|
'product_tag',
|
||||||
apply_filters( 'woocommerce_taxonomy_objects_product_tag', array( 'product' ) ),
|
apply_filters( 'woocommerce_taxonomy_objects_product_tag', array( 'product' ) ),
|
||||||
apply_filters( 'woocommerce_taxonomy_args_product_tag', array(
|
apply_filters(
|
||||||
|
'woocommerce_taxonomy_args_product_tag', array(
|
||||||
'hierarchical' => false,
|
'hierarchical' => false,
|
||||||
'update_count_callback' => '_wc_term_recount',
|
'update_count_callback' => '_wc_term_recount',
|
||||||
'label' => __( 'Product tags', 'woocommerce' ),
|
'label' => __( 'Product tags', 'woocommerce' ),
|
||||||
|
@ -144,12 +150,15 @@ class WC_Post_types {
|
||||||
'slug' => $permalinks['tag_rewrite_slug'],
|
'slug' => $permalinks['tag_rewrite_slug'],
|
||||||
'with_front' => false,
|
'with_front' => false,
|
||||||
),
|
),
|
||||||
) )
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
register_taxonomy( 'product_shipping_class',
|
register_taxonomy(
|
||||||
|
'product_shipping_class',
|
||||||
apply_filters( 'woocommerce_taxonomy_objects_product_shipping_class', array( 'product', 'product_variation' ) ),
|
apply_filters( 'woocommerce_taxonomy_objects_product_shipping_class', array( 'product', 'product_variation' ) ),
|
||||||
apply_filters( 'woocommerce_taxonomy_args_product_shipping_class', array(
|
apply_filters(
|
||||||
|
'woocommerce_taxonomy_args_product_shipping_class', array(
|
||||||
'hierarchical' => false,
|
'hierarchical' => false,
|
||||||
'update_count_callback' => '_update_post_term_count',
|
'update_count_callback' => '_update_post_term_count',
|
||||||
'label' => __( 'Shipping classes', 'woocommerce' ),
|
'label' => __( 'Shipping classes', 'woocommerce' ),
|
||||||
|
@ -177,16 +186,20 @@ class WC_Post_types {
|
||||||
'assign_terms' => 'assign_product_terms',
|
'assign_terms' => 'assign_product_terms',
|
||||||
),
|
),
|
||||||
'rewrite' => false,
|
'rewrite' => false,
|
||||||
) )
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
global $wc_product_attributes;
|
global $wc_product_attributes;
|
||||||
|
|
||||||
$wc_product_attributes = array();
|
$wc_product_attributes = array();
|
||||||
|
$attribute_taxonomies = wc_get_attribute_taxonomies();
|
||||||
|
|
||||||
if ( $attribute_taxonomies = wc_get_attribute_taxonomies() ) {
|
if ( $attribute_taxonomies ) {
|
||||||
foreach ( $attribute_taxonomies as $tax ) {
|
foreach ( $attribute_taxonomies as $tax ) {
|
||||||
if ( $name = wc_attribute_taxonomy_name( $tax->attribute_name ) ) {
|
$name = wc_attribute_taxonomy_name( $tax->attribute_name );
|
||||||
|
|
||||||
|
if ( $name ) {
|
||||||
$tax->attribute_public = absint( isset( $tax->attribute_public ) ? $tax->attribute_public : 1 );
|
$tax->attribute_public = absint( isset( $tax->attribute_public ) ? $tax->attribute_public : 1 );
|
||||||
$label = ! empty( $tax->attribute_label ) ? $tax->attribute_label : $tax->attribute_name;
|
$label = ! empty( $tax->attribute_label ) ? $tax->attribute_label : $tax->attribute_name;
|
||||||
$wc_product_attributes[ $name ] = $tax;
|
$wc_product_attributes[ $name ] = $tax;
|
||||||
|
@ -194,16 +207,26 @@ class WC_Post_types {
|
||||||
'hierarchical' => false,
|
'hierarchical' => false,
|
||||||
'update_count_callback' => '_update_post_term_count',
|
'update_count_callback' => '_update_post_term_count',
|
||||||
'labels' => array(
|
'labels' => array(
|
||||||
|
/* translators: %s: attribute name */
|
||||||
'name' => sprintf( _x( 'Product %s', 'Product Attribute', 'woocommerce' ), $label ),
|
'name' => sprintf( _x( 'Product %s', 'Product Attribute', 'woocommerce' ), $label ),
|
||||||
'singular_name' => $label,
|
'singular_name' => $label,
|
||||||
|
/* translators: %s: attribute name */
|
||||||
'search_items' => sprintf( __( 'Search %s', 'woocommerce' ), $label ),
|
'search_items' => sprintf( __( 'Search %s', 'woocommerce' ), $label ),
|
||||||
|
/* translators: %s: attribute name */
|
||||||
'all_items' => sprintf( __( 'All %s', 'woocommerce' ), $label ),
|
'all_items' => sprintf( __( 'All %s', 'woocommerce' ), $label ),
|
||||||
|
/* translators: %s: attribute name */
|
||||||
'parent_item' => sprintf( __( 'Parent %s', 'woocommerce' ), $label ),
|
'parent_item' => sprintf( __( 'Parent %s', 'woocommerce' ), $label ),
|
||||||
|
/* translators: %s: attribute name */
|
||||||
'parent_item_colon' => sprintf( __( 'Parent %s:', 'woocommerce' ), $label ),
|
'parent_item_colon' => sprintf( __( 'Parent %s:', 'woocommerce' ), $label ),
|
||||||
|
/* translators: %s: attribute name */
|
||||||
'edit_item' => sprintf( __( 'Edit %s', 'woocommerce' ), $label ),
|
'edit_item' => sprintf( __( 'Edit %s', 'woocommerce' ), $label ),
|
||||||
|
/* translators: %s: attribute name */
|
||||||
'update_item' => sprintf( __( 'Update %s', 'woocommerce' ), $label ),
|
'update_item' => sprintf( __( 'Update %s', 'woocommerce' ), $label ),
|
||||||
|
/* translators: %s: attribute name */
|
||||||
'add_new_item' => sprintf( __( 'Add new %s', 'woocommerce' ), $label ),
|
'add_new_item' => sprintf( __( 'Add new %s', 'woocommerce' ), $label ),
|
||||||
|
/* translators: %s: attribute name */
|
||||||
'new_item_name' => sprintf( __( 'New %s', 'woocommerce' ), $label ),
|
'new_item_name' => sprintf( __( 'New %s', 'woocommerce' ), $label ),
|
||||||
|
/* translators: %s: attribute name */
|
||||||
'not_found' => sprintf( __( 'No "%s" found', 'woocommerce' ), $label ),
|
'not_found' => sprintf( __( 'No "%s" found', 'woocommerce' ), $label ),
|
||||||
),
|
),
|
||||||
'show_ui' => true,
|
'show_ui' => true,
|
||||||
|
@ -269,8 +292,10 @@ class WC_Post_types {
|
||||||
update_option( 'woocommerce_queue_flush_rewrite_rules', 'yes' );
|
update_option( 'woocommerce_queue_flush_rewrite_rules', 'yes' );
|
||||||
}
|
}
|
||||||
|
|
||||||
register_post_type( 'product',
|
register_post_type(
|
||||||
apply_filters( 'woocommerce_register_post_type_product',
|
'product',
|
||||||
|
apply_filters(
|
||||||
|
'woocommerce_register_post_type_product',
|
||||||
array(
|
array(
|
||||||
'labels' => array(
|
'labels' => array(
|
||||||
'name' => __( 'Products', 'woocommerce' ),
|
'name' => __( 'Products', 'woocommerce' ),
|
||||||
|
@ -306,7 +331,11 @@ class WC_Post_types {
|
||||||
'publicly_queryable' => true,
|
'publicly_queryable' => true,
|
||||||
'exclude_from_search' => false,
|
'exclude_from_search' => false,
|
||||||
'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
|
'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
|
||||||
'rewrite' => $permalinks['product_rewrite_slug'] ? array( 'slug' => $permalinks['product_rewrite_slug'], 'with_front' => false, 'feeds' => true ) : false,
|
'rewrite' => $permalinks['product_rewrite_slug'] ? array(
|
||||||
|
'slug' => $permalinks['product_rewrite_slug'],
|
||||||
|
'with_front' => false,
|
||||||
|
'feeds' => true,
|
||||||
|
) : false,
|
||||||
'query_var' => true,
|
'query_var' => true,
|
||||||
'supports' => $supports,
|
'supports' => $supports,
|
||||||
'has_archive' => $has_archive,
|
'has_archive' => $has_archive,
|
||||||
|
@ -316,8 +345,10 @@ class WC_Post_types {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
register_post_type( 'product_variation',
|
register_post_type(
|
||||||
apply_filters( 'woocommerce_register_post_type_product_variation',
|
'product_variation',
|
||||||
|
apply_filters(
|
||||||
|
'woocommerce_register_post_type_product_variation',
|
||||||
array(
|
array(
|
||||||
'label' => __( 'Variations', 'woocommerce' ),
|
'label' => __( 'Variations', 'woocommerce' ),
|
||||||
'public' => false,
|
'public' => false,
|
||||||
|
@ -331,7 +362,8 @@ class WC_Post_types {
|
||||||
|
|
||||||
wc_register_order_type(
|
wc_register_order_type(
|
||||||
'shop_order',
|
'shop_order',
|
||||||
apply_filters( 'woocommerce_register_post_type_shop_order',
|
apply_filters(
|
||||||
|
'woocommerce_register_post_type_shop_order',
|
||||||
array(
|
array(
|
||||||
'labels' => array(
|
'labels' => array(
|
||||||
'name' => __( 'Orders', 'woocommerce' ),
|
'name' => __( 'Orders', 'woocommerce' ),
|
||||||
|
@ -371,7 +403,8 @@ class WC_Post_types {
|
||||||
|
|
||||||
wc_register_order_type(
|
wc_register_order_type(
|
||||||
'shop_order_refund',
|
'shop_order_refund',
|
||||||
apply_filters( 'woocommerce_register_post_type_shop_order_refund',
|
apply_filters(
|
||||||
|
'woocommerce_register_post_type_shop_order_refund',
|
||||||
array(
|
array(
|
||||||
'label' => __( 'Refunds', 'woocommerce' ),
|
'label' => __( 'Refunds', 'woocommerce' ),
|
||||||
'capability_type' => 'shop_order',
|
'capability_type' => 'shop_order',
|
||||||
|
@ -390,9 +423,11 @@ class WC_Post_types {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( 'yes' == get_option( 'woocommerce_enable_coupons' ) ) {
|
if ( 'yes' === get_option( 'woocommerce_enable_coupons' ) ) {
|
||||||
register_post_type( 'shop_coupon',
|
register_post_type(
|
||||||
apply_filters( 'woocommerce_register_post_type_shop_coupon',
|
'shop_coupon',
|
||||||
|
apply_filters(
|
||||||
|
'woocommerce_register_post_type_shop_coupon',
|
||||||
array(
|
array(
|
||||||
'labels' => array(
|
'labels' => array(
|
||||||
'name' => __( 'Coupons', 'woocommerce' ),
|
'name' => __( 'Coupons', 'woocommerce' ),
|
||||||
|
@ -439,7 +474,8 @@ class WC_Post_types {
|
||||||
*/
|
*/
|
||||||
public static function register_post_status() {
|
public static function register_post_status() {
|
||||||
|
|
||||||
$order_statuses = apply_filters( 'woocommerce_register_shop_order_post_statuses',
|
$order_statuses = apply_filters(
|
||||||
|
'woocommerce_register_shop_order_post_statuses',
|
||||||
array(
|
array(
|
||||||
'wc-pending' => array(
|
'wc-pending' => array(
|
||||||
'label' => _x( 'Pending payment', 'Order status', 'woocommerce' ),
|
'label' => _x( 'Pending payment', 'Order status', 'woocommerce' ),
|
||||||
|
@ -447,6 +483,7 @@ class WC_Post_types {
|
||||||
'exclude_from_search' => false,
|
'exclude_from_search' => false,
|
||||||
'show_in_admin_all_list' => true,
|
'show_in_admin_all_list' => true,
|
||||||
'show_in_admin_status_list' => true,
|
'show_in_admin_status_list' => true,
|
||||||
|
/* translators: %s: number of orders */
|
||||||
'label_count' => _n_noop( 'Pending payment <span class="count">(%s)</span>', 'Pending payment <span class="count">(%s)</span>', 'woocommerce' ),
|
'label_count' => _n_noop( 'Pending payment <span class="count">(%s)</span>', 'Pending payment <span class="count">(%s)</span>', 'woocommerce' ),
|
||||||
),
|
),
|
||||||
'wc-processing' => array(
|
'wc-processing' => array(
|
||||||
|
@ -455,6 +492,7 @@ class WC_Post_types {
|
||||||
'exclude_from_search' => false,
|
'exclude_from_search' => false,
|
||||||
'show_in_admin_all_list' => true,
|
'show_in_admin_all_list' => true,
|
||||||
'show_in_admin_status_list' => true,
|
'show_in_admin_status_list' => true,
|
||||||
|
/* translators: %s: number of orders */
|
||||||
'label_count' => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'woocommerce' ),
|
'label_count' => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'woocommerce' ),
|
||||||
),
|
),
|
||||||
'wc-on-hold' => array(
|
'wc-on-hold' => array(
|
||||||
|
@ -463,6 +501,7 @@ class WC_Post_types {
|
||||||
'exclude_from_search' => false,
|
'exclude_from_search' => false,
|
||||||
'show_in_admin_all_list' => true,
|
'show_in_admin_all_list' => true,
|
||||||
'show_in_admin_status_list' => true,
|
'show_in_admin_status_list' => true,
|
||||||
|
/* translators: %s: number of orders */
|
||||||
'label_count' => _n_noop( 'On hold <span class="count">(%s)</span>', 'On hold <span class="count">(%s)</span>', 'woocommerce' ),
|
'label_count' => _n_noop( 'On hold <span class="count">(%s)</span>', 'On hold <span class="count">(%s)</span>', 'woocommerce' ),
|
||||||
),
|
),
|
||||||
'wc-completed' => array(
|
'wc-completed' => array(
|
||||||
|
@ -471,6 +510,7 @@ class WC_Post_types {
|
||||||
'exclude_from_search' => false,
|
'exclude_from_search' => false,
|
||||||
'show_in_admin_all_list' => true,
|
'show_in_admin_all_list' => true,
|
||||||
'show_in_admin_status_list' => true,
|
'show_in_admin_status_list' => true,
|
||||||
|
/* translators: %s: number of orders */
|
||||||
'label_count' => _n_noop( 'Completed <span class="count">(%s)</span>', 'Completed <span class="count">(%s)</span>', 'woocommerce' ),
|
'label_count' => _n_noop( 'Completed <span class="count">(%s)</span>', 'Completed <span class="count">(%s)</span>', 'woocommerce' ),
|
||||||
),
|
),
|
||||||
'wc-cancelled' => array(
|
'wc-cancelled' => array(
|
||||||
|
@ -479,6 +519,7 @@ class WC_Post_types {
|
||||||
'exclude_from_search' => false,
|
'exclude_from_search' => false,
|
||||||
'show_in_admin_all_list' => true,
|
'show_in_admin_all_list' => true,
|
||||||
'show_in_admin_status_list' => true,
|
'show_in_admin_status_list' => true,
|
||||||
|
/* translators: %s: number of orders */
|
||||||
'label_count' => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'woocommerce' ),
|
'label_count' => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'woocommerce' ),
|
||||||
),
|
),
|
||||||
'wc-refunded' => array(
|
'wc-refunded' => array(
|
||||||
|
@ -487,6 +528,7 @@ class WC_Post_types {
|
||||||
'exclude_from_search' => false,
|
'exclude_from_search' => false,
|
||||||
'show_in_admin_all_list' => true,
|
'show_in_admin_all_list' => true,
|
||||||
'show_in_admin_status_list' => true,
|
'show_in_admin_status_list' => true,
|
||||||
|
/* translators: %s: number of orders */
|
||||||
'label_count' => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'woocommerce' ),
|
'label_count' => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'woocommerce' ),
|
||||||
),
|
),
|
||||||
'wc-failed' => array(
|
'wc-failed' => array(
|
||||||
|
@ -495,6 +537,7 @@ class WC_Post_types {
|
||||||
'exclude_from_search' => false,
|
'exclude_from_search' => false,
|
||||||
'show_in_admin_all_list' => true,
|
'show_in_admin_all_list' => true,
|
||||||
'show_in_admin_status_list' => true,
|
'show_in_admin_status_list' => true,
|
||||||
|
/* translators: %s: number of orders */
|
||||||
'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'woocommerce' ),
|
'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'woocommerce' ),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -536,7 +579,7 @@ class WC_Post_types {
|
||||||
/**
|
/**
|
||||||
* Added product for Jetpack related posts.
|
* Added product for Jetpack related posts.
|
||||||
*
|
*
|
||||||
* @param array $post_types
|
* @param array $post_types Post types.
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function rest_api_allowed_post_types( $post_types ) {
|
public static function rest_api_allowed_post_types( $post_types ) {
|
||||||
|
|
|
@ -1,18 +1,19 @@
|
||||||
<?php
|
<?php
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a product attribute.
|
* Represents a product attribute
|
||||||
*
|
*
|
||||||
* Attributes can be global (taxonomy based) or local to the product itself.
|
* Attributes can be global (taxonomy based) or local to the product itself.
|
||||||
* Uses ArrayAccess to be BW compatible with previous ways of reading attributes.
|
* Uses ArrayAccess to be BW compatible with previous ways of reading attributes.
|
||||||
*
|
*
|
||||||
|
* @package WooCommerce/Classes
|
||||||
* @version 3.0.0
|
* @version 3.0.0
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
* @package WooCommerce/Classes
|
*/
|
||||||
* @author WooThemes
|
|
||||||
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Product attribute class.
|
||||||
*/
|
*/
|
||||||
class WC_Product_Attribute implements ArrayAccess {
|
class WC_Product_Attribute implements ArrayAccess {
|
||||||
|
|
||||||
|
@ -122,12 +123,14 @@ class WC_Product_Attribute implements ArrayAccess {
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get_data() {
|
public function get_data() {
|
||||||
return array_merge( $this->data, array(
|
return array_merge(
|
||||||
|
$this->data, array(
|
||||||
'is_visible' => $this->get_visible() ? 1 : 0,
|
'is_visible' => $this->get_visible() ? 1 : 0,
|
||||||
'is_variation' => $this->get_variation() ? 1 : 0,
|
'is_variation' => $this->get_variation() ? 1 : 0,
|
||||||
'is_taxonomy' => $this->is_taxonomy() ? 1 : 0,
|
'is_taxonomy' => $this->is_taxonomy() ? 1 : 0,
|
||||||
'value' => $this->is_taxonomy() ? '' : wc_implode_text_attributes( $this->get_options() ),
|
'value' => $this->is_taxonomy() ? '' : wc_implode_text_attributes( $this->get_options() ),
|
||||||
) );
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -139,7 +142,7 @@ class WC_Product_Attribute implements ArrayAccess {
|
||||||
/**
|
/**
|
||||||
* Set ID (this is the attribute ID).
|
* Set ID (this is the attribute ID).
|
||||||
*
|
*
|
||||||
* @param int $value
|
* @param int $value Attribute ID.
|
||||||
*/
|
*/
|
||||||
public function set_id( $value ) {
|
public function set_id( $value ) {
|
||||||
$this->data['id'] = absint( $value );
|
$this->data['id'] = absint( $value );
|
||||||
|
@ -148,7 +151,7 @@ class WC_Product_Attribute implements ArrayAccess {
|
||||||
/**
|
/**
|
||||||
* Set name (this is the attribute name or taxonomy).
|
* Set name (this is the attribute name or taxonomy).
|
||||||
*
|
*
|
||||||
* @param int $value
|
* @param int $value Attribute name.
|
||||||
*/
|
*/
|
||||||
public function set_name( $value ) {
|
public function set_name( $value ) {
|
||||||
$this->data['name'] = $value;
|
$this->data['name'] = $value;
|
||||||
|
@ -157,7 +160,7 @@ class WC_Product_Attribute implements ArrayAccess {
|
||||||
/**
|
/**
|
||||||
* Set options.
|
* Set options.
|
||||||
*
|
*
|
||||||
* @param array $value
|
* @param array $value Attribute options.
|
||||||
*/
|
*/
|
||||||
public function set_options( $value ) {
|
public function set_options( $value ) {
|
||||||
$this->data['options'] = $value;
|
$this->data['options'] = $value;
|
||||||
|
@ -166,7 +169,7 @@ class WC_Product_Attribute implements ArrayAccess {
|
||||||
/**
|
/**
|
||||||
* Set position.
|
* Set position.
|
||||||
*
|
*
|
||||||
* @param int $value
|
* @param int $value Attribute position.
|
||||||
*/
|
*/
|
||||||
public function set_position( $value ) {
|
public function set_position( $value ) {
|
||||||
$this->data['position'] = absint( $value );
|
$this->data['position'] = absint( $value );
|
||||||
|
@ -175,7 +178,7 @@ class WC_Product_Attribute implements ArrayAccess {
|
||||||
/**
|
/**
|
||||||
* Set if visible.
|
* Set if visible.
|
||||||
*
|
*
|
||||||
* @param bool $value
|
* @param bool $value If is visible on Product's additional info tab.
|
||||||
*/
|
*/
|
||||||
public function set_visible( $value ) {
|
public function set_visible( $value ) {
|
||||||
$this->data['visible'] = wc_string_to_bool( $value );
|
$this->data['visible'] = wc_string_to_bool( $value );
|
||||||
|
@ -184,7 +187,7 @@ class WC_Product_Attribute implements ArrayAccess {
|
||||||
/**
|
/**
|
||||||
* Set if variation.
|
* Set if variation.
|
||||||
*
|
*
|
||||||
* @param bool $value
|
* @param bool $value If is used for variations.
|
||||||
*/
|
*/
|
||||||
public function set_variation( $value ) {
|
public function set_variation( $value ) {
|
||||||
$this->data['variation'] = wc_string_to_bool( $value );
|
$this->data['variation'] = wc_string_to_bool( $value );
|
||||||
|
@ -257,25 +260,21 @@ class WC_Product_Attribute implements ArrayAccess {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* offsetGet.
|
* OffsetGet.
|
||||||
*
|
*
|
||||||
* @param string $offset
|
* @param string $offset Offset.
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function offsetGet( $offset ) {
|
public function offsetGet( $offset ) {
|
||||||
switch ( $offset ) {
|
switch ( $offset ) {
|
||||||
case 'is_variation':
|
case 'is_variation':
|
||||||
return $this->get_variation() ? 1 : 0;
|
return $this->get_variation() ? 1 : 0;
|
||||||
break;
|
|
||||||
case 'is_visible':
|
case 'is_visible':
|
||||||
return $this->get_visible() ? 1 : 0;
|
return $this->get_visible() ? 1 : 0;
|
||||||
break;
|
|
||||||
case 'is_taxonomy':
|
case 'is_taxonomy':
|
||||||
return $this->is_taxonomy() ? 1 : 0;
|
return $this->is_taxonomy() ? 1 : 0;
|
||||||
break;
|
|
||||||
case 'value':
|
case 'value':
|
||||||
return $this->is_taxonomy() ? '' : wc_implode_text_attributes( $this->get_options() );
|
return $this->is_taxonomy() ? '' : wc_implode_text_attributes( $this->get_options() );
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
if ( is_callable( array( $this, "get_$offset" ) ) ) {
|
if ( is_callable( array( $this, "get_$offset" ) ) ) {
|
||||||
return $this->{"get_$offset"}();
|
return $this->{"get_$offset"}();
|
||||||
|
@ -286,10 +285,10 @@ class WC_Product_Attribute implements ArrayAccess {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* offsetSet.
|
* OffsetSet.
|
||||||
*
|
*
|
||||||
* @param string $offset
|
* @param string $offset Offset.
|
||||||
* @param mixed $value
|
* @param mixed $value Value.
|
||||||
*/
|
*/
|
||||||
public function offsetSet( $offset, $value ) {
|
public function offsetSet( $offset, $value ) {
|
||||||
switch ( $offset ) {
|
switch ( $offset ) {
|
||||||
|
@ -311,19 +310,19 @@ class WC_Product_Attribute implements ArrayAccess {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* offsetUnset.
|
* OffsetUnset.
|
||||||
*
|
*
|
||||||
* @param string $offset
|
* @param string $offset Offset.
|
||||||
*/
|
*/
|
||||||
public function offsetUnset( $offset ) {}
|
public function offsetUnset( $offset ) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* offsetExists.
|
* OffsetExists.
|
||||||
*
|
*
|
||||||
* @param string $offset
|
* @param string $offset Offset.
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function offsetExists( $offset ) {
|
public function offsetExists( $offset ) {
|
||||||
return in_array( $offset, array_merge( array( 'is_variation', 'is_visible', 'is_taxonomy', 'value' ), array_keys( $this->data ) ) );
|
return in_array( $offset, array_merge( array( 'is_variation', 'is_visible', 'is_taxonomy', 'value' ), array_keys( $this->data ) ), true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,22 @@
|
||||||
<?php
|
<?php
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a file which can be downloaded.
|
* Represents a file which can be downloaded.
|
||||||
*
|
*
|
||||||
|
* @package WooCommerce/Classes
|
||||||
* @version 3.0.0
|
* @version 3.0.0
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
* @package WooCommerce/Classes
|
*/
|
||||||
* @author WooThemes
|
|
||||||
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Product download class.
|
||||||
*/
|
*/
|
||||||
class WC_Product_Download implements ArrayAccess {
|
class WC_Product_Download implements ArrayAccess {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data array.
|
* Data array.
|
||||||
|
*
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
|
@ -26,6 +28,7 @@ class WC_Product_Download implements ArrayAccess {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all data for this object.
|
* Returns all data for this object.
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get_data() {
|
public function get_data() {
|
||||||
|
@ -34,6 +37,7 @@ class WC_Product_Download implements ArrayAccess {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get allowed mime types.
|
* Get allowed mime types.
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get_allowed_mime_types() {
|
public function get_allowed_mime_types() {
|
||||||
|
@ -42,6 +46,7 @@ class WC_Product_Download implements ArrayAccess {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get type of file path set.
|
* Get type of file path set.
|
||||||
|
*
|
||||||
* @param string $file_path optional.
|
* @param string $file_path optional.
|
||||||
* @return string absolute, relative, or shortcode.
|
* @return string absolute, relative, or shortcode.
|
||||||
*/
|
*/
|
||||||
|
@ -58,6 +63,7 @@ class WC_Product_Download implements ArrayAccess {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get file type.
|
* Get file type.
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_file_type() {
|
public function get_file_type() {
|
||||||
|
@ -67,26 +73,29 @@ class WC_Product_Download implements ArrayAccess {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get file extension.
|
* Get file extension.
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_file_extension() {
|
public function get_file_extension() {
|
||||||
$parsed_url = parse_url( $this->get_file(), PHP_URL_PATH );
|
$parsed_url = wp_parse_url( $this->get_file(), PHP_URL_PATH );
|
||||||
return pathinfo( $parsed_url, PATHINFO_EXTENSION );
|
return pathinfo( $parsed_url, PATHINFO_EXTENSION );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if file is allowed.
|
* Check if file is allowed.
|
||||||
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function is_allowed_filetype() {
|
public function is_allowed_filetype() {
|
||||||
if ( 'relative' !== $this->get_type_of_file_path() ) {
|
if ( 'relative' !== $this->get_type_of_file_path() ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return ! $this->get_file_extension() || in_array( $this->get_file_type(), $this->get_allowed_mime_types() );
|
return ! $this->get_file_extension() || in_array( $this->get_file_type(), $this->get_allowed_mime_types(), true );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate file exists.
|
* Validate file exists.
|
||||||
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function file_exists() {
|
public function file_exists() {
|
||||||
|
@ -110,7 +119,8 @@ class WC_Product_Download implements ArrayAccess {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set ID.
|
* Set ID.
|
||||||
* @param string $value
|
*
|
||||||
|
* @param string $value Download ID.
|
||||||
*/
|
*/
|
||||||
public function set_id( $value ) {
|
public function set_id( $value ) {
|
||||||
$this->data['id'] = wc_clean( $value );
|
$this->data['id'] = wc_clean( $value );
|
||||||
|
@ -118,7 +128,8 @@ class WC_Product_Download implements ArrayAccess {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set name.
|
* Set name.
|
||||||
* @param string $value
|
*
|
||||||
|
* @param string $value Download name.
|
||||||
*/
|
*/
|
||||||
public function set_name( $value ) {
|
public function set_name( $value ) {
|
||||||
$this->data['name'] = wc_clean( $value );
|
$this->data['name'] = wc_clean( $value );
|
||||||
|
@ -126,8 +137,9 @@ class WC_Product_Download implements ArrayAccess {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set previous_hash.
|
* Set previous_hash.
|
||||||
|
*
|
||||||
* @deprecated 3.3.0 No longer using filename based hashing to keep track of files.
|
* @deprecated 3.3.0 No longer using filename based hashing to keep track of files.
|
||||||
* @param string $value
|
* @param string $value Previous hash.
|
||||||
*/
|
*/
|
||||||
public function set_previous_hash( $value ) {
|
public function set_previous_hash( $value ) {
|
||||||
wc_deprecated_function( __FUNCTION__, '3.3' );
|
wc_deprecated_function( __FUNCTION__, '3.3' );
|
||||||
|
@ -136,7 +148,8 @@ class WC_Product_Download implements ArrayAccess {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set file.
|
* Set file.
|
||||||
* @param string $value
|
*
|
||||||
|
* @param string $value File.
|
||||||
*/
|
*/
|
||||||
public function set_file( $value ) {
|
public function set_file( $value ) {
|
||||||
switch ( $this->get_type_of_file_path( $value ) ) {
|
switch ( $this->get_type_of_file_path( $value ) ) {
|
||||||
|
@ -157,6 +170,7 @@ class WC_Product_Download implements ArrayAccess {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get id.
|
* Get id.
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_id() {
|
public function get_id() {
|
||||||
|
@ -165,6 +179,7 @@ class WC_Product_Download implements ArrayAccess {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get name.
|
* Get name.
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_name() {
|
public function get_name() {
|
||||||
|
@ -173,6 +188,7 @@ class WC_Product_Download implements ArrayAccess {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get previous_hash.
|
* Get previous_hash.
|
||||||
|
*
|
||||||
* @deprecated 3.3.0 No longer using filename based hashing to keep track of files.
|
* @deprecated 3.3.0 No longer using filename based hashing to keep track of files.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
@ -183,6 +199,7 @@ class WC_Product_Download implements ArrayAccess {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get file.
|
* Get file.
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_file() {
|
public function get_file() {
|
||||||
|
@ -196,8 +213,9 @@ class WC_Product_Download implements ArrayAccess {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* offsetGet
|
* OffsetGet.
|
||||||
* @param string $offset
|
*
|
||||||
|
* @param string $offset Offset.
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function offsetGet( $offset ) {
|
public function offsetGet( $offset ) {
|
||||||
|
@ -212,9 +230,10 @@ class WC_Product_Download implements ArrayAccess {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* offsetSet
|
* OffsetSet.
|
||||||
* @param string $offset
|
*
|
||||||
* @param mixed $value
|
* @param string $offset Offset.
|
||||||
|
* @param mixed $value Value.
|
||||||
*/
|
*/
|
||||||
public function offsetSet( $offset, $value ) {
|
public function offsetSet( $offset, $value ) {
|
||||||
switch ( $offset ) {
|
switch ( $offset ) {
|
||||||
|
@ -227,17 +246,19 @@ class WC_Product_Download implements ArrayAccess {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* offsetUnset
|
* OffsetUnset.
|
||||||
* @param string $offset
|
*
|
||||||
|
* @param string $offset Offset.
|
||||||
*/
|
*/
|
||||||
public function offsetUnset( $offset ) {}
|
public function offsetUnset( $offset ) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* offsetExists
|
* OffsetExists.
|
||||||
* @param string $offset
|
*
|
||||||
|
* @param string $offset Offset.
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function offsetExists( $offset ) {
|
public function offsetExists( $offset ) {
|
||||||
return in_array( $offset, array_keys( $this->data ) );
|
return in_array( $offset, array_keys( $this->data ), true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,17 @@
|
||||||
<?php
|
<?php
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* External Product Class.
|
* External Product
|
||||||
*
|
*
|
||||||
* External products cannot be bought; they link offsite. Extends simple products.
|
* External products cannot be bought; they link offsite. Extends simple products.
|
||||||
*
|
*
|
||||||
* @class WC_Product_External
|
|
||||||
* @version 3.0.0
|
|
||||||
* @package WooCommerce/Classes/Products
|
* @package WooCommerce/Classes/Products
|
||||||
* @category Class
|
* @version 3.0.0
|
||||||
* @author WooThemes
|
*/
|
||||||
|
|
||||||
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Product external class.
|
||||||
*/
|
*/
|
||||||
class WC_Product_External extends WC_Product {
|
class WC_Product_External extends WC_Product {
|
||||||
|
|
||||||
|
@ -28,6 +27,7 @@ class WC_Product_External extends WC_Product {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get internal type.
|
* Get internal type.
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_type() {
|
public function get_type() {
|
||||||
|
@ -45,7 +45,7 @@ class WC_Product_External extends WC_Product {
|
||||||
/**
|
/**
|
||||||
* Get product url.
|
* Get product url.
|
||||||
*
|
*
|
||||||
* @param string $context
|
* @param string $context What the value is for. Valid values are 'view' and 'edit'.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_product_url( $context = 'view' ) {
|
public function get_product_url( $context = 'view' ) {
|
||||||
|
@ -55,7 +55,7 @@ class WC_Product_External extends WC_Product {
|
||||||
/**
|
/**
|
||||||
* Get button text.
|
* Get button text.
|
||||||
*
|
*
|
||||||
* @param string $context
|
* @param string $context What the value is for. Valid values are 'view' and 'edit'.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_button_text( $context = 'view' ) {
|
public function get_button_text( $context = 'view' ) {
|
||||||
|
@ -96,7 +96,7 @@ class WC_Product_External extends WC_Product {
|
||||||
* External products cannot be stock managed.
|
* External products cannot be stock managed.
|
||||||
*
|
*
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
* @param bool
|
* @param bool $manage_stock If manage stock.
|
||||||
*/
|
*/
|
||||||
public function set_manage_stock( $manage_stock ) {
|
public function set_manage_stock( $manage_stock ) {
|
||||||
$this->set_prop( 'manage_stock', false );
|
$this->set_prop( 'manage_stock', false );
|
||||||
|
@ -111,7 +111,7 @@ class WC_Product_External extends WC_Product {
|
||||||
*
|
*
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*
|
*
|
||||||
* @param string $stock_status
|
* @param string $stock_status Stock status.
|
||||||
*/
|
*/
|
||||||
public function set_stock_status( $stock_status = '' ) {
|
public function set_stock_status( $stock_status = '' ) {
|
||||||
$this->set_prop( 'stock_status', 'instock' );
|
$this->set_prop( 'stock_status', 'instock' );
|
||||||
|
|
|
@ -1,31 +1,31 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
|
||||||
exit; // Exit if accessed directly
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Product Factory Class
|
* Product Factory
|
||||||
*
|
*
|
||||||
* The WooCommerce product factory creating the right product object.
|
* The WooCommerce product factory creating the right product object.
|
||||||
*
|
*
|
||||||
* @class WC_Product_Factory
|
|
||||||
* @version 3.0.0
|
|
||||||
* @package WooCommerce/Classes
|
* @package WooCommerce/Classes
|
||||||
* @category Class
|
* @version 3.0.0
|
||||||
* @author WooThemes
|
*/
|
||||||
|
|
||||||
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Product factory class.
|
||||||
*/
|
*/
|
||||||
class WC_Product_Factory {
|
class WC_Product_Factory {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a product.
|
* Get a product.
|
||||||
*
|
*
|
||||||
* @param mixed $product_id (default: false)
|
* @param mixed $product_id WC_Product|WP_Post|int|bool $product Product instance, post instance, numeric or false to use global $post.
|
||||||
* @param array $deprecated Previously used to pass arguments to the factory, e.g. to force a type.
|
* @param array $deprecated Previously used to pass arguments to the factory, e.g. to force a type.
|
||||||
* @return WC_Product|bool Product object or null if the product cannot be loaded.
|
* @return WC_Product|bool Product object or null if the product cannot be loaded.
|
||||||
*/
|
*/
|
||||||
public function get_product( $product_id = false, $deprecated = array() ) {
|
public function get_product( $product_id = false, $deprecated = array() ) {
|
||||||
if ( ! $product_id = $this->get_product_id( $product_id ) ) {
|
$product_id = $this->get_product_id( $product_id );
|
||||||
|
|
||||||
|
if ( ! $product_id ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,8 +53,8 @@ class WC_Product_Factory {
|
||||||
* Gets a product classname and allows filtering. Returns WC_Product_Simple if the class does not exist.
|
* Gets a product classname and allows filtering. Returns WC_Product_Simple if the class does not exist.
|
||||||
*
|
*
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
* @param int $product_id
|
* @param int $product_id Product ID.
|
||||||
* @param string $product_type
|
* @param string $product_type Product type.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function get_product_classname( $product_id, $product_type ) {
|
public static function get_product_classname( $product_id, $product_type ) {
|
||||||
|
@ -71,7 +71,7 @@ class WC_Product_Factory {
|
||||||
* Get the product type for a product.
|
* Get the product type for a product.
|
||||||
*
|
*
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
* @param int $product_id
|
* @param int $product_id Product ID.
|
||||||
* @return string|false
|
* @return string|false
|
||||||
*/
|
*/
|
||||||
public static function get_product_type( $product_id ) {
|
public static function get_product_type( $product_id ) {
|
||||||
|
@ -87,7 +87,7 @@ class WC_Product_Factory {
|
||||||
/**
|
/**
|
||||||
* Create a WC coding standards compliant class name e.g. WC_Product_Type_Class instead of WC_Product_type-class.
|
* Create a WC coding standards compliant class name e.g. WC_Product_Type_Class instead of WC_Product_type-class.
|
||||||
*
|
*
|
||||||
* @param string $product_type
|
* @param string $product_type Product type.
|
||||||
* @return string|false
|
* @return string|false
|
||||||
*/
|
*/
|
||||||
public static function get_classname_from_product_type( $product_type ) {
|
public static function get_classname_from_product_type( $product_type ) {
|
||||||
|
@ -98,7 +98,7 @@ class WC_Product_Factory {
|
||||||
* Get the product ID depending on what was passed.
|
* Get the product ID depending on what was passed.
|
||||||
*
|
*
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
* @param mixed $product
|
* @param WC_Product|WP_Post|int|bool $product Product instance, post instance, numeric or false to use global $post.
|
||||||
* @return int|bool false on failure
|
* @return int|bool false on failure
|
||||||
*/
|
*/
|
||||||
private function get_product_id( $product ) {
|
private function get_product_id( $product ) {
|
||||||
|
|
|
@ -1,22 +1,17 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Class WC_Product_Grouped file.
|
* Grouped Product
|
||||||
*
|
|
||||||
* @package WooCommerce\Classes\Products
|
|
||||||
*/
|
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Grouped Product Class.
|
|
||||||
*
|
*
|
||||||
* Grouped products cannot be purchased - they are wrappers for other products.
|
* Grouped products cannot be purchased - they are wrappers for other products.
|
||||||
*
|
*
|
||||||
* @class WC_Product_Grouped
|
* @package WooCommerce\Classes\Products
|
||||||
* @version 3.0.0
|
* @version 3.0.0
|
||||||
* @package WooCommerce/Classes/Products
|
*/
|
||||||
|
|
||||||
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Product grouped class.
|
||||||
*/
|
*/
|
||||||
class WC_Product_Grouped extends WC_Product {
|
class WC_Product_Grouped extends WC_Product {
|
||||||
|
|
||||||
|
@ -41,7 +36,6 @@ class WC_Product_Grouped extends WC_Product {
|
||||||
/**
|
/**
|
||||||
* Get the add to cart button text.
|
* Get the add to cart button text.
|
||||||
*
|
*
|
||||||
* @access public
|
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function add_to_cart_text() {
|
public function add_to_cart_text() {
|
||||||
|
@ -91,7 +85,6 @@ class WC_Product_Grouped extends WC_Product {
|
||||||
/**
|
/**
|
||||||
* Returns the price in html format.
|
* Returns the price in html format.
|
||||||
*
|
*
|
||||||
* @access public
|
|
||||||
* @param string $price (default: '').
|
* @param string $price (default: '').
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,21 +1,24 @@
|
||||||
<?php
|
<?php
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for parameter-based Product querying.
|
* Class for parameter-based Product querying
|
||||||
|
*
|
||||||
* Args and usage: https://github.com/woocommerce/woocommerce/wiki/wc_get_products-and-WC_Product_Query
|
* Args and usage: https://github.com/woocommerce/woocommerce/wiki/wc_get_products-and-WC_Product_Query
|
||||||
*
|
*
|
||||||
|
* @package WooCommerce/Classes
|
||||||
* @version 3.2.0
|
* @version 3.2.0
|
||||||
* @since 3.2.0
|
* @since 3.2.0
|
||||||
* @package WooCommerce/Classes
|
*/
|
||||||
* @category Class
|
|
||||||
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Product query class.
|
||||||
*/
|
*/
|
||||||
class WC_Product_Query extends WC_Object_Query {
|
class WC_Product_Query extends WC_Object_Query {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Valid query vars for products.
|
* Valid query vars for products.
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function get_default_query_vars() {
|
protected function get_default_query_vars() {
|
||||||
|
@ -64,6 +67,7 @@ class WC_Product_Query extends WC_Object_Query {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get products matching the current query vars.
|
* Get products matching the current query vars.
|
||||||
|
*
|
||||||
* @return array|object of WC_Product objects
|
* @return array|object of WC_Product objects
|
||||||
*/
|
*/
|
||||||
public function get_products() {
|
public function get_products() {
|
||||||
|
|
|
@ -1,25 +1,23 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
|
||||||
exit; // Exit if accessed directly
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple Product Class.
|
* Simple Product Class.
|
||||||
*
|
*
|
||||||
* The default product type kinda product.
|
* The default product type kinda product.
|
||||||
*
|
*
|
||||||
* @class WC_Product_Simple
|
|
||||||
* @package WooCommerce/Classes/Products
|
* @package WooCommerce/Classes/Products
|
||||||
* @category Class
|
*/
|
||||||
* @author WooThemes
|
|
||||||
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple product class.
|
||||||
*/
|
*/
|
||||||
class WC_Product_Simple extends WC_Product {
|
class WC_Product_Simple extends WC_Product {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize simple product.
|
* Initialize simple product.
|
||||||
*
|
*
|
||||||
* @param mixed $product
|
* @param WC_Product|int $product Product instance or ID.
|
||||||
*/
|
*/
|
||||||
public function __construct( $product = 0 ) {
|
public function __construct( $product = 0 ) {
|
||||||
$this->supports[] = 'ajax_add_to_cart';
|
$this->supports[] = 'ajax_add_to_cart';
|
||||||
|
@ -28,6 +26,7 @@ class WC_Product_Simple extends WC_Product {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get internal type.
|
* Get internal type.
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_type() {
|
public function get_type() {
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
<?php
|
<?php
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Variable Product Class.
|
* Variable Product
|
||||||
*
|
*
|
||||||
* The WooCommerce product class handles individual product data.
|
* The WooCommerce product class handles individual product data.
|
||||||
*
|
*
|
||||||
* @version 3.0.0
|
* @version 3.0.0
|
||||||
* @package WooCommerce/Classes/Products
|
* @package WooCommerce/Classes/Products
|
||||||
* @category Class
|
*/
|
||||||
* @author WooThemes
|
|
||||||
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Variable product class.
|
||||||
*/
|
*/
|
||||||
class WC_Product_Variable extends WC_Product {
|
class WC_Product_Variable extends WC_Product {
|
||||||
|
|
||||||
|
@ -75,7 +75,6 @@ class WC_Product_Variable extends WC_Product {
|
||||||
* Get an array of all sale and regular prices from all variations. This is used for example when displaying the price range at variable product level or seeing if the variable product is on sale.
|
* Get an array of all sale and regular prices from all variations. This is used for example when displaying the price range at variable product level or seeing if the variable product is on sale.
|
||||||
*
|
*
|
||||||
* @param bool $for_display If true, prices will be adapted for display based on the `woocommerce_tax_display_shop` setting (including or excluding taxes).
|
* @param bool $for_display If true, prices will be adapted for display based on the `woocommerce_tax_display_shop` setting (including or excluding taxes).
|
||||||
*
|
|
||||||
* @return array Array of RAW prices, regular prices, and sale prices with keys set to variation ID.
|
* @return array Array of RAW prices, regular prices, and sale prices with keys set to variation ID.
|
||||||
*/
|
*/
|
||||||
public function get_variation_prices( $for_display = false ) {
|
public function get_variation_prices( $for_display = false ) {
|
||||||
|
@ -93,7 +92,6 @@ class WC_Product_Variable extends WC_Product {
|
||||||
*
|
*
|
||||||
* @param string $min_or_max Min or max price.
|
* @param string $min_or_max Min or max price.
|
||||||
* @param boolean $for_display If true, prices will be adapted for display based on the `woocommerce_tax_display_shop` setting (including or excluding taxes).
|
* @param boolean $for_display If true, prices will be adapted for display based on the `woocommerce_tax_display_shop` setting (including or excluding taxes).
|
||||||
*
|
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_variation_regular_price( $min_or_max = 'min', $for_display = false ) {
|
public function get_variation_regular_price( $min_or_max = 'min', $for_display = false ) {
|
||||||
|
@ -108,7 +106,6 @@ class WC_Product_Variable extends WC_Product {
|
||||||
*
|
*
|
||||||
* @param string $min_or_max Min or max price.
|
* @param string $min_or_max Min or max price.
|
||||||
* @param boolean $for_display If true, prices will be adapted for display based on the `woocommerce_tax_display_shop` setting (including or excluding taxes).
|
* @param boolean $for_display If true, prices will be adapted for display based on the `woocommerce_tax_display_shop` setting (including or excluding taxes).
|
||||||
*
|
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_variation_sale_price( $min_or_max = 'min', $for_display = false ) {
|
public function get_variation_sale_price( $min_or_max = 'min', $for_display = false ) {
|
||||||
|
@ -123,7 +120,6 @@ class WC_Product_Variable extends WC_Product {
|
||||||
*
|
*
|
||||||
* @param string $min_or_max Min or max price.
|
* @param string $min_or_max Min or max price.
|
||||||
* @param boolean $for_display If true, prices will be adapted for display based on the `woocommerce_tax_display_shop` setting (including or excluding taxes).
|
* @param boolean $for_display If true, prices will be adapted for display based on the `woocommerce_tax_display_shop` setting (including or excluding taxes).
|
||||||
*
|
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_variation_price( $min_or_max = 'min', $for_display = false ) {
|
public function get_variation_price( $min_or_max = 'min', $for_display = false ) {
|
||||||
|
@ -146,8 +142,7 @@ class WC_Product_Variable extends WC_Product {
|
||||||
* due to the strings being very long and unclear/confusing. A single range
|
* due to the strings being very long and unclear/confusing. A single range
|
||||||
* is shown instead.
|
* is shown instead.
|
||||||
*
|
*
|
||||||
* @param string $price (default: '')
|
* @param string $price Price (default: '').
|
||||||
*
|
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_price_html( $price = '' ) {
|
public function get_price_html( $price = '' ) {
|
||||||
|
@ -180,11 +175,10 @@ class WC_Product_Variable extends WC_Product {
|
||||||
*
|
*
|
||||||
* This is skipped if the suffix
|
* This is skipped if the suffix
|
||||||
* has dynamic values such as {price_excluding_tax} for variable products.
|
* has dynamic values such as {price_excluding_tax} for variable products.
|
||||||
|
*
|
||||||
* @see get_price_html for an explanation as to why.
|
* @see get_price_html for an explanation as to why.
|
||||||
*
|
* @param string $price Price to calculate, left blank to just use get_price().
|
||||||
* @param string $price to calculate, left blank to just use get_price()
|
* @param integer $qty Quantity passed on to get_price_including_tax() or get_price_excluding_tax().
|
||||||
* @param integer $qty passed on to get_price_including_tax() or get_price_excluding_tax()
|
|
||||||
*
|
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_price_suffix( $price = '', $qty = 1 ) {
|
public function get_price_suffix( $price = '', $qty = 1 ) {
|
||||||
|
@ -200,8 +194,7 @@ class WC_Product_Variable extends WC_Product {
|
||||||
/**
|
/**
|
||||||
* Return a products child ids.
|
* Return a products child ids.
|
||||||
*
|
*
|
||||||
* @param bool|string $visible_only
|
* @param bool|string $visible_only Visible only.
|
||||||
*
|
|
||||||
* @return array Children ids
|
* @return array Children ids
|
||||||
*/
|
*/
|
||||||
public function get_children( $visible_only = '' ) {
|
public function get_children( $visible_only = '' ) {
|
||||||
|
@ -236,8 +229,7 @@ class WC_Product_Variable extends WC_Product {
|
||||||
/**
|
/**
|
||||||
* If set, get the default attributes for a variable product.
|
* If set, get the default attributes for a variable product.
|
||||||
*
|
*
|
||||||
* @param string $attribute_name
|
* @param string $attribute_name Attribute name.
|
||||||
*
|
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_variation_default_attribute( $attribute_name ) {
|
public function get_variation_default_attribute( $attribute_name ) {
|
||||||
|
@ -250,8 +242,7 @@ class WC_Product_Variable extends WC_Product {
|
||||||
/**
|
/**
|
||||||
* Variable products themselves cannot be downloadable.
|
* Variable products themselves cannot be downloadable.
|
||||||
*
|
*
|
||||||
* @param string $context
|
* @param string $context What the value is for. Valid values are view and edit.
|
||||||
*
|
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function get_downloadable( $context = 'view' ) {
|
public function get_downloadable( $context = 'view' ) {
|
||||||
|
@ -261,8 +252,7 @@ class WC_Product_Variable extends WC_Product {
|
||||||
/**
|
/**
|
||||||
* Variable products themselves cannot be virtual.
|
* Variable products themselves cannot be virtual.
|
||||||
*
|
*
|
||||||
* @param string $context
|
* @param string $context What the value is for. Valid values are view and edit.
|
||||||
*
|
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function get_virtual( $context = 'view' ) {
|
public function get_virtual( $context = 'view' ) {
|
||||||
|
@ -280,7 +270,7 @@ class WC_Product_Variable extends WC_Product {
|
||||||
foreach ( $this->get_children() as $child_id ) {
|
foreach ( $this->get_children() as $child_id ) {
|
||||||
$variation = wc_get_product( $child_id );
|
$variation = wc_get_product( $child_id );
|
||||||
|
|
||||||
// Hide out of stock variations if 'Hide out of stock items from the catalog' is checked
|
// Hide out of stock variations if 'Hide out of stock items from the catalog' is checked.
|
||||||
if ( ! $variation || ! $variation->exists() || ( 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) && ! $variation->is_in_stock() ) ) {
|
if ( ! $variation || ! $variation->exists() || ( 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) && ! $variation->is_in_stock() ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -299,10 +289,9 @@ class WC_Product_Variable extends WC_Product {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of data for a variation. Used in the add to cart form.
|
* Returns an array of data for a variation. Used in the add to cart form.
|
||||||
|
*
|
||||||
* @since 2.4.0
|
* @since 2.4.0
|
||||||
*
|
* @param WC_Product $variation Variation product object or ID.
|
||||||
* @param WC_Product $variation Variation product object or ID
|
|
||||||
*
|
|
||||||
* @return array|bool
|
* @return array|bool
|
||||||
*/
|
*/
|
||||||
public function get_available_variation( $variation ) {
|
public function get_available_variation( $variation ) {
|
||||||
|
@ -313,9 +302,10 @@ class WC_Product_Variable extends WC_Product {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// See if prices should be shown for each variation after selection.
|
// See if prices should be shown for each variation after selection.
|
||||||
$show_variation_price = apply_filters( 'woocommerce_show_variation_price', $variation->get_price() === "" || $this->get_variation_sale_price( 'min' ) !== $this->get_variation_sale_price( 'max' ) || $this->get_variation_regular_price( 'min' ) !== $this->get_variation_regular_price( 'max' ), $this, $variation );
|
$show_variation_price = apply_filters( 'woocommerce_show_variation_price', $variation->get_price() === '' || $this->get_variation_sale_price( 'min' ) !== $this->get_variation_sale_price( 'max' ) || $this->get_variation_regular_price( 'min' ) !== $this->get_variation_regular_price( 'max' ), $this, $variation );
|
||||||
|
|
||||||
return apply_filters( 'woocommerce_available_variation', array(
|
return apply_filters(
|
||||||
|
'woocommerce_available_variation', array(
|
||||||
'attributes' => $variation->get_variation_attributes(),
|
'attributes' => $variation->get_variation_attributes(),
|
||||||
'availability_html' => wc_get_stock_html( $variation ),
|
'availability_html' => wc_get_stock_html( $variation ),
|
||||||
'backorders_allowed' => $variation->backorders_allowed(),
|
'backorders_allowed' => $variation->backorders_allowed(),
|
||||||
|
@ -340,7 +330,8 @@ class WC_Product_Variable extends WC_Product {
|
||||||
'variation_is_visible' => $variation->variation_is_visible(),
|
'variation_is_visible' => $variation->variation_is_visible(),
|
||||||
'weight' => $variation->get_weight(),
|
'weight' => $variation->get_weight(),
|
||||||
'weight_html' => wc_format_weight( $variation->get_weight() ),
|
'weight_html' => wc_format_weight( $variation->get_weight() ),
|
||||||
), $this, $variation );
|
), $this, $variation
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -353,8 +344,7 @@ class WC_Product_Variable extends WC_Product {
|
||||||
* Sets an array of variation attributes.
|
* Sets an array of variation attributes.
|
||||||
*
|
*
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*
|
* @param array $variation_attributes Attributes list.
|
||||||
* @param array
|
|
||||||
*/
|
*/
|
||||||
public function set_variation_attributes( $variation_attributes ) {
|
public function set_variation_attributes( $variation_attributes ) {
|
||||||
$this->variation_attributes = $variation_attributes;
|
$this->variation_attributes = $variation_attributes;
|
||||||
|
@ -364,8 +354,7 @@ class WC_Product_Variable extends WC_Product {
|
||||||
* Sets an array of children for the product.
|
* Sets an array of children for the product.
|
||||||
*
|
*
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*
|
* @param array $children Childre products.
|
||||||
* @param array
|
|
||||||
*/
|
*/
|
||||||
public function set_children( $children ) {
|
public function set_children( $children ) {
|
||||||
$this->children = array_filter( wp_parse_id_list( (array) $children ) );
|
$this->children = array_filter( wp_parse_id_list( (array) $children ) );
|
||||||
|
@ -375,8 +364,7 @@ class WC_Product_Variable extends WC_Product {
|
||||||
* Sets an array of visible children only.
|
* Sets an array of visible children only.
|
||||||
*
|
*
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*
|
* @param array $visible_children List of visible children products.
|
||||||
* @param array
|
|
||||||
*/
|
*/
|
||||||
public function set_visible_children( $visible_children ) {
|
public function set_visible_children( $visible_children ) {
|
||||||
$this->visible_children = array_filter( wp_parse_id_list( (array) $visible_children ) );
|
$this->visible_children = array_filter( wp_parse_id_list( (array) $visible_children ) );
|
||||||
|
@ -390,6 +378,7 @@ class WC_Product_Variable extends WC_Product {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensure properties are set correctly before save.
|
* Ensure properties are set correctly before save.
|
||||||
|
*
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public function validate_props() {
|
public function validate_props() {
|
||||||
|
@ -454,8 +443,7 @@ class WC_Product_Variable extends WC_Product {
|
||||||
/**
|
/**
|
||||||
* Returns whether or not the product is on sale.
|
* Returns whether or not the product is on sale.
|
||||||
*
|
*
|
||||||
* @param string $context What the value is for. Valid values are view and edit.
|
* @param string $context What the value is for. Valid values are view and edit. What the value is for. Valid values are view and edit.
|
||||||
*
|
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function is_on_sale( $context = 'view' ) {
|
public function is_on_sale( $context = 'view' ) {
|
||||||
|
@ -467,6 +455,7 @@ class WC_Product_Variable extends WC_Product {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is a child in stock?
|
* Is a child in stock?
|
||||||
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function child_is_in_stock() {
|
public function child_is_in_stock() {
|
||||||
|
@ -485,6 +474,7 @@ class WC_Product_Variable extends WC_Product {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does a child have a weight set?
|
* Does a child have a weight set?
|
||||||
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function child_has_weight() {
|
public function child_has_weight() {
|
||||||
|
@ -501,6 +491,7 @@ class WC_Product_Variable extends WC_Product {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does a child have dimensions set?
|
* Does a child have dimensions set?
|
||||||
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function child_has_dimensions() {
|
public function child_has_dimensions() {
|
||||||
|
@ -556,7 +547,6 @@ class WC_Product_Variable extends WC_Product {
|
||||||
*
|
*
|
||||||
* @param WC_Product|int $product Product object or ID for which you wish to sync.
|
* @param WC_Product|int $product Product object or ID for which you wish to sync.
|
||||||
* @param bool $save If true, the product object will be saved to the DB before returning it.
|
* @param bool $save If true, the product object will be saved to the DB before returning it.
|
||||||
*
|
|
||||||
* @return WC_Product Synced product object.
|
* @return WC_Product Synced product object.
|
||||||
*/
|
*/
|
||||||
public static function sync( $product, $save = true ) {
|
public static function sync( $product, $save = true ) {
|
||||||
|
@ -575,10 +565,12 @@ class WC_Product_Variable extends WC_Product {
|
||||||
$product->save();
|
$product->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
wc_do_deprecated_action( 'woocommerce_variable_product_sync', array(
|
wc_do_deprecated_action(
|
||||||
|
'woocommerce_variable_product_sync', array(
|
||||||
$product->get_id(),
|
$product->get_id(),
|
||||||
$product->get_visible_children()
|
$product->get_visible_children(),
|
||||||
), '3.0', 'woocommerce_variable_product_sync_data, woocommerce_new_product or woocommerce_update_product' );
|
), '3.0', 'woocommerce_variable_product_sync_data, woocommerce_new_product or woocommerce_update_product'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $product;
|
return $product;
|
||||||
|
@ -589,7 +581,6 @@ class WC_Product_Variable extends WC_Product {
|
||||||
*
|
*
|
||||||
* @param WC_Product|int $product Product object or ID for which you wish to sync.
|
* @param WC_Product|int $product Product object or ID for which you wish to sync.
|
||||||
* @param bool $save If true, the product object will be saved to the DB before returning it.
|
* @param bool $save If true, the product object will be saved to the DB before returning it.
|
||||||
*
|
|
||||||
* @return WC_Product Synced product object.
|
* @return WC_Product Synced product object.
|
||||||
*/
|
*/
|
||||||
public static function sync_stock_status( $product, $save = true ) {
|
public static function sync_stock_status( $product, $save = true ) {
|
||||||
|
@ -611,8 +602,7 @@ class WC_Product_Variable extends WC_Product {
|
||||||
/**
|
/**
|
||||||
* Sort an associativate array of $variation_id => $price pairs in order of min and max prices.
|
* Sort an associativate array of $variation_id => $price pairs in order of min and max prices.
|
||||||
*
|
*
|
||||||
* @param array $prices Associativate array of $variation_id => $price pairs
|
* @param array $prices Associativate array of $variation_id => $price pairs.
|
||||||
*
|
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function sort_variation_prices( $prices ) {
|
protected function sort_variation_prices( $prices ) {
|
||||||
|
|
|
@ -1,24 +1,17 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* WooCommerce product variation class.
|
* Product Variation
|
||||||
*
|
|
||||||
* @package WooCommerce/Classes
|
|
||||||
*/
|
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Product Variation Class.
|
|
||||||
*
|
*
|
||||||
* The WooCommerce product variation class handles product variation data.
|
* The WooCommerce product variation class handles product variation data.
|
||||||
*
|
*
|
||||||
* @class WC_Product_Variation
|
|
||||||
* @version 3.0.0
|
|
||||||
* @package WooCommerce/Classes
|
* @package WooCommerce/Classes
|
||||||
* @category Class
|
* @version 3.0.0
|
||||||
* @author WooThemes
|
*/
|
||||||
|
|
||||||
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Product variation class.
|
||||||
*/
|
*/
|
||||||
class WC_Product_Variation extends WC_Product_Simple {
|
class WC_Product_Variation extends WC_Product_Simple {
|
||||||
|
|
||||||
|
@ -182,7 +175,14 @@ class WC_Product_Variation extends WC_Product_Simple {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function add_to_cart_url() {
|
public function add_to_cart_url() {
|
||||||
$url = $this->is_purchasable() ? remove_query_arg( 'added-to-cart', add_query_arg( array( 'variation_id' => $this->get_id(), 'add-to-cart' => $this->get_parent_id() ), $this->get_permalink() ) ) : $this->get_permalink();
|
$url = $this->is_purchasable() ? remove_query_arg(
|
||||||
|
'added-to-cart', add_query_arg(
|
||||||
|
array(
|
||||||
|
'variation_id' => $this->get_id(),
|
||||||
|
'add-to-cart' => $this->get_parent_id(),
|
||||||
|
), $this->get_permalink()
|
||||||
|
)
|
||||||
|
) : $this->get_permalink();
|
||||||
return apply_filters( 'woocommerce_product_add_to_cart_url', $url, $this );
|
return apply_filters( 'woocommerce_product_add_to_cart_url', $url, $this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,17 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
|
||||||
exit; // Exit if accessed directly
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WooCommerce Shipping Rate Class.
|
* WooCommerce Shipping Rate
|
||||||
*
|
*
|
||||||
* Simple Class for storing rates.
|
* Simple Class for storing rates.
|
||||||
*
|
*
|
||||||
* @class WC_Shipping_Rate
|
|
||||||
* @package WooCommerce/Classes/Shipping
|
* @package WooCommerce/Classes/Shipping
|
||||||
* @category Class
|
* @since 2.6.0
|
||||||
* @author Automattic
|
*/
|
||||||
|
|
||||||
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shipping rate class.
|
||||||
*/
|
*/
|
||||||
class WC_Shipping_Rate {
|
class WC_Shipping_Rate {
|
||||||
|
|
||||||
|
@ -42,12 +41,12 @@ class WC_Shipping_Rate {
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param string $id
|
* @param string $id Shipping rate ID.
|
||||||
* @param string $label
|
* @param string $label Shipping rate label.
|
||||||
* @param integer $cost
|
* @param integer $cost Cost.
|
||||||
* @param array $taxes
|
* @param array $taxes Taxes applied to shipping rate.
|
||||||
* @param string $method_id
|
* @param string $method_id Shipping method ID.
|
||||||
* @param int $instance_id
|
* @param int $instance_id Shipping instance ID.
|
||||||
*/
|
*/
|
||||||
public function __construct( $id = '', $label = '', $cost = 0, $taxes = array(), $method_id = '', $instance_id = 0 ) {
|
public function __construct( $id = '', $label = '', $cost = 0, $taxes = array(), $method_id = '', $instance_id = 0 ) {
|
||||||
$this->set_id( $id );
|
$this->set_id( $id );
|
||||||
|
@ -62,7 +61,7 @@ class WC_Shipping_Rate {
|
||||||
* Magic methods to support direct access to props.
|
* Magic methods to support direct access to props.
|
||||||
*
|
*
|
||||||
* @since 3.2.0
|
* @since 3.2.0
|
||||||
* @param string $key
|
* @param string $key Key.
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function __isset( $key ) {
|
public function __isset( $key ) {
|
||||||
|
@ -73,7 +72,7 @@ class WC_Shipping_Rate {
|
||||||
* Magic methods to support direct access to props.
|
* Magic methods to support direct access to props.
|
||||||
*
|
*
|
||||||
* @since 3.2.0
|
* @since 3.2.0
|
||||||
* @param string $key
|
* @param string $key Key.
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function __get( $key ) {
|
public function __get( $key ) {
|
||||||
|
@ -90,8 +89,8 @@ class WC_Shipping_Rate {
|
||||||
* Magic methods to support direct access to props.
|
* Magic methods to support direct access to props.
|
||||||
*
|
*
|
||||||
* @since 3.2.0
|
* @since 3.2.0
|
||||||
* @param string $key
|
* @param string $key Key.
|
||||||
* @param mixed $value
|
* @param mixed $value Value.
|
||||||
*/
|
*/
|
||||||
public function __set( $key, $value ) {
|
public function __set( $key, $value ) {
|
||||||
if ( is_callable( array( $this, "set_{$key}" ) ) ) {
|
if ( is_callable( array( $this, "set_{$key}" ) ) ) {
|
||||||
|
@ -105,7 +104,7 @@ class WC_Shipping_Rate {
|
||||||
* Set ID for the rate. This is usually a combination of the method and instance IDs.
|
* Set ID for the rate. This is usually a combination of the method and instance IDs.
|
||||||
*
|
*
|
||||||
* @since 3.2.0
|
* @since 3.2.0
|
||||||
* @param string $id
|
* @param string $id Shipping rate ID.
|
||||||
*/
|
*/
|
||||||
public function set_id( $id ) {
|
public function set_id( $id ) {
|
||||||
$this->data['id'] = (string) $id;
|
$this->data['id'] = (string) $id;
|
||||||
|
@ -115,7 +114,7 @@ class WC_Shipping_Rate {
|
||||||
* Set shipping method ID the rate belongs to.
|
* Set shipping method ID the rate belongs to.
|
||||||
*
|
*
|
||||||
* @since 3.2.0
|
* @since 3.2.0
|
||||||
* @param string $method_id
|
* @param string $method_id Shipping method ID.
|
||||||
*/
|
*/
|
||||||
public function set_method_id( $method_id ) {
|
public function set_method_id( $method_id ) {
|
||||||
$this->data['method_id'] = (string) $method_id;
|
$this->data['method_id'] = (string) $method_id;
|
||||||
|
@ -125,7 +124,7 @@ class WC_Shipping_Rate {
|
||||||
* Set instance ID the rate belongs to.
|
* Set instance ID the rate belongs to.
|
||||||
*
|
*
|
||||||
* @since 3.2.0
|
* @since 3.2.0
|
||||||
* @param int $instance_id
|
* @param int $instance_id Instance ID.
|
||||||
*/
|
*/
|
||||||
public function set_instance_id( $instance_id ) {
|
public function set_instance_id( $instance_id ) {
|
||||||
$this->data['instance_id'] = absint( $instance_id );
|
$this->data['instance_id'] = absint( $instance_id );
|
||||||
|
@ -135,7 +134,7 @@ class WC_Shipping_Rate {
|
||||||
* Set rate label.
|
* Set rate label.
|
||||||
*
|
*
|
||||||
* @since 3.2.0
|
* @since 3.2.0
|
||||||
* @param string $method_id
|
* @param string $label Shipping rate label.
|
||||||
*/
|
*/
|
||||||
public function set_label( $label ) {
|
public function set_label( $label ) {
|
||||||
$this->data['label'] = (string) $label;
|
$this->data['label'] = (string) $label;
|
||||||
|
@ -146,7 +145,7 @@ class WC_Shipping_Rate {
|
||||||
*
|
*
|
||||||
* @todo 4.0 Prevent negative value being set. #19293
|
* @todo 4.0 Prevent negative value being set. #19293
|
||||||
* @since 3.2.0
|
* @since 3.2.0
|
||||||
* @param string $cost
|
* @param string $cost Shipping rate cost.
|
||||||
*/
|
*/
|
||||||
public function set_cost( $cost ) {
|
public function set_cost( $cost ) {
|
||||||
$this->data['cost'] = $cost;
|
$this->data['cost'] = $cost;
|
||||||
|
@ -156,7 +155,7 @@ class WC_Shipping_Rate {
|
||||||
* Set rate taxes.
|
* Set rate taxes.
|
||||||
*
|
*
|
||||||
* @since 3.2.0
|
* @since 3.2.0
|
||||||
* @param array $taxes
|
* @param array $taxes List of taxes applied to shipping rate.
|
||||||
*/
|
*/
|
||||||
public function set_taxes( $taxes ) {
|
public function set_taxes( $taxes ) {
|
||||||
$this->data['taxes'] = ! empty( $taxes ) && is_array( $taxes ) ? $taxes : array();
|
$this->data['taxes'] = ! empty( $taxes ) && is_array( $taxes ) ? $taxes : array();
|
||||||
|
@ -227,15 +226,15 @@ class WC_Shipping_Rate {
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get_shipping_tax() {
|
public function get_shipping_tax() {
|
||||||
return apply_filters( 'woocommerce_get_shipping_tax', sizeof( $this->taxes ) > 0 && ! WC()->customer->get_is_vat_exempt() ? array_sum( $this->taxes ) : 0, $this );
|
return apply_filters( 'woocommerce_get_shipping_tax', count( $this->taxes ) > 0 && ! WC()->customer->get_is_vat_exempt() ? array_sum( $this->taxes ) : 0, $this );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add some meta data for this rate.
|
* Add some meta data for this rate.
|
||||||
*
|
*
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
* @param string $key
|
* @param string $key Key.
|
||||||
* @param string $value
|
* @param string $value Value.
|
||||||
*/
|
*/
|
||||||
public function add_meta_data( $key, $value ) {
|
public function add_meta_data( $key, $value ) {
|
||||||
$this->meta_data[ wc_clean( $key ) ] = wc_clean( $value );
|
$this->meta_data[ wc_clean( $key ) ] = wc_clean( $value );
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* WooCommerce Shipping Class
|
* WooCommerce Shipping
|
||||||
*
|
*
|
||||||
* Handles shipping and loads shipping methods via hooks.
|
* Handles shipping and loads shipping methods via hooks.
|
||||||
*
|
*
|
||||||
* @class WC_Shipping
|
|
||||||
* @version 2.6.0
|
* @version 2.6.0
|
||||||
* @package WooCommerce/Classes/Shipping
|
* @package WooCommerce/Classes/Shipping
|
||||||
*/
|
*/
|
||||||
|
@ -14,7 +13,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WC_Shipping
|
* Shipping class.
|
||||||
*/
|
*/
|
||||||
class WC_Shipping {
|
class WC_Shipping {
|
||||||
|
|
||||||
|
@ -60,7 +59,6 @@ class WC_Shipping {
|
||||||
* Ensures only one instance of WC_Shipping is loaded or can be loaded.
|
* Ensures only one instance of WC_Shipping is loaded or can be loaded.
|
||||||
*
|
*
|
||||||
* @since 2.1
|
* @since 2.1
|
||||||
* @static
|
|
||||||
* @return WC_Shipping Main instance
|
* @return WC_Shipping Main instance
|
||||||
*/
|
*/
|
||||||
public static function instance() {
|
public static function instance() {
|
||||||
|
|
|
@ -603,7 +603,7 @@ class WC_Tax {
|
||||||
$compound = $key_or_rate->tax_rate_compound;
|
$compound = $key_or_rate->tax_rate_compound;
|
||||||
} else {
|
} else {
|
||||||
$key = $key_or_rate;
|
$key = $key_or_rate;
|
||||||
$compound = $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate_compound FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_id = %s", $key ) ) ? true : false;
|
$compound = (bool) $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate_compound FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_id = %s", $key ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
return (bool) apply_filters( 'woocommerce_rate_compound', $compound, $key );
|
return (bool) apply_filters( 'woocommerce_rate_compound', $compound, $key );
|
||||||
|
|
|
@ -181,7 +181,7 @@ class WC_CLI_Runner {
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'type' => 'assoc',
|
'type' => 'assoc',
|
||||||
'description' => ! empty( $args['description'] ) ? $args['description'] : '',
|
'description' => ! empty( $args['description'] ) ? $args['description'] : '',
|
||||||
'optional' => empty( $args['required'] ) ? true : false,
|
'optional' => empty( $args['required'] ),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ class WC_Gateway_COD extends WC_Payment_Gateway {
|
||||||
$this->description = $this->get_option( 'description' );
|
$this->description = $this->get_option( 'description' );
|
||||||
$this->instructions = $this->get_option( 'instructions' );
|
$this->instructions = $this->get_option( 'instructions' );
|
||||||
$this->enable_for_methods = $this->get_option( 'enable_for_methods', array() );
|
$this->enable_for_methods = $this->get_option( 'enable_for_methods', array() );
|
||||||
$this->enable_for_virtual = $this->get_option( 'enable_for_virtual', 'yes' ) === 'yes' ? true : false;
|
$this->enable_for_virtual = $this->get_option( 'enable_for_virtual', 'yes' ) === 'yes';
|
||||||
|
|
||||||
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
|
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
|
||||||
add_action( 'woocommerce_thankyou_' . $this->id, array( $this, 'thankyou_page' ) );
|
add_action( 'woocommerce_thankyou_' . $this->id, array( $this, 'thankyou_page' ) );
|
||||||
|
|
|
@ -65,7 +65,7 @@ abstract class WC_Legacy_Coupon extends WC_Data {
|
||||||
$value = $this->get_id();
|
$value = $this->get_id();
|
||||||
break;
|
break;
|
||||||
case 'exists' :
|
case 'exists' :
|
||||||
$value = ( $this->get_id() > 0 ) ? true : false;
|
$value = $this->get_id() > 0;
|
||||||
break;
|
break;
|
||||||
case 'coupon_custom_fields' :
|
case 'coupon_custom_fields' :
|
||||||
$legacy_custom_fields = array();
|
$legacy_custom_fields = array();
|
||||||
|
|
|
@ -201,7 +201,7 @@ abstract class WP_Background_Process extends WP_Async_Request {
|
||||||
WHERE {$column} LIKE %s
|
WHERE {$column} LIKE %s
|
||||||
", $key ) );
|
", $key ) );
|
||||||
|
|
||||||
return ( $count > 0 ) ? false : true;
|
return ! ( $count > 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -241,7 +241,7 @@ class WC_Shortcode_Checkout {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
$non_js_checkout = ! empty( $_POST['woocommerce_checkout_update_totals'] ) ? true : false; // WPCS: input var ok, CSRF ok.
|
$non_js_checkout = ! empty( $_POST['woocommerce_checkout_update_totals'] ); // WPCS: input var ok, CSRF ok.
|
||||||
|
|
||||||
if ( wc_notice_count( 'error' ) === 0 && $non_js_checkout ) {
|
if ( wc_notice_count( 'error' ) === 0 && $non_js_checkout ) {
|
||||||
wc_add_notice( __( 'The order totals have been updated. Please confirm your order by pressing the "Place order" button at the bottom of the page.', 'woocommerce' ) );
|
wc_add_notice( __( 'The order totals have been updated. Please confirm your order by pressing the "Place order" button at the bottom of the page.', 'woocommerce' ) );
|
||||||
|
|
|
@ -18,7 +18,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function is_woocommerce() {
|
function is_woocommerce() {
|
||||||
return apply_filters( 'is_woocommerce', ( is_shop() || is_product_taxonomy() || is_product() ) ? true : false );
|
return apply_filters( 'is_woocommerce', is_shop() || is_product_taxonomy() || is_product() );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! function_exists( 'is_shop' ) ) {
|
if ( ! function_exists( 'is_shop' ) ) {
|
||||||
|
|
|
@ -2456,7 +2456,7 @@ if ( ! function_exists( 'wc_dropdown_variation_attribute_options' ) ) {
|
||||||
$name = $args['name'] ? $args['name'] : 'attribute_' . sanitize_title( $attribute );
|
$name = $args['name'] ? $args['name'] : 'attribute_' . sanitize_title( $attribute );
|
||||||
$id = $args['id'] ? $args['id'] : sanitize_title( $attribute );
|
$id = $args['id'] ? $args['id'] : sanitize_title( $attribute );
|
||||||
$class = $args['class'];
|
$class = $args['class'];
|
||||||
$show_option_none = $args['show_option_none'] ? true : false;
|
$show_option_none = (bool) $args['show_option_none'];
|
||||||
$show_option_none_text = $args['show_option_none'] ? $args['show_option_none'] : __( 'Choose an option', 'woocommerce' ); // We'll do our best to hide the placeholder, but we'll need to show something when resetting options.
|
$show_option_none_text = $args['show_option_none'] ? $args['show_option_none'] : __( 'Choose an option', 'woocommerce' ); // We'll do our best to hide the placeholder, but we'll need to show something when resetting options.
|
||||||
|
|
||||||
if ( empty( $options ) && ! empty( $product ) && ! empty( $attribute ) ) {
|
if ( empty( $options ) && ! empty( $product ) && ! empty( $attribute ) ) {
|
||||||
|
|
Loading…
Reference in New Issue