Plugin Updates

This commit is contained in:
Tony Volpe
2024-04-02 20:23:21 +00:00
parent 96800520e8
commit 94170ec2c4
1514 changed files with 133309 additions and 105985 deletions

View File

@@ -9,6 +9,7 @@
*/
use Automattic\Jetpack\Constants;
use Automattic\WooCommerce\StoreApi\Utilities\LocalPickupUtils;
defined( 'ABSPATH' ) || exit;
@@ -107,6 +108,7 @@ function wc_add_to_cart_message( $products, $show_qty = false, $return = false )
$products = array_fill_keys( array_keys( $products ), 1 );
}
$product_id = null;
foreach ( $products as $product_id => $qty ) {
/* translators: %s: product name */
$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 );
@@ -393,6 +395,9 @@ function wc_get_chosen_shipping_method_ids() {
$method_ids = array();
$chosen_methods = WC()->session->get( 'chosen_shipping_methods', array() );
foreach ( $chosen_methods as $chosen_method ) {
if ( ! is_string( $chosen_method ) ) {
continue;
}
$chosen_method = explode( ':', $chosen_method );
$method_ids[] = current( $chosen_method );
}
@@ -405,7 +410,7 @@ function wc_get_chosen_shipping_method_ids() {
* @since 3.2.0
* @param int $key Key of package.
* @param array $package Package data array.
* @return string|bool
* @return string|bool Either the chosen method ID or false if nothing is chosen yet.
*/
function wc_get_chosen_shipping_method_for_package( $key, $package ) {
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
@@ -421,6 +426,10 @@ function wc_get_chosen_shipping_method_for_package( $key, $package ) {
$method_count = 0;
}
if ( ! isset( $package['rates'] ) || ! is_array( $package['rates'] ) ) {
$package['rates'] = array();
}
// If not set, not available, or available methods have changed, set to the DEFAULT option.
if ( ! $chosen_method || $changed || ! isset( $package['rates'][ $chosen_method ] ) || count( $package['rates'] ) !== $method_count ) {
$chosen_method = wc_get_default_shipping_method_for_package( $key, $package, $chosen_method );
@@ -441,25 +450,55 @@ function wc_get_chosen_shipping_method_for_package( $key, $package ) {
* @since 3.2.0
* @param int $key Key of package.
* @param array $package Package data array.
* @param string $chosen_method Chosen method id.
* @param string $chosen_method Chosen shipping method. e.g. flat_rate:1.
* @return string
*/
function wc_get_default_shipping_method_for_package( $key, $package, $chosen_method ) {
$rate_keys = array_keys( $package['rates'] );
$default = current( $rate_keys );
$coupons = WC()->cart->get_coupons();
foreach ( $coupons as $coupon ) {
if ( $coupon->get_free_shipping() ) {
foreach ( $rate_keys as $rate_key ) {
if ( 0 === stripos( $rate_key, 'free_shipping' ) ) {
$default = $rate_key;
break;
$chosen_method_id = current( explode( ':', $chosen_method ) );
$rate_keys = array_keys( $package['rates'] );
$chosen_method_exists = in_array( $chosen_method, $rate_keys, true );
/**
* If the customer has selected local pickup, keep it selected if it's still in the package. We don't want to auto
* toggle between shipping and pickup even if available shipping methods are changed.
*
* This is important for block based checkout where there is an explicit toggle between shipping and pickup.
*/
$local_pickup_method_ids = LocalPickupUtils::get_local_pickup_method_ids();
$is_local_pickup_chosen = in_array( $chosen_method_id, $local_pickup_method_ids, true );
// Default to the first method in the package. This can be sorted in the backend by the merchant.
$default = current( $rate_keys );
// Default to local pickup if its chosen already.
if ( $chosen_method_exists && $is_local_pickup_chosen ) {
$default = $chosen_method;
} else {
// Check coupons to see if free shipping is available. If it is, we'll use that method as the default.
$coupons = WC()->cart->get_coupons();
foreach ( $coupons as $coupon ) {
if ( $coupon->get_free_shipping() ) {
foreach ( $rate_keys as $rate_key ) {
if ( 0 === stripos( $rate_key, 'free_shipping' ) ) {
$default = $rate_key;
break;
}
}
break;
}
break;
}
}
return apply_filters( 'woocommerce_shipping_chosen_method', $default, $package['rates'], $chosen_method );
/**
* Filters the default shipping method for a package.
*
* @since 3.2.0
* @param string $default Default shipping method.
* @param array $rates Shipping rates.
* @param string $chosen_method Chosen method id.
*/
return (string) apply_filters( 'woocommerce_shipping_chosen_method', $default, $package['rates'], $chosen_method );
}
/**