From b397b37b3e095dd6b100ee5dff56b71488cbac21 Mon Sep 17 00:00:00 2001 From: JeroenSormani Date: Sun, 19 Nov 2017 14:17:37 +0100 Subject: [PATCH 001/347] Remove 'woocommerce_lock_down_admin' option and use filter only instead --- includes/admin/class-wc-admin.php | 2 +- includes/wc-user-functions.php | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/includes/admin/class-wc-admin.php b/includes/admin/class-wc-admin.php index 007c974f7b5..540fcca3871 100644 --- a/includes/admin/class-wc-admin.php +++ b/includes/admin/class-wc-admin.php @@ -159,7 +159,7 @@ class WC_Admin { public function prevent_admin_access() { $prevent_access = false; - if ( 'yes' === get_option( 'woocommerce_lock_down_admin', 'yes' ) && ! is_ajax() && basename( $_SERVER["SCRIPT_FILENAME"] ) !== 'admin-post.php' ) { + if ( apply_filters( 'woocommerce_disable_admin_bar', true ) && ! is_ajax() && basename( $_SERVER["SCRIPT_FILENAME"] ) !== 'admin-post.php' ) { $has_cap = false; $access_caps = array( 'edit_posts', 'manage_woocommerce', 'view_admin_dashboard' ); diff --git a/includes/wc-user-functions.php b/includes/wc-user-functions.php index 94594673d43..6522fb758c2 100644 --- a/includes/wc-user-functions.php +++ b/includes/wc-user-functions.php @@ -17,14 +17,12 @@ if ( ! defined( 'ABSPATH' ) ) { /** * Prevent any user who cannot 'edit_posts' (subscribers, customers etc) from seeing the admin bar. * - * Note: get_option( 'woocommerce_lock_down_admin', true ) is a deprecated option here for backwards compatibility. Defaults to true. - * * @access public * @param bool $show_admin_bar * @return bool */ function wc_disable_admin_bar( $show_admin_bar ) { - if ( apply_filters( 'woocommerce_disable_admin_bar', get_option( 'woocommerce_lock_down_admin', 'yes' ) === 'yes' ) && ! ( current_user_can( 'edit_posts' ) || current_user_can( 'manage_woocommerce' ) ) ) { + if ( apply_filters( 'woocommerce_disable_admin_bar', true ) && ! ( current_user_can( 'edit_posts' ) || current_user_can( 'manage_woocommerce' ) ) ) { $show_admin_bar = false; } From d56edfd53aadd40d0c56b501ac49042d8d84be05 Mon Sep 17 00:00:00 2001 From: Khan M Rashedun-Naby Date: Tue, 17 Jul 2018 22:57:32 +0600 Subject: [PATCH 002/347] #20696 Cart widget Customizer selective refresh fix --- includes/widgets/class-wc-widget-cart.php | 39 +++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/includes/widgets/class-wc-widget-cart.php b/includes/widgets/class-wc-widget-cart.php index e699476d135..d9543e61332 100644 --- a/includes/widgets/class-wc-widget-cart.php +++ b/includes/widgets/class-wc-widget-cart.php @@ -36,6 +36,10 @@ class WC_Widget_Cart extends WC_Widget { ), ); + if ( is_customize_preview() ) { + $this->enqueue_ajax_script(); + } + parent::__construct(); } @@ -69,4 +73,39 @@ class WC_Widget_Cart extends WC_Widget { $this->widget_end( $args ); } + + /** + * This method provides the JS script which will execute on addition of a new widget. + * + * @return void + */ + private function enqueue_ajax_script() { + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; + + wp_register_script( 'wc-cart-fragments', WC()->plugin_url() . '/assets/js/frontend/cart-fragments' . $suffix . '.js', array( 'jquery', 'js-cookie' ), WC_VERSION, true ); + + wp_localize_script( 'wc-cart-fragments', 'wc_cart_fragments_params', + array( + 'ajax_url' => WC()->ajax_url(), + '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(), '/' ) . get_template() ) ), + 'fragment_name' => apply_filters( 'woocommerce_cart_fragment_name', 'wc_fragments_' . md5( get_current_blog_id() . '_' . get_site_url( get_current_blog_id(), '/' ) . get_template() ) ), + ) + ); + + wp_enqueue_script( 'wc-cart-fragments' ); + + ?> + + Date: Tue, 14 Aug 2018 13:03:02 +0600 Subject: [PATCH 003/347] Added @todo comment to PHPDoc --- includes/widgets/class-wc-widget-cart.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/includes/widgets/class-wc-widget-cart.php b/includes/widgets/class-wc-widget-cart.php index d9543e61332..41bab3984d9 100644 --- a/includes/widgets/class-wc-widget-cart.php +++ b/includes/widgets/class-wc-widget-cart.php @@ -77,6 +77,9 @@ class WC_Widget_Cart extends WC_Widget { /** * This method provides the JS script which will execute on addition of a new widget. * + * @todo 1. In this function there is a redundency of code, which needs to be fixed. + * 2. Also sort out a better way to fix the raw JS code block. May be using `wc_enqueue_js()`. + * * @return void */ private function enqueue_ajax_script() { From e41a6199bbf63ba19467998ea14755d31055e596 Mon Sep 17 00:00:00 2001 From: Khan M Rashedun-Naby Date: Tue, 14 Aug 2018 13:11:23 +0600 Subject: [PATCH 004/347] Updated @todo comment --- includes/widgets/class-wc-widget-cart.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/widgets/class-wc-widget-cart.php b/includes/widgets/class-wc-widget-cart.php index 41bab3984d9..d81a8e863cf 100644 --- a/includes/widgets/class-wc-widget-cart.php +++ b/includes/widgets/class-wc-widget-cart.php @@ -77,8 +77,8 @@ class WC_Widget_Cart extends WC_Widget { /** * This method provides the JS script which will execute on addition of a new widget. * - * @todo 1. In this function there is a redundency of code, which needs to be fixed. - * 2. Also sort out a better way to fix the raw JS code block. May be using `wc_enqueue_js()`. + * @todo 1. In this function there is redundency of code, which needs to be fixed. + * 2. Also sort out a better way to fix the later raw JS code block. May be do it a more WordPress way. * * @return void */ From 6f03a5fe72ebde13c43862675a6984885b4c9468 Mon Sep 17 00:00:00 2001 From: Florian Ludwig Date: Tue, 14 Aug 2018 12:19:23 +0200 Subject: [PATCH 005/347] Adds timeout to cart fragment ajax call --- assets/js/frontend/cart-fragments.js | 1 + 1 file changed, 1 insertion(+) diff --git a/assets/js/frontend/cart-fragments.js b/assets/js/frontend/cart-fragments.js index 5432e83e42f..eb0dd258b76 100644 --- a/assets/js/frontend/cart-fragments.js +++ b/assets/js/frontend/cart-fragments.js @@ -38,6 +38,7 @@ jQuery( function( $ ) { var $fragment_refresh = { url: wc_cart_fragments_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'get_refreshed_fragments' ), type: 'POST', + timeout: 5000, success: function( data ) { if ( data && data.fragments ) { From 1d76102395cbc5cef745a47ed1a21c494d4e38ad Mon Sep 17 00:00:00 2001 From: Florian Ludwig Date: Tue, 14 Aug 2018 12:25:29 +0200 Subject: [PATCH 006/347] Adds error event trigger for erroneous fragment retrieval (timeout or server error) --- assets/js/frontend/cart-fragments.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/assets/js/frontend/cart-fragments.js b/assets/js/frontend/cart-fragments.js index eb0dd258b76..865f353049a 100644 --- a/assets/js/frontend/cart-fragments.js +++ b/assets/js/frontend/cart-fragments.js @@ -57,6 +57,9 @@ jQuery( function( $ ) { $( document.body ).trigger( 'wc_fragments_refreshed' ); } + }, + error: function() { + $( document.body ).trigger( 'wc_fragments_ajax_error' ); } }; From 0f6f6814ad8ffc3db352dac2c031b32a4150010b Mon Sep 17 00:00:00 2001 From: Florian Ludwig Date: Tue, 14 Aug 2018 18:08:55 +0200 Subject: [PATCH 007/347] Moves cart hash calculation to WC_Cart class --- includes/class-wc-ajax.php | 2 +- includes/class-wc-cart-session.php | 2 +- includes/class-wc-cart.php | 11 +++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/includes/class-wc-ajax.php b/includes/class-wc-ajax.php index d3eb96aa941..2a78d9585f8 100644 --- a/includes/class-wc-ajax.php +++ b/includes/class-wc-ajax.php @@ -178,7 +178,7 @@ class WC_AJAX { 'div.widget_shopping_cart_content' => '
' . $mini_cart . '
', ) ), - 'cart_hash' => apply_filters( 'woocommerce_add_to_cart_hash', WC()->cart->get_cart_for_session() ? md5( json_encode( WC()->cart->get_cart_for_session() ) ) : '', WC()->cart->get_cart_for_session() ), + 'cart_hash' => WC()->cart->get_cart_hash(), ); wp_send_json( $data ); diff --git a/includes/class-wc-cart-session.php b/includes/class-wc-cart-session.php index ea8023a72b2..f1cc4abd382 100644 --- a/includes/class-wc-cart-session.php +++ b/includes/class-wc-cart-session.php @@ -228,7 +228,7 @@ final class WC_Cart_Session { private function set_cart_cookies( $set = true ) { if ( $set ) { wc_setcookie( 'woocommerce_items_in_cart', 1 ); - wc_setcookie( 'woocommerce_cart_hash', md5( wp_json_encode( $this->get_cart_for_session() ) ) ); + wc_setcookie( 'woocommerce_cart_hash', WC()->cart->get_cart_hash() ); } elseif ( isset( $_COOKIE['woocommerce_items_in_cart'] ) ) { // WPCS: input var ok. wc_setcookie( 'woocommerce_items_in_cart', 0, time() - HOUR_IN_SECONDS ); wc_setcookie( 'woocommerce_cart_hash', '', time() - HOUR_IN_SECONDS ); diff --git a/includes/class-wc-cart.php b/includes/class-wc-cart.php index ae5f00e5aaf..b31bed3b7ed 100644 --- a/includes/class-wc-cart.php +++ b/includes/class-wc-cart.php @@ -1938,4 +1938,15 @@ class WC_Cart extends WC_Legacy_Cart { $this->fees_api->remove_all_fees(); do_action( 'woocommerce_cart_reset', $this, false ); } + + /** + * Returns the hash based on cart contents. + * + * @return string hash for cart content + */ + public function get_cart_hash() { + $hash = $this->session->get_cart_for_session() ? md5( json_encode( $this->session->get_cart_for_session() ) ) : ''; + + return apply_filters( 'woocommerce_add_to_cart_hash', $hash, $this->get_cart_for_session() ); + } } From 34300a1c52aedae31dd4b5e87d46cc419449fb9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kavalek?= Date: Thu, 16 Aug 2018 09:44:01 +0200 Subject: [PATCH 008/347] Added missing HTML filter for quantity MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New filter into wc_add_to_cart_message which allows modify printed product quantity into message – for example in case of floats units – 1.2 kg (add_filter('woocommerce_stock_amount', 'floatval');) --- includes/wc-cart-functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/wc-cart-functions.php b/includes/wc-cart-functions.php index fb07c970c14..9dcb117b9f4 100644 --- a/includes/wc-cart-functions.php +++ b/includes/wc-cart-functions.php @@ -107,7 +107,7 @@ function wc_add_to_cart_message( $products, $show_qty = false, $return = false ) foreach ( $products as $product_id => $qty ) { /* translators: %s: product name */ - $titles[] = ( $qty > 1 ? absint( $qty ) . ' × ' : '' ) . apply_filters( 'woocommerce_add_to_cart_item_name_in_quotes', sprintf( _x( '“%s”', 'Item name in quotes', 'woocommerce' ), strip_tags( get_the_title( $product_id ) ) ), $product_id ); + $titles[] = ( $qty > 1 ? ( has_filter( 'woocommerce_add_to_cart_message_qty_html' ) ? apply_filters( 'woocommerce_add_to_cart_message_qty_html', $product_id, $qty ) : absint( $qty ) ) . ' × ' : '' ) . apply_filters( 'woocommerce_add_to_cart_item_name_in_quotes', sprintf( _x( '“%s”', 'Item name in quotes', 'woocommerce' ), strip_tags( get_the_title( $product_id ) ) ), $product_id ); $count += $qty; } From 3e4791fbb4e9f64bd4e446e7efa0d4a214fbee0c Mon Sep 17 00:00:00 2001 From: Florian Ludwig Date: Wed, 5 Sep 2018 10:16:01 +0200 Subject: [PATCH 009/347] Fixes wrong usage of deprecated get_cart_for_session --- includes/class-wc-cart.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/includes/class-wc-cart.php b/includes/class-wc-cart.php index b31bed3b7ed..1c4bdc139ad 100644 --- a/includes/class-wc-cart.php +++ b/includes/class-wc-cart.php @@ -1945,8 +1945,9 @@ class WC_Cart extends WC_Legacy_Cart { * @return string hash for cart content */ public function get_cart_hash() { - $hash = $this->session->get_cart_for_session() ? md5( json_encode( $this->session->get_cart_for_session() ) ) : ''; + $cart = $this->session->get_cart_for_session(); + $hash = $cart ? md5( json_encode( $cart ) ) : ''; - return apply_filters( 'woocommerce_add_to_cart_hash', $hash, $this->get_cart_for_session() ); + return apply_filters( 'woocommerce_add_to_cart_hash', $hash, $cart ); } } From f93f36ee65b972330c4357f79c8da5fd871f359a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kavalek?= Date: Wed, 5 Sep 2018 20:39:12 +0200 Subject: [PATCH 010/347] Added missing HTML filter for quantity https://github.com/woocommerce/woocommerce/pull/21069#pullrequestreview-147005349 --- includes/wc-cart-functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/wc-cart-functions.php b/includes/wc-cart-functions.php index 9dcb117b9f4..dc7d3f2a397 100644 --- a/includes/wc-cart-functions.php +++ b/includes/wc-cart-functions.php @@ -107,7 +107,7 @@ function wc_add_to_cart_message( $products, $show_qty = false, $return = false ) foreach ( $products as $product_id => $qty ) { /* translators: %s: product name */ - $titles[] = ( $qty > 1 ? ( has_filter( 'woocommerce_add_to_cart_message_qty_html' ) ? apply_filters( 'woocommerce_add_to_cart_message_qty_html', $product_id, $qty ) : absint( $qty ) ) . ' × ' : '' ) . apply_filters( 'woocommerce_add_to_cart_item_name_in_quotes', sprintf( _x( '“%s”', 'Item name in quotes', 'woocommerce' ), strip_tags( get_the_title( $product_id ) ) ), $product_id ); + $titles[] = apply_filters( 'woocommerce_add_to_cart_qty_html', ( $qty > 1 ? absint( $qty ) . ' × ' : '' ), $product_id ) . apply_filters( 'woocommerce_add_to_cart_item_name_in_quotes', sprintf( _x( '“%s”', 'Item name in quotes', 'woocommerce' ), strip_tags( get_the_title( $product_id ) ) ), $product_id ); $count += $qty; } From 37da7b6680e14449688bd818c490de9c04524fed Mon Sep 17 00:00:00 2001 From: Reuven Karasik Date: Thu, 13 Sep 2018 12:17:51 +0300 Subject: [PATCH 011/347] Added action 'woocommerce_variation_header' action --- .../admin/meta-boxes/views/html-variation-admin.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/includes/admin/meta-boxes/views/html-variation-admin.php b/includes/admin/meta-boxes/views/html-variation-admin.php index 06e3823884f..f8e73884d7e 100644 --- a/includes/admin/meta-boxes/views/html-variation-admin.php +++ b/includes/admin/meta-boxes/views/html-variation-admin.php @@ -48,6 +48,17 @@ if ( ! defined( 'ABSPATH' ) ) { ?> + +