Merge branch 'master' into fix/19404

This commit is contained in:
Peter Fabian 2018-03-23 09:36:15 +01:00
commit 59af63e642
37 changed files with 1105 additions and 965 deletions

View File

@ -1876,7 +1876,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
* @return bool
*/
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 );
}
/**

View File

@ -273,7 +273,7 @@ abstract class WC_Payment_Gateway extends WC_Settings_API {
* @return bool
*/
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
*/
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 );
}
/**

View File

@ -1360,7 +1360,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
* @since 2.5.0
*/
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 $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;
}
/**

View File

@ -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.
return ( $count > 0 ) ? false : true;
return ! ( $count > 0 );
}
/**

View File

@ -603,7 +603,7 @@ class WC_REST_System_Status_Controller extends WC_REST_Controller {
'site_url' => get_option( 'siteurl' ),
'version' => WC()->version,
'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_multisite' => is_multisite(),
'wp_memory_limit' => $wp_memory_limit,

View File

@ -337,7 +337,7 @@ class WC_API_Orders extends WC_API_Resource {
'id' => $note->comment_ID,
'created_at' => $this->server->format_datetime( $note->comment_date_gmt ),
'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 ),
);
}

View File

@ -1269,7 +1269,7 @@ class WC_API_Orders extends WC_API_Resource {
'id' => $note->comment_ID,
'created_at' => $this->server->format_datetime( $note->comment_date_gmt ),
'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 ) );

View File

@ -440,7 +440,7 @@ class WC_API_Products extends WC_API_Resource {
}
$product->delete( true );
$result = $product->get_id() > 0 ? false : true;
$result = ! ( $product->get_id() > 0 );
} else {
$product->delete();
$result = 'trash' === $product->get_status();

View File

@ -1316,7 +1316,7 @@ class WC_API_Orders extends WC_API_Resource {
'id' => $note->comment_ID,
'created_at' => $this->server->format_datetime( $note->comment_date_gmt ),
'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 ) );

View File

@ -499,7 +499,7 @@ class WC_API_Products extends WC_API_Resource {
}
$product->delete( true );
$result = $product->get_id() > 0 ? false : true;
$result = ! ( $product->get_id() > 0 );
} else {
$product->delete();
$result = 'trash' === $product->get_status();

View File

@ -1675,7 +1675,7 @@ class WC_REST_Products_V1_Controller extends WC_REST_Posts_Controller {
}
$product->delete( true );
$result = $product->get_id() > 0 ? false : true;
$result = ! ( $product->get_id() > 0 );
} else {
// If we don't support trashing for this type, error out.
if ( ! $supports_trash ) {

View File

@ -1,32 +1,40 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Transactional Emails Controller
*
* 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
* @category Class
* @author WooThemes
* @package WooCommerce/Classes/Emails
* @version 2.3.0
*/
defined( 'ABSPATH' ) || exit;
/**
* Emails class.
*/
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;
/**
* Background emailer class.
*
* @var WC_Background_Emailer
*/
protected static $background_emailer;
protected static $background_emailer = null;
/**
* Main WC_Emails Instance.
@ -66,27 +74,29 @@ class WC_Emails {
* Hook in all transactional emails.
*/
public static function init_transactional_emails() {
$email_actions = apply_filters( 'woocommerce_email_actions', array(
'woocommerce_low_stock',
'woocommerce_no_stock',
'woocommerce_product_on_backorder',
'woocommerce_order_status_pending_to_processing',
'woocommerce_order_status_pending_to_completed',
'woocommerce_order_status_processing_to_cancelled',
'woocommerce_order_status_pending_to_failed',
'woocommerce_order_status_pending_to_on-hold',
'woocommerce_order_status_failed_to_processing',
'woocommerce_order_status_failed_to_completed',
'woocommerce_order_status_failed_to_on-hold',
'woocommerce_order_status_on-hold_to_processing',
'woocommerce_order_status_on-hold_to_cancelled',
'woocommerce_order_status_on-hold_to_failed',
'woocommerce_order_status_completed',
'woocommerce_order_fully_refunded',
'woocommerce_order_partially_refunded',
'woocommerce_new_customer_note',
'woocommerce_created_customer',
) );
$email_actions = apply_filters(
'woocommerce_email_actions', array(
'woocommerce_low_stock',
'woocommerce_no_stock',
'woocommerce_product_on_backorder',
'woocommerce_order_status_pending_to_processing',
'woocommerce_order_status_pending_to_completed',
'woocommerce_order_status_processing_to_cancelled',
'woocommerce_order_status_pending_to_failed',
'woocommerce_order_status_pending_to_on-hold',
'woocommerce_order_status_failed_to_processing',
'woocommerce_order_status_failed_to_completed',
'woocommerce_order_status_failed_to_on-hold',
'woocommerce_order_status_on-hold_to_processing',
'woocommerce_order_status_on-hold_to_cancelled',
'woocommerce_order_status_on-hold_to_failed',
'woocommerce_order_status_completed',
'woocommerce_order_fully_refunded',
'woocommerce_order_partially_refunded',
'woocommerce_new_customer_note',
'woocommerce_created_customer',
)
);
if ( apply_filters( 'woocommerce_defer_transactional_emails', false ) ) {
self::$background_emailer = new WC_Background_Emailer();
@ -107,10 +117,12 @@ class WC_Emails {
*/
public static function queue_transactional_email() {
if ( is_a( self::$background_emailer, 'WC_Background_Emailer' ) ) {
self::$background_emailer->push_to_queue( array(
'filter' => current_filter(),
'args' => func_get_args(),
) );
self::$background_emailer->push_to_queue(
array(
'filter' => current_filter(),
'args' => func_get_args(),
)
);
} else {
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 );
} catch ( Exception $e ) {
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.
*
*/
public function __construct() {
$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_footer', array( $this, 'email_footer' ) );
add_action( 'woocommerce_email_order_details', array( $this, 'order_downloads' ), 10, 4 );
@ -171,16 +182,16 @@ class WC_Emails {
add_action( 'woocommerce_email_customer_details', array( $this, 'customer_details' ), 10, 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_no_stock_notification', array( $this, 'no_stock' ) );
add_action( 'woocommerce_product_on_backorder_notification', array( $this, 'backorder' ) );
add_action( 'woocommerce_created_customer_notification', array( $this, 'customer_new_account' ), 10, 3 );
// 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 );
}
@ -188,26 +199,26 @@ class WC_Emails {
* Init email classes.
*/
public function init() {
// Include email classes
include_once( dirname( __FILE__ ) . '/emails/class-wc-email.php' );
// Include email classes.
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_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_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_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_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_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_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_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_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_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_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_New_Account'] = include 'emails/class-wc-email-customer-new-account.php';
$this->emails = apply_filters( 'woocommerce_email_classes', $this->emails );
// include css inliner
// include css inliner.
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.
*
* @param mixed $email_heading heading for the email
* @param mixed $email_heading Heading for the email.
*/
public function email_header( $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 );
echo wpautop( wptexturize( $message ) );
echo wpautop( wptexturize( $message ) ); // WPCS: XSS ok.
do_action( 'woocommerce_email_footer', null );
@ -293,15 +304,15 @@ class WC_Emails {
/**
* Send the email.
*
* @param mixed $to
* @param mixed $subject
* @param mixed $message
* @param string $headers (default: "Content-Type: text/html\r\n")
* @param string $attachments (default: "")
* @param mixed $to Receiver.
* @param mixed $subject Email subject.
* @param mixed $message Message.
* @param string $headers Email headers (default: "Content-Type: text/html\r\n").
* @param string $attachments Attachments (default: "").
* @return bool
*/
public function send( $to, $subject, $message, $headers = "Content-Type: text/html\r\n", $attachments = "" ) {
// Send
public function send( $to, $subject, $message, $headers = "Content-Type: text/html\r\n", $attachments = '' ) {
// Send.
$email = new WC_Email();
return $email->send( $to, $subject, $message, $headers, $attachments );
}
@ -309,7 +320,7 @@ class WC_Emails {
/**
* 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 ) {
$email = $this->emails['WC_Email_Customer_Invoice'];
@ -324,9 +335,9 @@ class WC_Emails {
/**
* Customer new account welcome email.
*
* @param int $customer_id
* @param array $new_customer_data
* @param bool $password_generated
* @param int $customer_id Customer ID.
* @param array $new_customer_data New customer data.
* @param bool $password_generated If password is generated.
*/
public function customer_new_account( $customer_id, $new_customer_data = array(), $password_generated = false ) {
if ( ! $customer_id ) {
@ -342,16 +353,30 @@ class WC_Emails {
/**
* Show the order details table
*
* @param WC_Order $order
* @param bool $sent_to_admin
* @param bool $plain_text
* @param string $email
* @param WC_Order $order Order instance.
* @param bool $sent_to_admin If should sent to admin.
* @param bool $plain_text If is plain text email.
* @param string $email Email address.
*/
public function order_details( $order, $sent_to_admin = false, $plain_text = false, $email = '' ) {
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 {
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.
*
* @since 3.2.0
* @param WC_Order $order
* @param bool $sent_to_admin
* @param bool $plain_text
* @param string $email
* @param WC_Order $order Order instance.
* @param bool $sent_to_admin If should sent to admin.
* @param bool $plain_text If is plain text email.
* @param string $email Email address.
*/
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;
@ -372,25 +397,45 @@ class WC_Emails {
}
$downloads = $order->get_downloadable_items();
$columns = apply_filters( 'woocommerce_email_downloads_columns', array(
'download-product' => __( 'Product', 'woocommerce' ),
'download-expires' => __( 'Expires', 'woocommerce' ),
'download-file' => __( 'Download', 'woocommerce' ),
) );
$columns = apply_filters(
'woocommerce_email_downloads_columns', array(
'download-product' => __( 'Product', 'woocommerce' ),
'download-expires' => __( 'Expires', 'woocommerce' ),
'download-file' => __( 'Download', 'woocommerce' ),
)
);
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 {
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.
*
* @param mixed $order
* @param bool $sent_to_admin (default: false)
* @param bool $plain_text (default: false)
* @param WC_Order $order Order instance.
* @param bool $sent_to_admin If should sent to admin.
* @param bool $plain_text If is plain text email.
*/
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 );
@ -421,14 +466,14 @@ class WC_Emails {
foreach ( $fields as $field ) {
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 {
foreach ( $fields as $field ) {
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?
* @param array $field
*
* @param array $field Field data to check if is valid.
* @return boolean
*/
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.
*
* @param WC_Order $order
* @param bool $sent_to_admin (default: false)
* @param bool $plain_text (default: false)
* @return string
* @param WC_Order $order Order instance.
* @param bool $sent_to_admin If should sent to admin.
* @param bool $plain_text If is plain text email.
*/
public function customer_details( $order, $sent_to_admin = false, $plain_text = false ) {
if ( ! is_a( $order, 'WC_Order' ) ) {
@ -473,23 +518,34 @@ class WC_Emails {
/**
* Get the email addresses.
*
* @param WC_Order $order
* @param bool $sent_to_admin
* @param bool $plain_text
* @param WC_Order $order Order instance.
* @param bool $sent_to_admin If should sent to admin.
* @param bool $plain_text If is plain text email.
*/
public function email_addresses( $order, $sent_to_admin = false, $plain_text = false ) {
if ( ! is_a( $order, 'WC_Order' ) ) {
return;
}
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 {
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.
*
* @return string
*/
private function get_blogname() {
@ -499,7 +555,7 @@ class WC_Emails {
/**
* Low stock notification email.
*
* @param WC_Product $product
* @param WC_Product $product Product instance.
*/
public function low_stock( $product ) {
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' ) );
/* translators: 1: product name 2: items in stock */
$message = sprintf(
/* translators: 1: product name 2: items in stock */
__( '%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_stock_quantity() ) )
@ -526,7 +582,7 @@ class WC_Emails {
/**
* No stock notification email.
*
* @param WC_Product $product
* @param WC_Product $product Product instance.
*/
public function no_stock( $product ) {
if ( 'no' === get_option( 'woocommerce_notify_no_stock', 'yes' ) ) {
@ -549,14 +605,16 @@ class WC_Emails {
/**
* Backorder notification email.
*
* @param array $args
* @param array $args Arguments.
*/
public function backorder( $args ) {
$args = wp_parse_args( $args, array(
'product' => '',
'quantity' => '',
'order_id' => '',
) );
$args = wp_parse_args(
$args, array(
'product' => '',
'quantity' => '',
'order_id' => '',
)
);
$order = wc_get_order( $args['order_id'] );
if (
@ -569,8 +627,9 @@ class WC_Emails {
}
$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() );
wp_mail(
apply_filters( 'woocommerce_email_recipient_backorder', get_option( 'woocommerce_stock_email_recipient' ), $args ),
apply_filters( 'woocommerce_email_subject_backorder', $subject, $args ),
@ -587,9 +646,9 @@ class WC_Emails {
* @see WC_Structured_Data::generate_order_data()
*
* @since 2.6.0
* @param mixed $order
* @param bool $sent_to_admin (default: false)
* @param bool $plain_text (default: false)
* @param WC_Order $order Order instance.
* @param bool $sent_to_admin If should sent to admin.
* @param bool $plain_text If is plain text email.
*/
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' );

View File

@ -2,11 +2,8 @@
/**
* Handle frontend scripts
*
* @class WC_Frontend_Scripts
* @version 2.3.0
* @package WooCommerce/Classes/
* @category Class
* @author WooThemes
* @package WooCommerce/Classes
* @version 2.3.0
*/
if ( ! defined( 'ABSPATH' ) ) {
@ -14,24 +11,27 @@ if ( ! defined( 'ABSPATH' ) ) {
}
/**
* WC_Frontend_Scripts Class.
* Frontend scripts class.
*/
class WC_Frontend_Scripts {
/**
* Contains an array of script handles registered by WC.
*
* @var array
*/
private static $scripts = array();
/**
* Contains an array of script handles registered by WC.
*
* @var array
*/
private static $styles = array();
/**
* Contains an array of script handles localized by WC.
*
* @var array
*/
private static $wp_localize_scripts = array();
@ -51,36 +51,37 @@ class WC_Frontend_Scripts {
* @return array
*/
public static function get_styles() {
return apply_filters( 'woocommerce_enqueue_styles', array(
'woocommerce-layout' => array(
'src' => self::get_asset_url( 'assets/css/woocommerce-layout.css' ),
'deps' => '',
'version' => WC_VERSION,
'media' => 'all',
'has_rtl' => true,
),
'woocommerce-smallscreen' => array(
'src' => self::get_asset_url( 'assets/css/woocommerce-smallscreen.css' ),
'deps' => 'woocommerce-layout',
'version' => WC_VERSION,
'media' => 'only screen and (max-width: ' . apply_filters( 'woocommerce_style_smallscreen_breakpoint', $breakpoint = '768px' ) . ')',
'has_rtl' => true,
),
'woocommerce-general' => array(
'src' => self::get_asset_url( 'assets/css/woocommerce.css' ),
'deps' => '',
'version' => WC_VERSION,
'media' => 'all',
'has_rtl' => true,
),
) );
return apply_filters(
'woocommerce_enqueue_styles', array(
'woocommerce-layout' => array(
'src' => self::get_asset_url( 'assets/css/woocommerce-layout.css' ),
'deps' => '',
'version' => WC_VERSION,
'media' => 'all',
'has_rtl' => true,
),
'woocommerce-smallscreen' => array(
'src' => self::get_asset_url( 'assets/css/woocommerce-smallscreen.css' ),
'deps' => 'woocommerce-layout',
'version' => WC_VERSION,
'media' => 'only screen and (max-width: ' . apply_filters( 'woocommerce_style_smallscreen_breakpoint', '768px' ) . ')',
'has_rtl' => true,
),
'woocommerce-general' => array(
'src' => self::get_asset_url( 'assets/css/woocommerce.css' ),
'deps' => '',
'version' => WC_VERSION,
'media' => 'all',
'has_rtl' => true,
),
)
);
}
/**
* Return asset URL.
*
* @param string $path
*
* @param string $path Assets path.
* @return string
*/
private static function get_asset_url( $path ) {
@ -91,12 +92,11 @@ class WC_Frontend_Scripts {
* Register a script for use.
*
* @uses wp_register_script()
* @access private
* @param string $handle
* @param string $path
* @param string[] $deps
* @param string $version
* @param boolean $in_footer
* @param string $handle Name of the script. Should be unique.
* @param string $path Full URL of the script, or path of the script relative to the WordPress root directory.
* @param string[] $deps An array of registered script handles this script depends on.
* @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 boolean $in_footer Whether to enqueue the script before </body> instead of in the <head>. Default 'false'.
*/
private static function register_script( $handle, $path, $deps = array( 'jquery' ), $version = WC_VERSION, $in_footer = true ) {
self::$scripts[] = $handle;
@ -107,15 +107,14 @@ class WC_Frontend_Scripts {
* Register and enqueue a script for use.
*
* @uses wp_enqueue_script()
* @access private
* @param string $handle
* @param string $path
* @param string[] $deps
* @param string $version
* @param boolean $in_footer
* @param string $handle Name of the script. Should be unique.
* @param string $path Full URL of the script, or path of the script relative to the WordPress root directory.
* @param string[] $deps An array of registered script handles this script depends on.
* @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 boolean $in_footer Whether to enqueue the script before </body> instead of in the <head>. Default 'false'.
*/
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 );
}
wp_enqueue_script( $handle );
@ -125,13 +124,12 @@ class WC_Frontend_Scripts {
* Register a style for use.
*
* @uses wp_register_style()
* @access private
* @param string $handle
* @param string $path
* @param string[] $deps
* @param string $version
* @param string $media
* @param boolean $has_rtl
* @param string $handle Name of the stylesheet. Should be unique.
* @param string $path Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
* @param string[] $deps An array of registered stylesheet handles this stylesheet depends on.
* @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 $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 boolean $has_rtl If has RTL version to load too.
*/
private static function register_style( $handle, $path, $deps = array(), $version = WC_VERSION, $media = 'all', $has_rtl = false ) {
self::$styles[] = $handle;
@ -146,16 +144,15 @@ class WC_Frontend_Scripts {
* Register and enqueue a styles for use.
*
* @uses wp_enqueue_style()
* @access private
* @param string $handle
* @param string $path
* @param string[] $deps
* @param string $version
* @param string $media
* @param boolean $has_rtl
* @param string $handle Name of the stylesheet. Should be unique.
* @param string $path Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
* @param string[] $deps An array of registered stylesheet handles this stylesheet depends on.
* @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 $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 boolean $has_rtl If has RTL version to load too.
*/
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 );
}
wp_enqueue_style( $handle );
@ -167,112 +164,112 @@ class WC_Frontend_Scripts {
private static function register_scripts() {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
$register_scripts = array(
'flexslider' => array(
'flexslider' => array(
'src' => self::get_asset_url( 'assets/js/flexslider/jquery.flexslider' . $suffix . '.js' ),
'deps' => array( 'jquery' ),
'version' => '2.7.0',
),
'js-cookie' => array(
'js-cookie' => array(
'src' => self::get_asset_url( 'assets/js/js-cookie/js.cookie' . $suffix . '.js' ),
'deps' => array(),
'version' => '2.1.4',
),
'jquery-blockui' => array(
'jquery-blockui' => array(
'src' => self::get_asset_url( 'assets/js/jquery-blockui/jquery.blockUI' . $suffix . '.js' ),
'deps' => array( 'jquery' ),
'version' => '2.70',
),
'jquery-cookie' => array( // deprecated.
'jquery-cookie' => array( // deprecated.
'src' => self::get_asset_url( 'assets/js/jquery-cookie/jquery.cookie' . $suffix . '.js' ),
'deps' => array( 'jquery' ),
'version' => '1.4.1',
),
'jquery-payment' => array(
'jquery-payment' => array(
'src' => self::get_asset_url( 'assets/js/jquery-payment/jquery.payment' . $suffix . '.js' ),
'deps' => array( 'jquery' ),
'version' => '3.0.0',
),
'photoswipe' => array(
'photoswipe' => array(
'src' => self::get_asset_url( 'assets/js/photoswipe/photoswipe' . $suffix . '.js' ),
'deps' => array(),
'version' => '4.1.1',
),
'photoswipe-ui-default' => array(
'photoswipe-ui-default' => array(
'src' => self::get_asset_url( 'assets/js/photoswipe/photoswipe-ui-default' . $suffix . '.js' ),
'deps' => array( 'photoswipe' ),
'version' => '4.1.1',
),
'prettyPhoto' => array( // deprecated.
'prettyPhoto' => array( // deprecated.
'src' => self::get_asset_url( 'assets/js/prettyPhoto/jquery.prettyPhoto' . $suffix . '.js' ),
'deps' => array( 'jquery' ),
'version' => '3.1.6',
),
'prettyPhoto-init' => array( // deprecated.
'prettyPhoto-init' => array( // deprecated.
'src' => self::get_asset_url( 'assets/js/prettyPhoto/jquery.prettyPhoto.init' . $suffix . '.js' ),
'deps' => array( 'jquery', 'prettyPhoto' ),
'version' => WC_VERSION,
),
'select2' => array(
'select2' => array(
'src' => self::get_asset_url( 'assets/js/select2/select2.full' . $suffix . '.js' ),
'deps' => array( 'jquery' ),
'version' => '4.0.3',
),
'selectWoo' => array(
'selectWoo' => array(
'src' => self::get_asset_url( 'assets/js/selectWoo/selectWoo.full' . $suffix . '.js' ),
'deps' => array( 'jquery' ),
'version' => '1.0.4',
),
'wc-address-i18n' => array(
'wc-address-i18n' => array(
'src' => self::get_asset_url( 'assets/js/frontend/address-i18n' . $suffix . '.js' ),
'deps' => array( 'jquery' ),
'version' => WC_VERSION,
),
'wc-add-payment-method' => array(
'wc-add-payment-method' => array(
'src' => self::get_asset_url( 'assets/js/frontend/add-payment-method' . $suffix . '.js' ),
'deps' => array( 'jquery', 'woocommerce' ),
'version' => WC_VERSION,
),
'wc-cart' => array(
'wc-cart' => array(
'src' => self::get_asset_url( 'assets/js/frontend/cart' . $suffix . '.js' ),
'deps' => array( 'jquery', 'wc-country-select', 'wc-address-i18n' ),
'version' => WC_VERSION,
),
'wc-cart-fragments' => array(
'wc-cart-fragments' => array(
'src' => self::get_asset_url( 'assets/js/frontend/cart-fragments' . $suffix . '.js' ),
'deps' => array( 'jquery', 'js-cookie' ),
'version' => WC_VERSION,
),
'wc-checkout' => array(
'wc-checkout' => array(
'src' => self::get_asset_url( 'assets/js/frontend/checkout' . $suffix . '.js' ),
'deps' => array( 'jquery', 'woocommerce', 'wc-country-select', 'wc-address-i18n' ),
'version' => WC_VERSION,
),
'wc-country-select' => array(
'wc-country-select' => array(
'src' => self::get_asset_url( 'assets/js/frontend/country-select' . $suffix . '.js' ),
'deps' => array( 'jquery' ),
'version' => WC_VERSION,
),
'wc-credit-card-form' => array(
'wc-credit-card-form' => array(
'src' => self::get_asset_url( 'assets/js/frontend/credit-card-form' . $suffix . '.js' ),
'deps' => array( 'jquery', 'jquery-payment' ),
'version' => WC_VERSION,
),
'wc-add-to-cart' => array(
'wc-add-to-cart' => array(
'src' => self::get_asset_url( 'assets/js/frontend/add-to-cart' . $suffix . '.js' ),
'deps' => array( 'jquery' ),
'version' => WC_VERSION,
),
'wc-add-to-cart-variation' => array(
'wc-add-to-cart-variation' => array(
'src' => self::get_asset_url( 'assets/js/frontend/add-to-cart-variation' . $suffix . '.js' ),
'deps' => array( 'jquery', 'wp-util' ),
'version' => WC_VERSION,
),
'wc-geolocation' => array(
'wc-geolocation' => array(
'src' => self::get_asset_url( 'assets/js/frontend/geolocation' . $suffix . '.js' ),
'deps' => array( 'jquery' ),
'version' => WC_VERSION,
),
'wc-lost-password' => array(
'wc-lost-password' => array(
'src' => self::get_asset_url( 'assets/js/frontend/lost-password' . $suffix . '.js' ),
'deps' => array( 'jquery', 'woocommerce' ),
'version' => WC_VERSION,
@ -282,17 +279,17 @@ class WC_Frontend_Scripts {
'deps' => array( 'jquery', 'password-strength-meter' ),
'version' => WC_VERSION,
),
'wc-single-product' => array(
'wc-single-product' => array(
'src' => self::get_asset_url( 'assets/js/frontend/single-product' . $suffix . '.js' ),
'deps' => array( 'jquery' ),
'version' => WC_VERSION,
),
'woocommerce' => array(
'woocommerce' => array(
'src' => self::get_asset_url( 'assets/js/frontend/woocommerce' . $suffix . '.js' ),
'deps' => array( 'jquery', 'jquery-blockui', 'js-cookie' ),
'version' => WC_VERSION,
),
'zoom' => array(
'zoom' => array(
'src' => self::get_asset_url( 'assets/js/zoom/jquery.zoom' . $suffix . '.js' ),
'deps' => array( 'jquery' ),
'version' => '1.7.15',
@ -308,19 +305,19 @@ class WC_Frontend_Scripts {
*/
private static function register_styles() {
$register_styles = array(
'photoswipe' => array(
'photoswipe' => array(
'src' => self::get_asset_url( 'assets/css/photoswipe/photoswipe.css' ),
'deps' => array(),
'version' => WC_VERSION,
'has_rtl' => false,
),
'photoswipe-default-skin' => array(
'photoswipe-default-skin' => array(
'src' => self::get_asset_url( 'assets/css/photoswipe/default-skin/default-skin.css' ),
'deps' => array( 'photoswipe' ),
'version' => WC_VERSION,
'has_rtl' => false,
),
'select2' => array(
'select2' => array(
'src' => self::get_asset_url( 'assets/css/select2.css' ),
'deps' => array(),
'version' => WC_VERSION,
@ -400,12 +397,13 @@ class WC_Frontend_Scripts {
}
}
// Global frontend scripts
// Global frontend scripts.
self::enqueue_script( 'woocommerce' );
self::enqueue_script( 'wc-cart-fragments' );
// CSS Styles
if ( $enqueue_styles = self::get_styles() ) {
// CSS Styles.
$enqueue_styles = self::get_styles();
if ( $enqueue_styles ) {
foreach ( $enqueue_styles as $handle => $args ) {
if ( ! isset( $args['has_rtl'] ) ) {
$args['has_rtl'] = false;
@ -418,12 +416,18 @@ class WC_Frontend_Scripts {
/**
* 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.
* @param string $handle
*
* @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 Script handle the data will be attached to.
*/
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';
self::$wp_localize_scripts[] = $handle;
wp_localize_script( $handle, $name, apply_filters( $name, $data ) );
@ -432,118 +436,122 @@ class WC_Frontend_Scripts {
/**
* Return data for script handles.
* @access private
* @param string $handle
*
* @param string $handle Script handle the data will be attached to.
* @return array|bool
*/
private static function get_script_data( $handle ) {
global $wp;
switch ( $handle ) {
case 'woocommerce' :
case 'woocommerce':
$params = array(
'ajax_url' => WC()->ajax_url(),
'wc_ajax_url' => WC_AJAX::get_endpoint( "%%endpoint%%" ),
'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
);
break;
case 'wc-geolocation' :
break;
case 'wc-geolocation':
$params = array(
'wc_ajax_url' => WC_AJAX::get_endpoint( "%%endpoint%%" ),
'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
'home_url' => home_url(),
'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;
case 'wc-single-product' :
break;
case 'wc-single-product':
$params = array(
'i18n_required_rating_text' => esc_attr__( 'Please select a rating', 'woocommerce' ),
'review_rating_required' => get_option( 'woocommerce_review_rating_required' ),
'flexslider' => apply_filters( 'woocommerce_single_product_carousel_options', array(
'rtl' => is_rtl(),
'animation' => 'slide',
'smoothHeight' => true,
'directionNav' => false,
'controlNav' => 'thumbnails',
'slideshow' => false,
'animationSpeed' => 500,
'animationLoop' => false, // Breaks photoswipe pagination if true.
'allowOneSlide' => false,
) ),
'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() ),
'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(
'shareEl' => false,
'closeOnScroll' => false,
'history' => false,
'hideAnimationDuration' => 0,
'showAnimationDuration' => 0,
) ),
'flexslider_enabled' => apply_filters( 'woocommerce_single_product_flexslider_enabled', get_theme_support( 'wc-product-gallery-slider' ) ),
'flexslider' => apply_filters(
'woocommerce_single_product_carousel_options', array(
'rtl' => is_rtl(),
'animation' => 'slide',
'smoothHeight' => true,
'directionNav' => false,
'controlNav' => 'thumbnails',
'slideshow' => false,
'animationSpeed' => 500,
'animationLoop' => false, // Breaks photoswipe pagination if true.
'allowOneSlide' => false,
)
),
'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() ),
'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(
'shareEl' => false,
'closeOnScroll' => false,
'history' => false,
'hideAnimationDuration' => 0,
'showAnimationDuration' => 0,
)
),
'flexslider_enabled' => apply_filters( 'woocommerce_single_product_flexslider_enabled', get_theme_support( 'wc-product-gallery-slider' ) ),
);
break;
case 'wc-checkout' :
break;
case 'wc-checkout':
$params = array(
'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' ),
'apply_coupon_nonce' => wp_create_nonce( 'apply-coupon' ),
'remove_coupon_nonce' => wp_create_nonce( 'remove-coupon' ),
'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,
'debug_mode' => defined( 'WP_DEBUG' ) && WP_DEBUG,
'i18n_checkout_error' => esc_attr__( 'Error processing checkout. Please try again.', 'woocommerce' ),
);
break;
case 'wc-address-i18n' :
break;
case 'wc-address-i18n':
$params = array(
'locale' => json_encode( WC()->countries->get_country_locale() ),
'locale_fields' => json_encode( WC()->countries->get_country_locale_field_selectors() ),
'locale' => wp_json_encode( WC()->countries->get_country_locale() ),
'locale_fields' => wp_json_encode( WC()->countries->get_country_locale_field_selectors() ),
'i18n_required_text' => esc_attr__( 'required', 'woocommerce' ),
);
break;
case 'wc-cart' :
break;
case 'wc-cart':
$params = array(
'ajax_url' => WC()->ajax_url(),
'wc_ajax_url' => WC_AJAX::get_endpoint( "%%endpoint%%" ),
'update_shipping_method_nonce' => wp_create_nonce( "update-shipping-method" ),
'apply_coupon_nonce' => wp_create_nonce( "apply-coupon" ),
'remove_coupon_nonce' => wp_create_nonce( "remove-coupon" ),
'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
'update_shipping_method_nonce' => wp_create_nonce( 'update-shipping-method' ),
'apply_coupon_nonce' => wp_create_nonce( 'apply-coupon' ),
'remove_coupon_nonce' => wp_create_nonce( 'remove-coupon' ),
);
break;
case 'wc-cart-fragments' :
break;
case 'wc-cart-fragments':
$params = array(
'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(), '/' ) ) ),
'fragment_name' => apply_filters( 'woocommerce_cart_fragment_name', 'wc_fragments_' . md5( get_current_blog_id() . '_' . get_site_url( get_current_blog_id(), '/' ) ) ),
);
break;
case 'wc-add-to-cart' :
break;
case 'wc-add-to-cart':
$params = array(
'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' ),
'cart_url' => apply_filters( 'woocommerce_add_to_cart_redirect', wc_get_cart_url() ),
'is_cart' => is_cart(),
'cart_redirect_after_add' => get_option( 'woocommerce_cart_redirect_after_add' ),
);
break;
case 'wc-add-to-cart-variation' :
// We also need the wp.template for this script :)
break;
case 'wc-add-to-cart-variation':
// We also need the wp.template for this script :).
wc_get_template( 'single-product/add-to-cart/variation.php' );
$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_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' ),
);
break;
case 'wc-country-select' :
break;
case 'wc-country-select':
$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&hellip;', 'woocommerce' ),
'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'woocommerce' ),
'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'woocommerce' ),
@ -556,14 +564,14 @@ class WC_Frontend_Scripts {
'i18n_load_more' => _x( 'Loading more results&hellip;', 'enhanced select', 'woocommerce' ),
'i18n_searching' => _x( 'Searching&hellip;', 'enhanced select', 'woocommerce' ),
);
break;
case 'wc-password-strength-meter' :
break;
case 'wc-password-strength-meter':
$params = array(
'min_password_strength' => apply_filters( 'woocommerce_min_password_strength', 3 ),
'i18n_password_error' => esc_attr__( 'Please enter a stronger password.', 'woocommerce' ),
'i18n_password_hint' => esc_attr( wp_get_password_hint() ),
);
break;
break;
default:
$params = false;
}

View File

@ -1,28 +1,32 @@
<?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.
*
* @class WC_Payment_Gateways
* @version 2.2.0
* @package WooCommerce/Classes/Payment
* @category Class
* @author WooThemes
* @version 2.2.0
* @package WooCommerce/Classes/Payment
*/
defined( 'ABSPATH' ) || exit;
/**
* Payment gateways class.
*/
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
* @since 2.1
* The single instance of the class.
*
* @var WC_Payment_Gateways
* @since 2.1.0
*/
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.
*
* @since 2.1
* @static
* @return WC_Payment_Gateways Main 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.
*/
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() );
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 );
// Get sort order option
// Get sort order option.
$ordering = (array) get_option( 'woocommerce_gateway_order' );
$order_end = 999;
// Load gateways in order
// Load gateways in order.
foreach ( $load_gateways as $gateway ) {
$load_gateway = is_string( $gateway ) ? new $gateway() : $gateway;
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;
} else {
// Add to end of the array
// Add to end of the array.
$this->payment_gateways[ $order_end ] = $load_gateway;
$order_end++;
}
@ -119,12 +122,13 @@ class WC_Payment_Gateways {
/**
* Get gateways.
*
* @return array
*/
public function payment_gateways() {
$_available_gateways = array();
if ( sizeof( $this->payment_gateways ) > 0 ) {
if ( count( $this->payment_gateways ) > 0 ) {
foreach ( $this->payment_gateways as $gateway ) {
$_available_gateways[ $gateway->id ] = $gateway;
}
@ -135,6 +139,7 @@ class WC_Payment_Gateways {
/**
* Get array of registered gateway ids
*
* @since 2.6.0
* @return array of strings
*/
@ -169,7 +174,7 @@ class WC_Payment_Gateways {
* @param array $gateways Available payment gateways.
*/
public function set_current_gateway( $gateways ) {
// Be on the defensive
// Be on the defensive.
if ( ! is_array( $gateways ) || empty( $gateways ) ) {
return;
}
@ -190,7 +195,7 @@ class WC_Payment_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' ) ) ) {
$current_gateway->set_current();
}
@ -200,10 +205,10 @@ class WC_Payment_Gateways {
* Save options in admin.
*/
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();
if ( is_array( $gateway_order ) && sizeof( $gateway_order ) > 0 ) {
if ( is_array( $gateway_order ) && count( $gateway_order ) > 0 ) {
$loop = 0;
foreach ( $gateway_order as $gateway_id ) {
$order[ esc_attr( $gateway_id ) ] = $loop;

View File

@ -1,19 +1,18 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* WooCommerce Payment Tokens.
* WooCommerce Payment Tokens
*
* An API for storing and managing tokens for gateways and customers.
*
* @class WC_Payment_Tokens
* @version 3.0.0
* @since 2.6.0
* @package WooCommerce/Classes
* @category Class
* @author WooThemes
* @package WooCommerce/Classes
* @version 3.0.0
* @since 2.6.0
*/
defined( 'ABSPATH' ) || exit;
/**
* Payment tokens class.
*/
class WC_Payment_Tokens {
@ -21,16 +20,25 @@ class WC_Payment_Tokens {
* Gets valid tokens from the database based on user defined criteria.
*
* @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
*/
public static function get_tokens( $args ) {
$args = wp_parse_args( $args, array(
'token_id' => '',
'user_id' => '',
'gateway_id' => '',
'type' => '',
) );
$args = wp_parse_args(
$args, array(
'token_id' => '',
'user_id' => '',
'gateway_id' => '',
'type' => '',
)
);
$data_store = WC_Data_Store::load( 'payment-token' );
$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.
*
* @since 2.6.0
* @param int $customer_id Customer ID
* @param string $gateway_id Optional Gateway ID for getting tokens for a specific gateway
* @return array Array of token objects
* @param int $customer_id Customer ID.
* @param string $gateway_id Optional Gateway ID for getting tokens for a specific gateway.
* @return array Array of token objects.
*/
public static function get_customer_tokens( $customer_id, $gateway_id = '' ) {
if ( $customer_id < 1 ) {
return array();
}
$tokens = self::get_tokens( array(
'user_id' => $customer_id,
'gateway_id' => $gateway_id,
) );
$tokens = self::get_tokens(
array(
'user_id' => $customer_id,
'gateway_id' => $gateway_id,
)
);
return apply_filters( 'woocommerce_get_customer_payment_tokens', $tokens, $customer_id, $gateway_id );
}
@ -72,8 +82,8 @@ class WC_Payment_Tokens {
/**
* Returns a customers default token or NULL if there is no default token.
*
* @since 2.6.0
* @param int $customer_id
* @since 2.6.0
* @param int $customer_id Customer ID.
* @return WC_Payment_Token|null
*/
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.
*
* @since 2.6.0
* @param int $order_id Order ID
* @return array Array of token objects
* @param int $order_id Order ID.
* @return array Array of token objects.
*/
public static function get_order_tokens( $order_id ) {
$order = wc_get_order( $order_id );
@ -111,9 +121,11 @@ class WC_Payment_Tokens {
return array();
}
$tokens = self::get_tokens( array(
'token_id' => $token_ids,
) );
$tokens = self::get_tokens(
array(
'token_id' => $token_ids,
)
);
return apply_filters( 'woocommerce_get_order_payment_tokens', $tokens, $order_id );
}
@ -123,17 +135,16 @@ class WC_Payment_Tokens {
*
* @since 2.6.0
*
* @param int $token_id Token ID
* @param object $token_result
*
* @return null|WC_Payment_Token Returns a valid payment token or null if no token can be found
* @param int $token_id Token ID.
* @param object $token_result Token result.
* @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 ) {
$data_store = WC_Data_Store::load( 'payment-token' );
if ( is_null( $token_result ) ) {
$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 ) ) {
return null;
}
@ -142,7 +153,7 @@ class WC_Payment_Tokens {
$token_class = 'WC_Payment_Token_' . $token_result->type;
if ( class_exists( $token_class ) ) {
$meta = $data_store->get_metadata( $token_id );
$meta = $data_store->get_metadata( $token_id );
$passed_meta = array();
if ( ! empty( $meta ) ) {
foreach ( $meta as $meta_key => $meta_value ) {
@ -157,8 +168,9 @@ class WC_Payment_Tokens {
/**
* Remove a payment token from the database by ID.
*
* @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 ) {
$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.
*
* @since 2.6.0
* @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 $user_id User to set a default for.
* @param int $token_id The ID of the token that should be default.
*/
public static function set_users_default( $user_id, $token_id ) {
$data_store = WC_Data_Store::load( 'payment-token' );
@ -192,9 +204,9 @@ class WC_Payment_Tokens {
/**
* Returns what type (credit card, echeck, etc) of token a token is by ID.
*
* @since 2.6.0
* @param int $token_id Token ID
* @return string Type
* @since 2.6.0
* @param int $token_id Token ID.
* @return string Type.
*/
public static function get_token_type_by_id( $token_id ) {
$data_store = WC_Data_Store::load( 'payment-token' );

View File

@ -1,19 +1,17 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Post Data.
* Post Data
*
* Standardises certain post data on save.
*
* @class WC_Post_Data
* @version 2.2.0
* @package WooCommerce/Classes/Data
* @category Class
* @author WooThemes
* @package WooCommerce/Classes/Data
* @version 2.2.0
*/
defined( 'ABSPATH' ) || exit;
/**
* Post data class.
*/
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( '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( 'wp_trash_post', array( __CLASS__, 'trash_post' ) );
add_action( 'untrashed_post', array( __CLASS__, 'untrash_post' ) );
@ -59,14 +57,18 @@ class WC_Post_Data {
/**
* Link to parent products when getting permalink for variation.
*
* @param string $permalink
* @param object $post
* @param string $permalink Permalink.
* @param WP_Post $post Post data.
*
* @return string
*/
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() ) {
return $variation->get_permalink();
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 $permalink;
}
@ -85,7 +87,8 @@ class WC_Post_Data {
/**
* Sync a product.
* @param int $product_id
*
* @param int $product_id Product ID.
*/
public static function deferred_product_sync( $product_id ) {
$product = wc_get_product( $product_id );
@ -98,18 +101,18 @@ class WC_Post_Data {
/**
* Delete transients when terms are set.
*
* @param int $object_id
* @param mixed $terms
* @param array $tt_ids
* @param string $taxonomy
* @param mixed $append
* @param array $old_tt_ids
* @param int $object_id Object ID.
* @param mixed $terms An array of object terms.
* @param array $tt_ids An array of term taxonomy IDs.
* @param string $taxonomy Taxonomy slug.
* @param mixed $append Whether to append new terms to the old terms.
* @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 ) {
foreach ( array_merge( $tt_ids, $old_tt_ids ) as $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();
}
}
@ -117,12 +120,12 @@ class WC_Post_Data {
/**
* When a post status changes.
*
* @param string $new_status
* @param string $old_status
* @param object $post
* @param string $new_status New status.
* @param string $old_status Old status.
* @param WP_Post $post Post data.
*/
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();
}
}
@ -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.
*/
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 );
// 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() ) {
global $wpdb;
$wpdb->query( "
$wpdb->query(
"
DELETE FROM `$wpdb->options`
WHERE `option_name` LIKE ('\_transient\_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\_timeout\_wc\_products\_will\_display\_%')
" );
"
);
}
}
@ -152,9 +157,9 @@ class WC_Post_Data {
* Handle type changes.
*
* @since 3.0.0
* @param WC_Product $product
* @param string $from
* @param string $to
* @param WC_Product $product Product data.
* @param string $from Origin type.
* @param string $to New type.
*/
public static function product_type_changed( $product, $from, $to ) {
if ( 'variable' === $from && 'variable' !== $to ) {
@ -166,9 +171,10 @@ class WC_Post_Data {
/**
* When editing a term, check for product attributes.
* @param id $term_id
* @param id $tt_id
* @param string $taxonomy
*
* @param int $term_id Term ID.
* @param int $tt_id Term taxonomy ID.
* @param string $taxonomy Taxonomy slug.
*/
public static function edit_term( $term_id, $tt_id, $taxonomy ) {
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.
* @param id $term_id
* @param id $tt_id
* @param string $taxonomy
*
* @param int $term_id Term ID.
* @param int $tt_id Term taxonomy ID.
* @param string $taxonomy Taxonomy slug.
*/
public static function edited_term( $term_id, $tt_id, $taxonomy ) {
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.
*
* @param null $check
* @param int $object_id
* @param string $meta_key
* @param mixed $meta_value
* @param mixed $prev_value
* @param null $check Whether to allow updating metadata for the given type.
* @param int $object_id Object ID.
* @param string $meta_key Meta key.
* @param mixed $meta_value Meta value. Must be serializable if non-scalar.
* @param mixed $prev_value If specified, only update existing metadata entries with the specified value. Otherwise, update all entries.
* @return null|bool
*/
public static function update_order_item_metadata( $check, $object_id, $meta_key, $meta_value, $prev_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 );
// Update meta value with new string
// Update meta value with new string.
update_metadata( 'order_item', $object_id, $meta_key, $meta_value, $prev_value );
// Return
return true;
}
return $check;
@ -226,28 +232,27 @@ class WC_Post_Data {
/**
* Ensure floats are correctly converted to strings based on PHP locale.
*
* @param null $check
* @param int $object_id
* @param string $meta_key
* @param mixed $meta_value
* @param mixed $prev_value
* @param null $check Whether to allow updating metadata for the given type.
* @param int $object_id Object ID.
* @param string $meta_key Meta key.
* @param mixed $meta_value Meta value. Must be serializable if non-scalar.
* @param mixed $prev_value If specified, only update existing metadata entries with the specified value. Otherwise, update all entries.
* @return null|bool
*/
public static function update_post_metadata( $check, $object_id, $meta_key, $meta_value, $prev_value ) {
// 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' );
}
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 );
// Update meta value with new string
// Update meta value with new string.
update_metadata( 'post', $object_id, $meta_key, $meta_value, $prev_value );
// Return
return true;
}
return $check;
@ -255,10 +260,11 @@ class WC_Post_Data {
/**
* When setting stock level, ensure the stock status is kept in sync.
* @param int $meta_id
* @param int $object_id
* @param string $meta_key
* @param mixed $meta_value
*
* @param int $meta_id Meta ID.
* @param int $object_id Object ID.
* @param string $meta_key Meta key.
* @param mixed $meta_value Meta value.
* @deprecated
*/
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 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
*/
public static function wp_insert_post_data( $data ) {
@ -277,13 +283,13 @@ class WC_Post_Data {
$order_title .= ' &ndash; ' . date_i18n( 'F j, Y @ h:i A', strtotime( $data['post_date'] ) );
}
$data['post_title'] = $order_title;
} elseif ( 'product' === $data['post_type'] && isset( $_POST['product-type'] ) ) {
$product_type = stripslashes( $_POST['product-type'] );
} elseif ( 'product' === $data['post_type'] && isset( $_POST['product-type'] ) ) { // WPCS: input var ok, CSRF ok.
$product_type = wc_clean( wp_unslash( $_POST['product-type'] ) ); // WPCS: input var ok, CSRF ok.
switch ( $product_type ) {
case 'grouped' :
case 'variable' :
case 'grouped':
case 'variable':
$data['post_parent'] = 0;
break;
break;
}
} elseif ( 'product' === $data['post_type'] && 'auto-draft' === $data['post_status'] ) {
$data['post_title'] = 'AUTO-DRAFT';
@ -301,7 +307,7 @@ class WC_Post_Data {
* @return array
*/
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 $data;
@ -310,7 +316,7 @@ class WC_Post_Data {
/**
* 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 ) {
if ( ! current_user_can( 'delete_posts' ) || ! $id ) {
@ -320,18 +326,19 @@ class WC_Post_Data {
$post_type = get_post_type( $id );
switch ( $post_type ) {
case 'product' :
case 'product':
$data_store = WC_Data_Store::load( 'product-variable' );
$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 );
}
break;
case 'product_variation' :
case 'product_variation':
wc_delete_product_transients( wp_get_post_parent_id( $id ) );
break;
case 'shop_order' :
case 'shop_order':
global $wpdb;
$refunds = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = 'shop_order_refund' AND post_parent = %d", $id ) );
@ -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 ) {
if ( ! $id ) {
@ -358,7 +365,7 @@ class WC_Post_Data {
$post_type = get_post_type( $id );
// 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;
$refunds = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = 'shop_order_refund' AND post_parent = %d", $id ) );
@ -369,7 +376,7 @@ class WC_Post_Data {
wc_delete_shop_order_transients( $id );
// If this is a product, trash children variations.
// If this is a product, trash children variations.
} elseif ( 'product' === $post_type ) {
$data_store = WC_Data_Store::load( 'product-variable' );
$data_store->delete_variations( $id, false );
@ -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 ) {
if ( ! $id ) {
@ -388,7 +395,7 @@ class WC_Post_Data {
$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;
$refunds = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = 'shop_order_refund' AND post_parent = %d", $id ) );
@ -411,12 +418,12 @@ class WC_Post_Data {
* Before deleting an order, do some cleanup.
*
* @since 3.2.0
* @param int $order_id
* @param int $order_id 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.
$order = wc_get_order( $order_id );
$order = wc_get_order( $order_id );
// Check for `get_customer_id`, since this may be e.g. a refund order (which doesn't implement it).
$customer_id = is_callable( array( $order, 'get_customer_id' ) ) ? $order->get_customer_id() : 0;
@ -444,20 +451,22 @@ class WC_Post_Data {
/**
* Remove item meta on permanent deletion.
*
* @param int $postid
* @param int $postid Post ID.
*/
public static function delete_order_items( $postid ) {
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 );
$wpdb->query( "
$wpdb->query(
"
DELETE {$wpdb->prefix}woocommerce_order_items, {$wpdb->prefix}woocommerce_order_itemmeta
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
WHERE {$wpdb->prefix}woocommerce_order_items.order_id = '{$postid}';
" );
"
); // WPCS: unprepared SQL ok.
do_action( 'woocommerce_deleted_order_items', $postid );
}
@ -466,10 +475,10 @@ class WC_Post_Data {
/**
* Remove downloadable permissions on permanent order deletion.
*
* @param int $postid
* @param int $postid Post ID.
*/
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 );
$data_store = WC_Data_Store::load( 'customer-download' );
@ -483,9 +492,9 @@ class WC_Post_Data {
* 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.
* @param int $product_id product identifier
* @param int $variation_id optional product variation identifier
* @param array $downloads newly set files
* @param int $product_id Product ID.
* @param int $variation_id Variation ID. Optional product variation identifier.
* @param array $downloads Newly set files.
*/
public static function process_product_file_download_paths( $product_id, $variation_id, $downloads ) {
wc_deprecated_function( __FUNCTION__, '3.3' );
@ -493,10 +502,11 @@ class WC_Post_Data {
/**
* Flush meta cache for CRUD objects on direct update.
* @param int $meta_id
* @param int $object_id
* @param string $meta_key
* @param string $meta_value
*
* @param int $meta_id Meta ID.
* @param int $object_id Object ID.
* @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 ) {
WC_Cache_Helper::incr_cache_prefix( 'object_' . $object_id );
@ -507,10 +517,10 @@ class WC_Post_Data {
*
* @since 3.3.0
* @param int $object_id Product ID.
* @param array $terms Terms array.
* @param array $tt_ids Term ids array.
* @param string $taxonomy Taxonomy name.
* @param bool $append Are we appending or setting terms.
* @param array $terms Terms array.
* @param array $tt_ids Term ids array.
* @param string $taxonomy Taxonomy name.
* @param bool $append Are we appending or setting terms.
*/
public static function force_default_term( $object_id, $terms, $tt_ids, $taxonomy, $append ) {
if ( ! $append && 'product_cat' === $taxonomy && empty( $tt_ids ) && 'product' === get_post_type( $object_id ) ) {

View File

@ -4,21 +4,16 @@
*
* Registers post types and taxonomies.
*
* @class WC_Post_types
* @version 2.5.0
* @package WooCommerce/Classes/Products
* @category Class
* @author WooThemes
* @package WooCommerce/Classes/Products
* @version 2.5.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
defined( 'ABSPATH' ) || exit;
/**
* WC_Post_types Class.
* Post types Class.
*/
class WC_Post_types {
class WC_Post_Types {
/**
* Hook in methods.
@ -50,37 +45,45 @@ class WC_Post_types {
$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_args_product_type', array(
'hierarchical' => false,
'show_ui' => false,
'show_in_nav_menus' => false,
'query_var' => is_admin(),
'rewrite' => false,
'public' => false,
) )
apply_filters(
'woocommerce_taxonomy_args_product_type', array(
'hierarchical' => false,
'show_ui' => false,
'show_in_nav_menus' => false,
'query_var' => is_admin(),
'rewrite' => 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_args_product_visibility', array(
'hierarchical' => false,
'show_ui' => false,
'show_in_nav_menus' => false,
'query_var' => is_admin(),
'rewrite' => false,
'public' => false,
) )
apply_filters(
'woocommerce_taxonomy_args_product_visibility', array(
'hierarchical' => false,
'show_ui' => false,
'show_in_nav_menus' => false,
'query_var' => is_admin(),
'rewrite' => false,
'public' => false,
)
)
);
register_taxonomy( 'product_cat',
register_taxonomy(
'product_cat',
apply_filters( 'woocommerce_taxonomy_objects_product_cat', array( 'product' ) ),
apply_filters( 'woocommerce_taxonomy_args_product_cat', array(
'hierarchical' => true,
'update_count_callback' => '_wc_term_recount',
'label' => __( 'Categories', 'woocommerce' ),
'labels' => array(
apply_filters(
'woocommerce_taxonomy_args_product_cat', array(
'hierarchical' => true,
'update_count_callback' => '_wc_term_recount',
'label' => __( 'Categories', 'woocommerce' ),
'labels' => array(
'name' => __( 'Product categories', 'woocommerce' ),
'singular_name' => __( 'Category', 'woocommerce' ),
'menu_name' => _x( 'Categories', 'Admin menu name', 'woocommerce' ),
@ -94,29 +97,32 @@ class WC_Post_types {
'new_item_name' => __( 'New category name', 'woocommerce' ),
'not_found' => __( 'No categories found', 'woocommerce' ),
),
'show_ui' => true,
'query_var' => true,
'capabilities' => array(
'manage_terms' => 'manage_product_terms',
'edit_terms' => 'edit_product_terms',
'delete_terms' => 'delete_product_terms',
'assign_terms' => 'assign_product_terms',
),
'rewrite' => array(
'slug' => $permalinks['category_rewrite_slug'],
'with_front' => false,
'hierarchical' => true,
),
) )
'show_ui' => true,
'query_var' => true,
'capabilities' => array(
'manage_terms' => 'manage_product_terms',
'edit_terms' => 'edit_product_terms',
'delete_terms' => 'delete_product_terms',
'assign_terms' => 'assign_product_terms',
),
'rewrite' => array(
'slug' => $permalinks['category_rewrite_slug'],
'with_front' => false,
'hierarchical' => true,
),
)
)
);
register_taxonomy( 'product_tag',
register_taxonomy(
'product_tag',
apply_filters( 'woocommerce_taxonomy_objects_product_tag', array( 'product' ) ),
apply_filters( 'woocommerce_taxonomy_args_product_tag', array(
'hierarchical' => false,
'update_count_callback' => '_wc_term_recount',
'label' => __( 'Product tags', 'woocommerce' ),
'labels' => array(
apply_filters(
'woocommerce_taxonomy_args_product_tag', array(
'hierarchical' => false,
'update_count_callback' => '_wc_term_recount',
'label' => __( 'Product tags', 'woocommerce' ),
'labels' => array(
'name' => __( 'Product tags', 'woocommerce' ),
'singular_name' => __( 'Tag', 'woocommerce' ),
'menu_name' => _x( 'Tags', 'Admin menu name', 'woocommerce' ),
@ -132,28 +138,31 @@ class WC_Post_types {
'choose_from_most_used' => __( 'Choose from the most used tags', 'woocommerce' ),
'not_found' => __( 'No tags found', 'woocommerce' ),
),
'show_ui' => true,
'query_var' => true,
'capabilities' => array(
'manage_terms' => 'manage_product_terms',
'edit_terms' => 'edit_product_terms',
'delete_terms' => 'delete_product_terms',
'assign_terms' => 'assign_product_terms',
),
'rewrite' => array(
'slug' => $permalinks['tag_rewrite_slug'],
'with_front' => false,
),
) )
'show_ui' => true,
'query_var' => true,
'capabilities' => array(
'manage_terms' => 'manage_product_terms',
'edit_terms' => 'edit_product_terms',
'delete_terms' => 'delete_product_terms',
'assign_terms' => 'assign_product_terms',
),
'rewrite' => array(
'slug' => $permalinks['tag_rewrite_slug'],
'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_args_product_shipping_class', array(
'hierarchical' => false,
'update_count_callback' => '_update_post_term_count',
'label' => __( 'Shipping classes', 'woocommerce' ),
'labels' => array(
apply_filters(
'woocommerce_taxonomy_args_product_shipping_class', array(
'hierarchical' => false,
'update_count_callback' => '_update_post_term_count',
'label' => __( 'Shipping classes', 'woocommerce' ),
'labels' => array(
'name' => __( 'Product shipping classes', 'woocommerce' ),
'singular_name' => __( 'Shipping class', 'woocommerce' ),
'menu_name' => _x( 'Shipping classes', 'Admin menu name', 'woocommerce' ),
@ -166,27 +175,31 @@ class WC_Post_types {
'add_new_item' => __( 'Add new shipping class', 'woocommerce' ),
'new_item_name' => __( 'New shipping class Name', 'woocommerce' ),
),
'show_ui' => false,
'show_in_quick_edit' => false,
'show_in_nav_menus' => false,
'query_var' => is_admin(),
'capabilities' => array(
'manage_terms' => 'manage_product_terms',
'edit_terms' => 'edit_product_terms',
'delete_terms' => 'delete_product_terms',
'assign_terms' => 'assign_product_terms',
),
'rewrite' => false,
) )
'show_ui' => false,
'show_in_quick_edit' => false,
'show_in_nav_menus' => false,
'query_var' => is_admin(),
'capabilities' => array(
'manage_terms' => 'manage_product_terms',
'edit_terms' => 'edit_product_terms',
'delete_terms' => 'delete_product_terms',
'assign_terms' => 'assign_product_terms',
),
'rewrite' => false,
)
)
);
global $wc_product_attributes;
$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 ) {
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 );
$label = ! empty( $tax->attribute_label ) ? $tax->attribute_label : $tax->attribute_name;
$wc_product_attributes[ $name ] = $tax;
@ -194,28 +207,38 @@ class WC_Post_types {
'hierarchical' => false,
'update_count_callback' => '_update_post_term_count',
'labels' => array(
'name' => sprintf( _x( 'Product %s', 'Product Attribute', 'woocommerce' ), $label ),
'singular_name' => $label,
'search_items' => sprintf( __( 'Search %s', 'woocommerce' ), $label ),
'all_items' => sprintf( __( 'All %s', 'woocommerce' ), $label ),
'parent_item' => sprintf( __( 'Parent %s', 'woocommerce' ), $label ),
'parent_item_colon' => sprintf( __( 'Parent %s:', 'woocommerce' ), $label ),
'edit_item' => sprintf( __( 'Edit %s', 'woocommerce' ), $label ),
'update_item' => sprintf( __( 'Update %s', 'woocommerce' ), $label ),
'add_new_item' => sprintf( __( 'Add new %s', 'woocommerce' ), $label ),
'new_item_name' => sprintf( __( 'New %s', 'woocommerce' ), $label ),
'not_found' => sprintf( __( 'No &quot;%s&quot; found', 'woocommerce' ), $label ),
),
'show_ui' => true,
'show_in_quick_edit' => false,
'show_in_menu' => false,
'meta_box_cb' => false,
'query_var' => 1 === $tax->attribute_public,
'rewrite' => false,
'sort' => false,
'public' => 1 === $tax->attribute_public,
'show_in_nav_menus' => 1 === $tax->attribute_public && apply_filters( 'woocommerce_attribute_show_in_nav_menus', false, $name ),
'capabilities' => array(
/* translators: %s: attribute name */
'name' => sprintf( _x( 'Product %s', 'Product Attribute', 'woocommerce' ), $label ),
'singular_name' => $label,
/* translators: %s: attribute name */
'search_items' => sprintf( __( 'Search %s', 'woocommerce' ), $label ),
/* translators: %s: attribute name */
'all_items' => sprintf( __( 'All %s', 'woocommerce' ), $label ),
/* translators: %s: attribute name */
'parent_item' => sprintf( __( 'Parent %s', 'woocommerce' ), $label ),
/* translators: %s: attribute name */
'parent_item_colon' => sprintf( __( 'Parent %s:', 'woocommerce' ), $label ),
/* translators: %s: attribute name */
'edit_item' => sprintf( __( 'Edit %s', 'woocommerce' ), $label ),
/* translators: %s: attribute name */
'update_item' => sprintf( __( 'Update %s', 'woocommerce' ), $label ),
/* translators: %s: attribute name */
'add_new_item' => sprintf( __( 'Add new %s', 'woocommerce' ), $label ),
/* translators: %s: attribute name */
'new_item_name' => sprintf( __( 'New %s', 'woocommerce' ), $label ),
/* translators: %s: attribute name */
'not_found' => sprintf( __( 'No &quot;%s&quot; found', 'woocommerce' ), $label ),
),
'show_ui' => true,
'show_in_quick_edit' => false,
'show_in_menu' => false,
'meta_box_cb' => false,
'query_var' => 1 === $tax->attribute_public,
'rewrite' => false,
'sort' => false,
'public' => 1 === $tax->attribute_public,
'show_in_nav_menus' => 1 === $tax->attribute_public && apply_filters( 'woocommerce_attribute_show_in_nav_menus', false, $name ),
'capabilities' => array(
'manage_terms' => 'manage_product_terms',
'edit_terms' => 'edit_product_terms',
'delete_terms' => 'delete_product_terms',
@ -250,7 +273,7 @@ class WC_Post_types {
do_action( 'woocommerce_register_post_type' );
$permalinks = wc_get_permalink_structure();
$supports = array( 'title', 'editor', 'excerpt', 'thumbnail', 'custom-fields', 'publicize', 'wpcom-markdown' );
$supports = array( 'title', 'editor', 'excerpt', 'thumbnail', 'custom-fields', 'publicize', 'wpcom-markdown' );
if ( 'yes' === get_option( 'woocommerce_enable_reviews', 'yes' ) ) {
$supports[] = 'comments';
@ -259,7 +282,7 @@ class WC_Post_types {
$shop_page_id = wc_get_page_id( 'shop' );
if ( current_theme_supports( 'woocommerce' ) ) {
$has_archive = $shop_page_id && get_post( $shop_page_id ) ? urldecode( get_page_uri( $shop_page_id ) ) : 'shop';
$has_archive = $shop_page_id && get_post( $shop_page_id ) ? urldecode( get_page_uri( $shop_page_id ) ) : 'shop';
} else {
$has_archive = false;
}
@ -269,35 +292,37 @@ class WC_Post_types {
update_option( 'woocommerce_queue_flush_rewrite_rules', 'yes' );
}
register_post_type( 'product',
apply_filters( 'woocommerce_register_post_type_product',
register_post_type(
'product',
apply_filters(
'woocommerce_register_post_type_product',
array(
'labels' => array(
'name' => __( 'Products', 'woocommerce' ),
'singular_name' => __( 'Product', 'woocommerce' ),
'all_items' => __( 'All Products', 'woocommerce' ),
'menu_name' => _x( 'Products', 'Admin menu name', 'woocommerce' ),
'add_new' => __( 'Add New', 'woocommerce' ),
'add_new_item' => __( 'Add new product', 'woocommerce' ),
'edit' => __( 'Edit', 'woocommerce' ),
'edit_item' => __( 'Edit product', 'woocommerce' ),
'new_item' => __( 'New product', 'woocommerce' ),
'view_item' => __( 'View product', 'woocommerce' ),
'view_items' => __( 'View products', 'woocommerce' ),
'search_items' => __( 'Search products', 'woocommerce' ),
'not_found' => __( 'No products found', 'woocommerce' ),
'not_found_in_trash' => __( 'No products found in trash', 'woocommerce' ),
'parent' => __( 'Parent product', 'woocommerce' ),
'featured_image' => __( 'Product image', 'woocommerce' ),
'set_featured_image' => __( 'Set product image', 'woocommerce' ),
'remove_featured_image' => __( 'Remove product image', 'woocommerce' ),
'use_featured_image' => __( 'Use as product image', 'woocommerce' ),
'insert_into_item' => __( 'Insert into product', 'woocommerce' ),
'uploaded_to_this_item' => __( 'Uploaded to this product', 'woocommerce' ),
'filter_items_list' => __( 'Filter products', 'woocommerce' ),
'items_list_navigation' => __( 'Products navigation', 'woocommerce' ),
'items_list' => __( 'Products list', 'woocommerce' ),
),
'name' => __( 'Products', 'woocommerce' ),
'singular_name' => __( 'Product', 'woocommerce' ),
'all_items' => __( 'All Products', 'woocommerce' ),
'menu_name' => _x( 'Products', 'Admin menu name', 'woocommerce' ),
'add_new' => __( 'Add New', 'woocommerce' ),
'add_new_item' => __( 'Add new product', 'woocommerce' ),
'edit' => __( 'Edit', 'woocommerce' ),
'edit_item' => __( 'Edit product', 'woocommerce' ),
'new_item' => __( 'New product', 'woocommerce' ),
'view_item' => __( 'View product', 'woocommerce' ),
'view_items' => __( 'View products', 'woocommerce' ),
'search_items' => __( 'Search products', 'woocommerce' ),
'not_found' => __( 'No products found', 'woocommerce' ),
'not_found_in_trash' => __( 'No products found in trash', 'woocommerce' ),
'parent' => __( 'Parent product', 'woocommerce' ),
'featured_image' => __( 'Product image', 'woocommerce' ),
'set_featured_image' => __( 'Set product image', 'woocommerce' ),
'remove_featured_image' => __( 'Remove product image', 'woocommerce' ),
'use_featured_image' => __( 'Use as product image', 'woocommerce' ),
'insert_into_item' => __( 'Insert into product', 'woocommerce' ),
'uploaded_to_this_item' => __( 'Uploaded to this product', 'woocommerce' ),
'filter_items_list' => __( 'Filter products', 'woocommerce' ),
'items_list_navigation' => __( 'Products navigation', 'woocommerce' ),
'items_list' => __( 'Products list', 'woocommerce' ),
),
'description' => __( 'This is where you can add new products to your store.', 'woocommerce' ),
'public' => true,
'show_ui' => true,
@ -306,7 +331,11 @@ class WC_Post_types {
'publicly_queryable' => true,
'exclude_from_search' => false,
'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,
'supports' => $supports,
'has_archive' => $has_archive,
@ -316,8 +345,10 @@ class WC_Post_types {
)
);
register_post_type( 'product_variation',
apply_filters( 'woocommerce_register_post_type_product_variation',
register_post_type(
'product_variation',
apply_filters(
'woocommerce_register_post_type_product_variation',
array(
'label' => __( 'Variations', 'woocommerce' ),
'public' => false,
@ -331,26 +362,27 @@ class WC_Post_types {
wc_register_order_type(
'shop_order',
apply_filters( 'woocommerce_register_post_type_shop_order',
apply_filters(
'woocommerce_register_post_type_shop_order',
array(
'labels' => array(
'name' => __( 'Orders', 'woocommerce' ),
'singular_name' => _x( 'Order', 'shop_order post type singular name', 'woocommerce' ),
'add_new' => __( 'Add order', 'woocommerce' ),
'add_new_item' => __( 'Add new order', 'woocommerce' ),
'edit' => __( 'Edit', 'woocommerce' ),
'edit_item' => __( 'Edit order', 'woocommerce' ),
'new_item' => __( 'New order', 'woocommerce' ),
'view_item' => __( 'View order', 'woocommerce' ),
'search_items' => __( 'Search orders', 'woocommerce' ),
'not_found' => __( 'No orders found', 'woocommerce' ),
'not_found_in_trash' => __( 'No orders found in trash', 'woocommerce' ),
'parent' => __( 'Parent orders', 'woocommerce' ),
'menu_name' => _x( 'Orders', 'Admin menu name', 'woocommerce' ),
'filter_items_list' => __( 'Filter orders', 'woocommerce' ),
'items_list_navigation' => __( 'Orders navigation', 'woocommerce' ),
'items_list' => __( 'Orders list', 'woocommerce' ),
),
'name' => __( 'Orders', 'woocommerce' ),
'singular_name' => _x( 'Order', 'shop_order post type singular name', 'woocommerce' ),
'add_new' => __( 'Add order', 'woocommerce' ),
'add_new_item' => __( 'Add new order', 'woocommerce' ),
'edit' => __( 'Edit', 'woocommerce' ),
'edit_item' => __( 'Edit order', 'woocommerce' ),
'new_item' => __( 'New order', 'woocommerce' ),
'view_item' => __( 'View order', 'woocommerce' ),
'search_items' => __( 'Search orders', 'woocommerce' ),
'not_found' => __( 'No orders found', 'woocommerce' ),
'not_found_in_trash' => __( 'No orders found in trash', 'woocommerce' ),
'parent' => __( 'Parent orders', 'woocommerce' ),
'menu_name' => _x( 'Orders', 'Admin menu name', 'woocommerce' ),
'filter_items_list' => __( 'Filter orders', 'woocommerce' ),
'items_list_navigation' => __( 'Orders navigation', 'woocommerce' ),
'items_list' => __( 'Orders list', 'woocommerce' ),
),
'description' => __( 'This is where store orders are stored.', 'woocommerce' ),
'public' => false,
'show_ui' => true,
@ -371,7 +403,8 @@ class WC_Post_types {
wc_register_order_type(
'shop_order_refund',
apply_filters( 'woocommerce_register_post_type_shop_order_refund',
apply_filters(
'woocommerce_register_post_type_shop_order_refund',
array(
'label' => __( 'Refunds', 'woocommerce' ),
'capability_type' => 'shop_order',
@ -390,28 +423,30 @@ class WC_Post_types {
)
);
if ( 'yes' == get_option( 'woocommerce_enable_coupons' ) ) {
register_post_type( 'shop_coupon',
apply_filters( 'woocommerce_register_post_type_shop_coupon',
if ( 'yes' === get_option( 'woocommerce_enable_coupons' ) ) {
register_post_type(
'shop_coupon',
apply_filters(
'woocommerce_register_post_type_shop_coupon',
array(
'labels' => array(
'name' => __( 'Coupons', 'woocommerce' ),
'singular_name' => __( 'Coupon', 'woocommerce' ),
'menu_name' => _x( 'Coupons', 'Admin menu name', 'woocommerce' ),
'add_new' => __( 'Add coupon', 'woocommerce' ),
'add_new_item' => __( 'Add new coupon', 'woocommerce' ),
'edit' => __( 'Edit', 'woocommerce' ),
'edit_item' => __( 'Edit coupon', 'woocommerce' ),
'new_item' => __( 'New coupon', 'woocommerce' ),
'view_item' => __( 'View coupon', 'woocommerce' ),
'search_items' => __( 'Search coupons', 'woocommerce' ),
'not_found' => __( 'No coupons found', 'woocommerce' ),
'not_found_in_trash' => __( 'No coupons found in trash', 'woocommerce' ),
'parent' => __( 'Parent coupon', 'woocommerce' ),
'filter_items_list' => __( 'Filter coupons', 'woocommerce' ),
'items_list_navigation' => __( 'Coupons navigation', 'woocommerce' ),
'items_list' => __( 'Coupons list', 'woocommerce' ),
),
'name' => __( 'Coupons', 'woocommerce' ),
'singular_name' => __( 'Coupon', 'woocommerce' ),
'menu_name' => _x( 'Coupons', 'Admin menu name', 'woocommerce' ),
'add_new' => __( 'Add coupon', 'woocommerce' ),
'add_new_item' => __( 'Add new coupon', 'woocommerce' ),
'edit' => __( 'Edit', 'woocommerce' ),
'edit_item' => __( 'Edit coupon', 'woocommerce' ),
'new_item' => __( 'New coupon', 'woocommerce' ),
'view_item' => __( 'View coupon', 'woocommerce' ),
'search_items' => __( 'Search coupons', 'woocommerce' ),
'not_found' => __( 'No coupons found', 'woocommerce' ),
'not_found_in_trash' => __( 'No coupons found in trash', 'woocommerce' ),
'parent' => __( 'Parent coupon', 'woocommerce' ),
'filter_items_list' => __( 'Filter coupons', 'woocommerce' ),
'items_list_navigation' => __( 'Coupons navigation', 'woocommerce' ),
'items_list' => __( 'Coupons list', 'woocommerce' ),
),
'description' => __( 'This is where you can add new coupons that customers can use in your store.', 'woocommerce' ),
'public' => false,
'show_ui' => true,
@ -439,7 +474,8 @@ class WC_Post_types {
*/
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(
'wc-pending' => array(
'label' => _x( 'Pending payment', 'Order status', 'woocommerce' ),
@ -447,6 +483,7 @@ class WC_Post_types {
'exclude_from_search' => false,
'show_in_admin_all_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' ),
),
'wc-processing' => array(
@ -455,6 +492,7 @@ class WC_Post_types {
'exclude_from_search' => false,
'show_in_admin_all_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' ),
),
'wc-on-hold' => array(
@ -463,6 +501,7 @@ class WC_Post_types {
'exclude_from_search' => false,
'show_in_admin_all_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' ),
),
'wc-completed' => array(
@ -471,6 +510,7 @@ class WC_Post_types {
'exclude_from_search' => false,
'show_in_admin_all_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' ),
),
'wc-cancelled' => array(
@ -479,6 +519,7 @@ class WC_Post_types {
'exclude_from_search' => false,
'show_in_admin_all_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' ),
),
'wc-refunded' => array(
@ -487,6 +528,7 @@ class WC_Post_types {
'exclude_from_search' => false,
'show_in_admin_all_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' ),
),
'wc-failed' => array(
@ -495,6 +537,7 @@ class WC_Post_types {
'exclude_from_search' => false,
'show_in_admin_all_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' ),
),
)
@ -536,7 +579,7 @@ class WC_Post_types {
/**
* Added product for Jetpack related posts.
*
* @param array $post_types
* @param array $post_types Post types.
* @return array
*/
public static function rest_api_allowed_post_types( $post_types ) {

View File

@ -1,18 +1,19 @@
<?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.
* Uses ArrayAccess to be BW compatible with previous ways of reading attributes.
*
* @version 3.0.0
* @since 3.0.0
* @package WooCommerce/Classes
* @author WooThemes
* @package WooCommerce/Classes
* @version 3.0.0
* @since 3.0.0
*/
defined( 'ABSPATH' ) || exit;
/**
* Product attribute class.
*/
class WC_Product_Attribute implements ArrayAccess {
@ -122,12 +123,14 @@ class WC_Product_Attribute implements ArrayAccess {
* @return array
*/
public function get_data() {
return array_merge( $this->data, array(
'is_visible' => $this->get_visible() ? 1 : 0,
'is_variation' => $this->get_variation() ? 1 : 0,
'is_taxonomy' => $this->is_taxonomy() ? 1 : 0,
'value' => $this->is_taxonomy() ? '' : wc_implode_text_attributes( $this->get_options() ),
) );
return array_merge(
$this->data, array(
'is_visible' => $this->get_visible() ? 1 : 0,
'is_variation' => $this->get_variation() ? 1 : 0,
'is_taxonomy' => $this->is_taxonomy() ? 1 : 0,
'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).
*
* @param int $value
* @param int $value Attribute ID.
*/
public function set_id( $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).
*
* @param int $value
* @param int $value Attribute name.
*/
public function set_name( $value ) {
$this->data['name'] = $value;
@ -157,7 +160,7 @@ class WC_Product_Attribute implements ArrayAccess {
/**
* Set options.
*
* @param array $value
* @param array $value Attribute options.
*/
public function set_options( $value ) {
$this->data['options'] = $value;
@ -166,7 +169,7 @@ class WC_Product_Attribute implements ArrayAccess {
/**
* Set position.
*
* @param int $value
* @param int $value Attribute position.
*/
public function set_position( $value ) {
$this->data['position'] = absint( $value );
@ -175,7 +178,7 @@ class WC_Product_Attribute implements ArrayAccess {
/**
* Set if visible.
*
* @param bool $value
* @param bool $value If is visible on Product's additional info tab.
*/
public function set_visible( $value ) {
$this->data['visible'] = wc_string_to_bool( $value );
@ -184,7 +187,7 @@ class WC_Product_Attribute implements ArrayAccess {
/**
* Set if variation.
*
* @param bool $value
* @param bool $value If is used for variations.
*/
public function set_variation( $value ) {
$this->data['variation'] = wc_string_to_bool( $value );
@ -257,26 +260,22 @@ class WC_Product_Attribute implements ArrayAccess {
*/
/**
* offsetGet.
* OffsetGet.
*
* @param string $offset
* @param string $offset Offset.
* @return mixed
*/
public function offsetGet( $offset ) {
switch ( $offset ) {
case 'is_variation' :
case 'is_variation':
return $this->get_variation() ? 1 : 0;
break;
case 'is_visible' :
case 'is_visible':
return $this->get_visible() ? 1 : 0;
break;
case 'is_taxonomy' :
case 'is_taxonomy':
return $this->is_taxonomy() ? 1 : 0;
break;
case 'value' :
case 'value':
return $this->is_taxonomy() ? '' : wc_implode_text_attributes( $this->get_options() );
break;
default :
default:
if ( is_callable( array( $this, "get_$offset" ) ) ) {
return $this->{"get_$offset"}();
}
@ -286,23 +285,23 @@ class WC_Product_Attribute implements ArrayAccess {
}
/**
* offsetSet.
* OffsetSet.
*
* @param string $offset
* @param mixed $value
* @param string $offset Offset.
* @param mixed $value Value.
*/
public function offsetSet( $offset, $value ) {
switch ( $offset ) {
case 'is_variation' :
case 'is_variation':
$this->set_variation( $value );
break;
case 'is_visible' :
case 'is_visible':
$this->set_visible( $value );
break;
case 'value' :
case 'value':
$this->set_options( $value );
break;
default :
default:
if ( is_callable( array( $this, "set_$offset" ) ) ) {
return $this->{"set_$offset"}( $value );
}
@ -311,19 +310,19 @@ class WC_Product_Attribute implements ArrayAccess {
}
/**
* offsetUnset.
* OffsetUnset.
*
* @param string $offset
* @param string $offset Offset.
*/
public function offsetUnset( $offset ) {}
/**
* offsetExists.
* OffsetExists.
*
* @param string $offset
* @param string $offset Offset.
* @return bool
*/
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 );
}
}

View File

@ -1,31 +1,34 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Represents a file which can be downloaded.
*
* @version 3.0.0
* @since 3.0.0
* @package WooCommerce/Classes
* @author WooThemes
* @package WooCommerce/Classes
* @version 3.0.0
* @since 3.0.0
*/
defined( 'ABSPATH' ) || exit;
/**
* Product download class.
*/
class WC_Product_Download implements ArrayAccess {
/**
* Data array.
*
* @since 3.0.0
* @var array
*/
protected $data = array(
'id' => '',
'name' => '',
'file' => '',
'id' => '',
'name' => '',
'file' => '',
);
/**
* Returns all data for this object.
*
* @return array
*/
public function get_data() {
@ -34,6 +37,7 @@ class WC_Product_Download implements ArrayAccess {
/**
* Get allowed mime types.
*
* @return array
*/
public function get_allowed_mime_types() {
@ -42,6 +46,7 @@ class WC_Product_Download implements ArrayAccess {
/**
* Get type of file path set.
*
* @param string $file_path optional.
* @return string absolute, relative, or shortcode.
*/
@ -58,6 +63,7 @@ class WC_Product_Download implements ArrayAccess {
/**
* Get file type.
*
* @return string
*/
public function get_file_type() {
@ -67,26 +73,29 @@ class WC_Product_Download implements ArrayAccess {
/**
* Get file extension.
*
* @return string
*/
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 );
}
/**
* Check if file is allowed.
*
* @return boolean
*/
public function is_allowed_filetype() {
if ( 'relative' !== $this->get_type_of_file_path() ) {
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.
*
* @return boolean
*/
public function file_exists() {
@ -110,7 +119,8 @@ class WC_Product_Download implements ArrayAccess {
/**
* Set ID.
* @param string $value
*
* @param string $value Download ID.
*/
public function set_id( $value ) {
$this->data['id'] = wc_clean( $value );
@ -118,7 +128,8 @@ class WC_Product_Download implements ArrayAccess {
/**
* Set name.
* @param string $value
*
* @param string $value Download name.
*/
public function set_name( $value ) {
$this->data['name'] = wc_clean( $value );
@ -126,8 +137,9 @@ class WC_Product_Download implements ArrayAccess {
/**
* Set previous_hash.
*
* @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 ) {
wc_deprecated_function( __FUNCTION__, '3.3' );
@ -136,11 +148,12 @@ class WC_Product_Download implements ArrayAccess {
/**
* Set file.
* @param string $value
*
* @param string $value File.
*/
public function set_file( $value ) {
switch ( $this->get_type_of_file_path( $value ) ) {
case 'absolute' :
case 'absolute':
$this->data['file'] = esc_url_raw( $value );
break;
default:
@ -157,6 +170,7 @@ class WC_Product_Download implements ArrayAccess {
/**
* Get id.
*
* @return string
*/
public function get_id() {
@ -165,6 +179,7 @@ class WC_Product_Download implements ArrayAccess {
/**
* Get name.
*
* @return string
*/
public function get_name() {
@ -173,6 +188,7 @@ class WC_Product_Download implements ArrayAccess {
/**
* Get previous_hash.
*
* @deprecated 3.3.0 No longer using filename based hashing to keep track of files.
* @return string
*/
@ -183,6 +199,7 @@ class WC_Product_Download implements ArrayAccess {
/**
* Get file.
*
* @return string
*/
public function get_file() {
@ -196,13 +213,14 @@ class WC_Product_Download implements ArrayAccess {
*/
/**
* offsetGet
* @param string $offset
* OffsetGet.
*
* @param string $offset Offset.
* @return mixed
*/
public function offsetGet( $offset ) {
switch ( $offset ) {
default :
default:
if ( is_callable( array( $this, "get_$offset" ) ) ) {
return $this->{"get_$offset"}();
}
@ -212,13 +230,14 @@ class WC_Product_Download implements ArrayAccess {
}
/**
* offsetSet
* @param string $offset
* @param mixed $value
* OffsetSet.
*
* @param string $offset Offset.
* @param mixed $value Value.
*/
public function offsetSet( $offset, $value ) {
switch ( $offset ) {
default :
default:
if ( is_callable( array( $this, "set_$offset" ) ) ) {
return $this->{"set_$offset"}( $value );
}
@ -227,17 +246,19 @@ class WC_Product_Download implements ArrayAccess {
}
/**
* offsetUnset
* @param string $offset
* OffsetUnset.
*
* @param string $offset Offset.
*/
public function offsetUnset( $offset ) {}
/**
* offsetExists
* @param string $offset
* OffsetExists.
*
* @param string $offset Offset.
* @return bool
*/
public function offsetExists( $offset ) {
return in_array( $offset, array_keys( $this->data ) );
return in_array( $offset, array_keys( $this->data ), true );
}
}

View File

@ -1,18 +1,17 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* External Product Class.
* External Product
*
* External products cannot be bought; they link offsite. Extends simple products.
*
* @class WC_Product_External
* @version 3.0.0
* @package WooCommerce/Classes/Products
* @category Class
* @author WooThemes
* @package WooCommerce/Classes/Products
* @version 3.0.0
*/
defined( 'ABSPATH' ) || exit;
/**
* Product external class.
*/
class WC_Product_External extends WC_Product {
@ -28,6 +27,7 @@ class WC_Product_External extends WC_Product {
/**
* Get internal type.
*
* @return string
*/
public function get_type() {
@ -45,7 +45,7 @@ class WC_Product_External extends WC_Product {
/**
* Get product url.
*
* @param string $context
* @param string $context What the value is for. Valid values are 'view' and 'edit'.
* @return string
*/
public function get_product_url( $context = 'view' ) {
@ -55,7 +55,7 @@ class WC_Product_External extends WC_Product {
/**
* Get button text.
*
* @param string $context
* @param string $context What the value is for. Valid values are 'view' and 'edit'.
* @return string
*/
public function get_button_text( $context = 'view' ) {
@ -96,7 +96,7 @@ class WC_Product_External extends WC_Product {
* External products cannot be stock managed.
*
* @since 3.0.0
* @param bool
* @param bool $manage_stock If manage stock.
*/
public function set_manage_stock( $manage_stock ) {
$this->set_prop( 'manage_stock', false );
@ -111,7 +111,7 @@ class WC_Product_External extends WC_Product {
*
* @since 3.0.0
*
* @param string $stock_status
* @param string $stock_status Stock status.
*/
public function set_stock_status( $stock_status = '' ) {
$this->set_prop( 'stock_status', 'instock' );

View File

@ -1,31 +1,31 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Product Factory Class
* Product Factory
*
* The WooCommerce product factory creating the right product object.
*
* @class WC_Product_Factory
* @version 3.0.0
* @package WooCommerce/Classes
* @category Class
* @author WooThemes
* @package WooCommerce/Classes
* @version 3.0.0
*/
defined( 'ABSPATH' ) || exit;
/**
* Product factory class.
*/
class WC_Product_Factory {
/**
* 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.
* @return WC_Product|bool Product object or null if the product cannot be loaded.
*/
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;
}
@ -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.
*
* @since 3.0.0
* @param int $product_id
* @param string $product_type
* @param int $product_id Product ID.
* @param string $product_type Product type.
* @return string
*/
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.
*
* @since 3.0.0
* @param int $product_id
* @param int $product_id Product ID.
* @return string|false
*/
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.
*
* @param string $product_type
* @param string $product_type Product type.
* @return string|false
*/
public static function get_classname_from_product_type( $product_type ) {
@ -97,8 +97,8 @@ class WC_Product_Factory {
/**
* Get the product ID depending on what was passed.
*
* @since 3.0.0
* @param mixed $product
* @since 3.0.0
* @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
*/
private function get_product_id( $product ) {

View File

@ -1,22 +1,17 @@
<?php
/**
* Class WC_Product_Grouped file.
*
* @package WooCommerce\Classes\Products
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Grouped Product Class.
* Grouped Product
*
* Grouped products cannot be purchased - they are wrappers for other products.
*
* @class WC_Product_Grouped
* @version 3.0.0
* @package WooCommerce/Classes/Products
* @package WooCommerce\Classes\Products
* @version 3.0.0
*/
defined( 'ABSPATH' ) || exit;
/**
* Product grouped class.
*/
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.
*
* @access public
* @return string
*/
public function add_to_cart_text() {
@ -91,7 +85,6 @@ class WC_Product_Grouped extends WC_Product {
/**
* Returns the price in html format.
*
* @access public
* @param string $price (default: '').
* @return string
*/

View File

@ -1,73 +1,77 @@
<?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
*
* @package WooCommerce/Classes
* @version 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 {
/**
* Valid query vars for products.
*
* @return array
*/
protected function get_default_query_vars() {
return array_merge(
parent::get_default_query_vars(),
array(
'status' => array( 'draft', 'pending', 'private', 'publish' ),
'type' => array_merge( array_keys( wc_get_product_types() ) ),
'limit' => get_option( 'posts_per_page' ),
'include' => array(),
'date_created' => '',
'date_modified' => '',
'featured' => '',
'visibility' => '',
'sku' => '',
'price' => '',
'regular_price' => '',
'sale_price' => '',
'date_on_sale_from' => '',
'date_on_sale_to' => '',
'total_sales' => '',
'tax_status' => '',
'tax_class' => '',
'manage_stock' => '',
'stock_quantity' => '',
'stock_status' => '',
'backorders' => '',
'sold_individually' => '',
'weight' => '',
'length' => '',
'width' => '',
'height' => '',
'reviews_allowed' => '',
'virtual' => '',
'downloadable' => '',
'category' => array(),
'tag' => array(),
'shipping_class' => array(),
'download_limit' => '',
'download_expiry' => '',
'average_rating' => '',
'review_count' => '',
'status' => array( 'draft', 'pending', 'private', 'publish' ),
'type' => array_merge( array_keys( wc_get_product_types() ) ),
'limit' => get_option( 'posts_per_page' ),
'include' => array(),
'date_created' => '',
'date_modified' => '',
'featured' => '',
'visibility' => '',
'sku' => '',
'price' => '',
'regular_price' => '',
'sale_price' => '',
'date_on_sale_from' => '',
'date_on_sale_to' => '',
'total_sales' => '',
'tax_status' => '',
'tax_class' => '',
'manage_stock' => '',
'stock_quantity' => '',
'stock_status' => '',
'backorders' => '',
'sold_individually' => '',
'weight' => '',
'length' => '',
'width' => '',
'height' => '',
'reviews_allowed' => '',
'virtual' => '',
'downloadable' => '',
'category' => array(),
'tag' => array(),
'shipping_class' => array(),
'download_limit' => '',
'download_expiry' => '',
'average_rating' => '',
'review_count' => '',
)
);
}
/**
* Get products matching the current query vars.
*
* @return array|object of WC_Product objects
*/
public function get_products() {
$args = apply_filters( 'woocommerce_product_object_query_args', $this->get_query_vars() );
$args = apply_filters( 'woocommerce_product_object_query_args', $this->get_query_vars() );
$results = WC_Data_Store::load( 'product' )->query( $args );
return apply_filters( 'woocommerce_product_object_query', $results, $args );
}

View File

@ -1,33 +1,32 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Simple Product Class.
*
* The default product type kinda product.
*
* @class WC_Product_Simple
* @package WooCommerce/Classes/Products
* @category Class
* @author WooThemes
* @package WooCommerce/Classes/Products
*/
defined( 'ABSPATH' ) || exit;
/**
* Simple product class.
*/
class WC_Product_Simple extends WC_Product {
/**
* Initialize simple product.
*
* @param mixed $product
* @param WC_Product|int $product Product instance or ID.
*/
public function __construct( $product = 0 ) {
$this->supports[] = 'ajax_add_to_cart';
$this->supports[] = 'ajax_add_to_cart';
parent::__construct( $product );
}
/**
* Get internal type.
*
* @return string
*/
public function get_type() {

View File

@ -1,17 +1,17 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Variable Product Class.
* Variable Product
*
* The WooCommerce product class handles individual product data.
*
* @version 3.0.0
* @package WooCommerce/Classes/Products
* @category Class
* @author WooThemes
* @version 3.0.0
* @package WooCommerce/Classes/Products
*/
defined( 'ABSPATH' ) || exit;
/**
* Variable product class.
*/
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.
*
* @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.
*/
public function get_variation_prices( $for_display = false ) {
@ -91,9 +90,8 @@ class WC_Product_Variable extends WC_Product {
/**
* Get the min or max variation regular price.
*
* @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).
*
* @return string
*/
public function get_variation_regular_price( $min_or_max = 'min', $for_display = false ) {
@ -106,9 +104,8 @@ class WC_Product_Variable extends WC_Product {
/**
* Get the min or max variation sale price.
*
* @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).
*
* @return string
*/
public function get_variation_sale_price( $min_or_max = 'min', $for_display = false ) {
@ -121,9 +118,8 @@ class WC_Product_Variable extends WC_Product {
/**
* Get the min or max variation (active) price.
*
* @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).
*
* @return string
*/
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
* is shown instead.
*
* @param string $price (default: '')
*
* @param string $price Price (default: '').
* @return string
*/
public function get_price_html( $price = '' ) {
@ -180,11 +175,10 @@ class WC_Product_Variable extends WC_Product {
*
* This is skipped if the suffix
* has dynamic values such as {price_excluding_tax} for variable products.
*
* @see get_price_html for an explanation as to why.
*
* @param string $price to calculate, left blank to just use get_price()
* @param integer $qty passed on to get_price_including_tax() or get_price_excluding_tax()
*
* @param string $price 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().
* @return string
*/
public function get_price_suffix( $price = '', $qty = 1 ) {
@ -200,8 +194,7 @@ class WC_Product_Variable extends WC_Product {
/**
* Return a products child ids.
*
* @param bool|string $visible_only
*
* @param bool|string $visible_only Visible only.
* @return array Children ids
*/
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.
*
* @param string $attribute_name
*
* @param string $attribute_name Attribute name.
* @return string
*/
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.
*
* @param string $context
*
* @param string $context What the value is for. Valid values are view and edit.
* @return bool
*/
public function get_downloadable( $context = 'view' ) {
@ -261,8 +252,7 @@ class WC_Product_Variable extends WC_Product {
/**
* 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
*/
public function get_virtual( $context = 'view' ) {
@ -280,7 +270,7 @@ class WC_Product_Variable extends WC_Product {
foreach ( $this->get_children() as $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() ) ) {
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.
*
* @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
*/
public function get_available_variation( $variation ) {
@ -313,34 +302,36 @@ class WC_Product_Variable extends WC_Product {
return false;
}
// 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(
'attributes' => $variation->get_variation_attributes(),
'availability_html' => wc_get_stock_html( $variation ),
'backorders_allowed' => $variation->backorders_allowed(),
'dimensions' => $variation->get_dimensions( false ),
'dimensions_html' => wc_format_dimensions( $variation->get_dimensions( false ) ),
'display_price' => wc_get_price_to_display( $variation ),
'display_regular_price' => wc_get_price_to_display( $variation, array( 'price' => $variation->get_regular_price() ) ),
'image' => wc_get_product_attachment_props( $variation->get_image_id() ),
'image_id' => $variation->get_image_id(),
'is_downloadable' => $variation->is_downloadable(),
'is_in_stock' => $variation->is_in_stock(),
'is_purchasable' => $variation->is_purchasable(),
'is_sold_individually' => $variation->is_sold_individually() ? 'yes' : 'no',
'is_virtual' => $variation->is_virtual(),
'max_qty' => 0 < $variation->get_max_purchase_quantity() ? $variation->get_max_purchase_quantity() : '',
'min_qty' => $variation->get_min_purchase_quantity(),
'price_html' => $show_variation_price ? '<span class="price">' . $variation->get_price_html() . '</span>' : '',
'sku' => $variation->get_sku(),
'variation_description' => wc_format_content( $variation->get_description() ),
'variation_id' => $variation->get_id(),
'variation_is_active' => $variation->variation_is_active(),
'variation_is_visible' => $variation->variation_is_visible(),
'weight' => $variation->get_weight(),
'weight_html' => wc_format_weight( $variation->get_weight() ),
), $this, $variation );
return apply_filters(
'woocommerce_available_variation', array(
'attributes' => $variation->get_variation_attributes(),
'availability_html' => wc_get_stock_html( $variation ),
'backorders_allowed' => $variation->backorders_allowed(),
'dimensions' => $variation->get_dimensions( false ),
'dimensions_html' => wc_format_dimensions( $variation->get_dimensions( false ) ),
'display_price' => wc_get_price_to_display( $variation ),
'display_regular_price' => wc_get_price_to_display( $variation, array( 'price' => $variation->get_regular_price() ) ),
'image' => wc_get_product_attachment_props( $variation->get_image_id() ),
'image_id' => $variation->get_image_id(),
'is_downloadable' => $variation->is_downloadable(),
'is_in_stock' => $variation->is_in_stock(),
'is_purchasable' => $variation->is_purchasable(),
'is_sold_individually' => $variation->is_sold_individually() ? 'yes' : 'no',
'is_virtual' => $variation->is_virtual(),
'max_qty' => 0 < $variation->get_max_purchase_quantity() ? $variation->get_max_purchase_quantity() : '',
'min_qty' => $variation->get_min_purchase_quantity(),
'price_html' => $show_variation_price ? '<span class="price">' . $variation->get_price_html() . '</span>' : '',
'sku' => $variation->get_sku(),
'variation_description' => wc_format_content( $variation->get_description() ),
'variation_id' => $variation->get_id(),
'variation_is_active' => $variation->variation_is_active(),
'variation_is_visible' => $variation->variation_is_visible(),
'weight' => $variation->get_weight(),
'weight_html' => wc_format_weight( $variation->get_weight() ),
), $this, $variation
);
}
/*
@ -353,8 +344,7 @@ class WC_Product_Variable extends WC_Product {
* Sets an array of variation attributes.
*
* @since 3.0.0
*
* @param array
* @param array $variation_attributes Attributes list.
*/
public function set_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.
*
* @since 3.0.0
*
* @param array
* @param array $children Childre products.
*/
public function set_children( $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.
*
* @since 3.0.0
*
* @param array
* @param array $visible_children List of visible children products.
*/
public function set_visible_children( $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.
*
* @since 3.0.0
*/
public function validate_props() {
@ -454,8 +443,7 @@ class WC_Product_Variable extends WC_Product {
/**
* 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
*/
public function is_on_sale( $context = 'view' ) {
@ -467,6 +455,7 @@ class WC_Product_Variable extends WC_Product {
/**
* Is a child in stock?
*
* @return boolean
*/
public function child_is_in_stock() {
@ -485,6 +474,7 @@ class WC_Product_Variable extends WC_Product {
/**
* Does a child have a weight set?
*
* @return boolean
*/
public function child_has_weight() {
@ -501,6 +491,7 @@ class WC_Product_Variable extends WC_Product {
/**
* Does a child have dimensions set?
*
* @return boolean
*/
public function child_has_dimensions() {
@ -555,8 +546,7 @@ class WC_Product_Variable extends WC_Product {
* upwards (from child to parent) when the variation is saved.
*
* @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.
*/
public static function sync( $product, $save = true ) {
@ -575,10 +565,12 @@ class WC_Product_Variable extends WC_Product {
$product->save();
}
wc_do_deprecated_action( 'woocommerce_variable_product_sync', array(
$product->get_id(),
$product->get_visible_children()
), '3.0', 'woocommerce_variable_product_sync_data, woocommerce_new_product or woocommerce_update_product' );
wc_do_deprecated_action(
'woocommerce_variable_product_sync', array(
$product->get_id(),
$product->get_visible_children(),
), '3.0', 'woocommerce_variable_product_sync_data, woocommerce_new_product or woocommerce_update_product'
);
}
return $product;
@ -588,8 +580,7 @@ class WC_Product_Variable extends WC_Product {
* Sync parent stock status with the status of all children and save.
*
* @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.
*/
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.
*
* @param array $prices Associativate array of $variation_id => $price pairs
*
* @param array $prices Associativate array of $variation_id => $price pairs.
* @return array
*/
protected function sort_variation_prices( $prices ) {

View File

@ -1,24 +1,17 @@
<?php
/**
* WooCommerce product variation class.
*
* @package WooCommerce/Classes
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Product Variation Class.
* Product Variation
*
* The WooCommerce product variation class handles product variation data.
*
* @class WC_Product_Variation
* @version 3.0.0
* @package WooCommerce/Classes
* @category Class
* @author WooThemes
* @package WooCommerce/Classes
* @version 3.0.0
*/
defined( 'ABSPATH' ) || exit;
/**
* Product variation class.
*/
class WC_Product_Variation extends WC_Product_Simple {
@ -166,11 +159,11 @@ class WC_Product_Variation extends WC_Product_Simple {
if ( ! empty( $item_object['variation'] ) ) {
$data = $item_object['variation'];
} elseif ( ! empty( $item_object['item_meta_array'] ) ) {
$data_keys = array_map( 'wc_variation_attribute_name', wp_list_pluck( $item_object['item_meta_array'], 'key' ) );
$data_values = wp_list_pluck( $item_object['item_meta_array'], 'value' );
$data = array_intersect_key( array_combine( $data_keys, $data_values ), $this->get_variation_attributes() );
$data_keys = array_map( 'wc_variation_attribute_name', wp_list_pluck( $item_object['item_meta_array'], 'key' ) );
$data_values = wp_list_pluck( $item_object['item_meta_array'], 'value' );
$data = array_intersect_key( array_combine( $data_keys, $data_values ), $this->get_variation_attributes() );
} else {
$data = $this->get_variation_attributes();
$data = $this->get_variation_attributes();
}
return add_query_arg( array_map( 'urlencode', array_filter( $data ) ), $url );
@ -182,7 +175,14 @@ class WC_Product_Variation extends WC_Product_Simple {
* @return string
*/
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 );
}
@ -504,7 +504,7 @@ class WC_Product_Variation extends WC_Product_Simple {
* @return array valid tax classes
*/
protected function get_valid_tax_classes() {
$valid_classes = WC_Tax::get_tax_class_slugs();
$valid_classes = WC_Tax::get_tax_class_slugs();
$valid_classes[] = 'parent';
return $valid_classes;

View File

@ -1,18 +1,17 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* WooCommerce Shipping Rate Class.
* WooCommerce Shipping Rate
*
* Simple Class for storing rates.
*
* @class WC_Shipping_Rate
* @package WooCommerce/Classes/Shipping
* @category Class
* @author Automattic
* @package WooCommerce/Classes/Shipping
* @since 2.6.0
*/
defined( 'ABSPATH' ) || exit;
/**
* Shipping rate class.
*/
class WC_Shipping_Rate {
@ -42,12 +41,12 @@ class WC_Shipping_Rate {
/**
* Constructor.
*
* @param string $id
* @param string $label
* @param integer $cost
* @param array $taxes
* @param string $method_id
* @param int $instance_id
* @param string $id Shipping rate ID.
* @param string $label Shipping rate label.
* @param integer $cost Cost.
* @param array $taxes Taxes applied to shipping rate.
* @param string $method_id Shipping method ID.
* @param int $instance_id Shipping instance ID.
*/
public function __construct( $id = '', $label = '', $cost = 0, $taxes = array(), $method_id = '', $instance_id = 0 ) {
$this->set_id( $id );
@ -62,7 +61,7 @@ class WC_Shipping_Rate {
* Magic methods to support direct access to props.
*
* @since 3.2.0
* @param string $key
* @param string $key Key.
* @return bool
*/
public function __isset( $key ) {
@ -73,7 +72,7 @@ class WC_Shipping_Rate {
* Magic methods to support direct access to props.
*
* @since 3.2.0
* @param string $key
* @param string $key Key.
* @return mixed
*/
public function __get( $key ) {
@ -90,8 +89,8 @@ class WC_Shipping_Rate {
* Magic methods to support direct access to props.
*
* @since 3.2.0
* @param string $key
* @param mixed $value
* @param string $key Key.
* @param mixed $value Value.
*/
public function __set( $key, $value ) {
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.
*
* @since 3.2.0
* @param string $id
* @param string $id Shipping rate ID.
*/
public function set_id( $id ) {
$this->data['id'] = (string) $id;
@ -115,7 +114,7 @@ class WC_Shipping_Rate {
* Set shipping method ID the rate belongs to.
*
* @since 3.2.0
* @param string $method_id
* @param string $method_id Shipping method ID.
*/
public function set_method_id( $method_id ) {
$this->data['method_id'] = (string) $method_id;
@ -125,7 +124,7 @@ class WC_Shipping_Rate {
* Set instance ID the rate belongs to.
*
* @since 3.2.0
* @param int $instance_id
* @param int $instance_id Instance ID.
*/
public function set_instance_id( $instance_id ) {
$this->data['instance_id'] = absint( $instance_id );
@ -135,7 +134,7 @@ class WC_Shipping_Rate {
* Set rate label.
*
* @since 3.2.0
* @param string $method_id
* @param string $label Shipping rate label.
*/
public function set_label( $label ) {
$this->data['label'] = (string) $label;
@ -146,7 +145,7 @@ class WC_Shipping_Rate {
*
* @todo 4.0 Prevent negative value being set. #19293
* @since 3.2.0
* @param string $cost
* @param string $cost Shipping rate cost.
*/
public function set_cost( $cost ) {
$this->data['cost'] = $cost;
@ -156,7 +155,7 @@ class WC_Shipping_Rate {
* Set rate taxes.
*
* @since 3.2.0
* @param array $taxes
* @param array $taxes List of taxes applied to shipping rate.
*/
public function set_taxes( $taxes ) {
$this->data['taxes'] = ! empty( $taxes ) && is_array( $taxes ) ? $taxes : array();
@ -227,15 +226,15 @@ class WC_Shipping_Rate {
* @return array
*/
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.
*
* @since 2.6.0
* @param string $key
* @param string $value
* @param string $key Key.
* @param string $value Value.
*/
public function add_meta_data( $key, $value ) {
$this->meta_data[ wc_clean( $key ) ] = wc_clean( $value );

View File

@ -2,7 +2,7 @@
/**
* Represents a single shipping zone
*
* @since 2.6.0
* @since 2.6.0
* @version 3.0.0
* @package WooCommerce/Classes
*/

View File

@ -1,12 +1,11 @@
<?php
/**
* WooCommerce Shipping Class
* WooCommerce Shipping
*
* Handles shipping and loads shipping methods via hooks.
*
* @class WC_Shipping
* @version 2.6.0
* @package WooCommerce/Classes/Shipping
* @version 2.6.0
* @package WooCommerce/Classes/Shipping
*/
if ( ! defined( 'ABSPATH' ) ) {
@ -14,7 +13,7 @@ if ( ! defined( 'ABSPATH' ) ) {
}
/**
* WC_Shipping
* Shipping class.
*/
class WC_Shipping {
@ -60,7 +59,6 @@ class WC_Shipping {
* Ensures only one instance of WC_Shipping is loaded or can be loaded.
*
* @since 2.1
* @static
* @return WC_Shipping Main instance
*/
public static function instance() {

View File

@ -603,7 +603,7 @@ class WC_Tax {
$compound = $key_or_rate->tax_rate_compound;
} else {
$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 );

View File

@ -181,7 +181,7 @@ class WC_CLI_Runner {
'name' => $name,
'type' => 'assoc',
'description' => ! empty( $args['description'] ) ? $args['description'] : '',
'optional' => empty( $args['required'] ) ? true : false,
'optional' => empty( $args['required'] ),
);
}
}

View File

@ -37,7 +37,7 @@ class WC_Gateway_COD extends WC_Payment_Gateway {
$this->description = $this->get_option( 'description' );
$this->instructions = $this->get_option( 'instructions' );
$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_thankyou_' . $this->id, array( $this, 'thankyou_page' ) );

View File

@ -65,7 +65,7 @@ abstract class WC_Legacy_Coupon extends WC_Data {
$value = $this->get_id();
break;
case 'exists' :
$value = ( $this->get_id() > 0 ) ? true : false;
$value = $this->get_id() > 0;
break;
case 'coupon_custom_fields' :
$legacy_custom_fields = array();

View File

@ -201,7 +201,7 @@ abstract class WP_Background_Process extends WP_Async_Request {
WHERE {$column} LIKE %s
", $key ) );
return ( $count > 0 ) ? false : true;
return ! ( $count > 0 );
}
/**

View File

@ -241,7 +241,7 @@ class WC_Shortcode_Checkout {
} 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 ) {
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' ) );

View File

@ -18,7 +18,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* @return bool
*/
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' ) ) {

View File

@ -2456,7 +2456,7 @@ if ( ! function_exists( 'wc_dropdown_variation_attribute_options' ) ) {
$name = $args['name'] ? $args['name'] : 'attribute_' . sanitize_title( $attribute );
$id = $args['id'] ? $args['id'] : sanitize_title( $attribute );
$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.
if ( empty( $options ) && ! empty( $product ) && ! empty( $attribute ) ) {