Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../src/StoreApi/Utilitie...
File: LocalPickupUtils.php
<?php
[0] Fix | Delete
namespace Automattic\WooCommerce\StoreApi\Utilities;
[1] Fix | Delete
[2] Fix | Delete
/**
[3] Fix | Delete
* Util class for local pickup related functionality, this contains methods that need to be accessed from places besides
[4] Fix | Delete
* the ShippingController, i.e. the OrderController.
[5] Fix | Delete
*/
[6] Fix | Delete
class LocalPickupUtils {
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Gets the local pickup location settings.
[10] Fix | Delete
*
[11] Fix | Delete
* @param string $context The context for the settings. Defaults to 'view'.
[12] Fix | Delete
*/
[13] Fix | Delete
public static function get_local_pickup_settings( $context = 'view' ) {
[14] Fix | Delete
$pickup_location_settings = get_option(
[15] Fix | Delete
'woocommerce_pickup_location_settings',
[16] Fix | Delete
[
[17] Fix | Delete
'enabled' => 'no',
[18] Fix | Delete
'title' => __( 'Pickup', 'woocommerce' ),
[19] Fix | Delete
'cost' => '',
[20] Fix | Delete
'tax_status' => 'taxable',
[21] Fix | Delete
]
[22] Fix | Delete
);
[23] Fix | Delete
[24] Fix | Delete
if ( empty( $pickup_location_settings['title'] ) ) {
[25] Fix | Delete
$pickup_location_settings['title'] = __( 'Pickup', 'woocommerce' );
[26] Fix | Delete
}
[27] Fix | Delete
[28] Fix | Delete
if ( empty( $pickup_location_settings['enabled'] ) ) {
[29] Fix | Delete
$pickup_location_settings['enabled'] = 'no';
[30] Fix | Delete
}
[31] Fix | Delete
[32] Fix | Delete
if ( ! isset( $pickup_location_settings['cost'] ) ) {
[33] Fix | Delete
$pickup_location_settings['cost'] = '';
[34] Fix | Delete
}
[35] Fix | Delete
[36] Fix | Delete
// Return settings as is if we're editing them.
[37] Fix | Delete
if ( 'edit' === $context ) {
[38] Fix | Delete
return $pickup_location_settings;
[39] Fix | Delete
}
[40] Fix | Delete
[41] Fix | Delete
// All consumers of this turn it into a bool eventually. Doing it here removes the need for that.
[42] Fix | Delete
$pickup_location_settings['enabled'] = wc_string_to_bool( $pickup_location_settings['enabled'] );
[43] Fix | Delete
$pickup_location_settings['title'] = wc_clean( $pickup_location_settings['title'] );
[44] Fix | Delete
[45] Fix | Delete
return $pickup_location_settings;
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
/**
[49] Fix | Delete
* Checks if WC Blocks local pickup is enabled.
[50] Fix | Delete
*
[51] Fix | Delete
* @return bool True if local pickup is enabled.
[52] Fix | Delete
*/
[53] Fix | Delete
public static function is_local_pickup_enabled() {
[54] Fix | Delete
// Get option directly to avoid early translation function call.
[55] Fix | Delete
// See https://github.com/woocommerce/woocommerce/pull/47113.
[56] Fix | Delete
$pickup_location_settings = get_option(
[57] Fix | Delete
'woocommerce_pickup_location_settings',
[58] Fix | Delete
[
[59] Fix | Delete
'enabled' => 'no',
[60] Fix | Delete
]
[61] Fix | Delete
);
[62] Fix | Delete
[63] Fix | Delete
if ( empty( $pickup_location_settings['enabled'] ) ) {
[64] Fix | Delete
$pickup_location_settings['enabled'] = 'no';
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
return wc_string_to_bool( $pickup_location_settings['enabled'] );
[68] Fix | Delete
}
[69] Fix | Delete
/**
[70] Fix | Delete
* Gets a list of payment method ids that support the 'local-pickup' feature.
[71] Fix | Delete
*
[72] Fix | Delete
* @return string[] List of payment method ids that support the 'local-pickup' feature.
[73] Fix | Delete
*/
[74] Fix | Delete
public static function get_local_pickup_method_ids() {
[75] Fix | Delete
$all_methods_supporting_local_pickup = array_reduce(
[76] Fix | Delete
WC()->shipping()->get_shipping_methods(),
[77] Fix | Delete
function ( $methods, $method ) {
[78] Fix | Delete
if ( $method->supports( 'local-pickup' ) ) {
[79] Fix | Delete
$methods[] = $method->id;
[80] Fix | Delete
}
[81] Fix | Delete
return $methods;
[82] Fix | Delete
},
[83] Fix | Delete
array( 'local_pickup' )
[84] Fix | Delete
);
[85] Fix | Delete
[86] Fix | Delete
// We use array_values because this will be used in JS, so we don't need the (numerical) keys.
[87] Fix | Delete
return array_values(
[88] Fix | Delete
// This array_unique is necessary because WC()->shipping()->get_shipping_methods() can return duplicates.
[89] Fix | Delete
array_unique(
[90] Fix | Delete
$all_methods_supporting_local_pickup
[91] Fix | Delete
)
[92] Fix | Delete
);
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
/**
[96] Fix | Delete
* Checks if a method is a local pickup method.
[97] Fix | Delete
*
[98] Fix | Delete
* @param string $method_id The method id to check.
[99] Fix | Delete
* @return bool True if the method is a local pickup method.
[100] Fix | Delete
*/
[101] Fix | Delete
public static function is_local_pickup_method( $method_id ) {
[102] Fix | Delete
return in_array( $method_id, self::get_local_pickup_method_ids(), true );
[103] Fix | Delete
}
[104] Fix | Delete
}
[105] Fix | Delete
[106] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function