Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../src/Internal/FraudPro...
File: SessionDataCollector.php
return $billing_data;
[500] Fix | Delete
}
[501] Fix | Delete
[502] Fix | Delete
/**
[503] Fix | Delete
* Get shipping address from customer data.
[504] Fix | Delete
*
[505] Fix | Delete
* Collects shipping address fields from WC_Customer object with graceful degradation.
[506] Fix | Delete
* Returns array with 6 address fields, sanitized with sanitize_text_field().
[507] Fix | Delete
*
[508] Fix | Delete
* @since 10.5.0
[509] Fix | Delete
*
[510] Fix | Delete
* @return array Shipping address array with 6 keys.
[511] Fix | Delete
*/
[512] Fix | Delete
private function get_shipping_address(): array {
[513] Fix | Delete
$shipping_data = array(
[514] Fix | Delete
'first_name' => null,
[515] Fix | Delete
'last_name' => null,
[516] Fix | Delete
'address' => null,
[517] Fix | Delete
'address_1' => null,
[518] Fix | Delete
'address_2' => null,
[519] Fix | Delete
'city' => null,
[520] Fix | Delete
'state' => null,
[521] Fix | Delete
'postcode' => null,
[522] Fix | Delete
'country' => null,
[523] Fix | Delete
);
[524] Fix | Delete
try {
[525] Fix | Delete
if ( WC()->customer instanceof \WC_Customer ) {
[526] Fix | Delete
$shipping_data = array_merge(
[527] Fix | Delete
$shipping_data,
[528] Fix | Delete
array(
[529] Fix | Delete
'first_name' => \sanitize_text_field( WC()->customer->get_shipping_first_name() ),
[530] Fix | Delete
'last_name' => \sanitize_text_field( WC()->customer->get_shipping_last_name() ),
[531] Fix | Delete
'address_1' => \sanitize_text_field( WC()->customer->get_shipping_address_1() ),
[532] Fix | Delete
'address_2' => \sanitize_text_field( WC()->customer->get_shipping_address_2() ),
[533] Fix | Delete
'city' => \sanitize_text_field( WC()->customer->get_shipping_city() ),
[534] Fix | Delete
'state' => \sanitize_text_field( WC()->customer->get_shipping_state() ),
[535] Fix | Delete
'postcode' => \sanitize_text_field( WC()->customer->get_shipping_postcode() ),
[536] Fix | Delete
'country' => \sanitize_text_field( WC()->customer->get_shipping_country() ),
[537] Fix | Delete
)
[538] Fix | Delete
);
[539] Fix | Delete
} elseif ( WC()->session instanceof \WC_Session ) {
[540] Fix | Delete
// Fallback to session customer data if WC_Customer not available.
[541] Fix | Delete
$customer_data = WC()->session->get( 'customer' );
[542] Fix | Delete
if ( is_array( $customer_data ) ) {
[543] Fix | Delete
$shipping_data = array_merge(
[544] Fix | Delete
$shipping_data,
[545] Fix | Delete
array(
[546] Fix | Delete
'first_name' => \sanitize_text_field( $customer_data['shipping_first_name'] ?? null ),
[547] Fix | Delete
'last_name' => \sanitize_text_field( $customer_data['shipping_last_name'] ?? null ),
[548] Fix | Delete
'address_1' => \sanitize_text_field( $customer_data['shipping_address_1'] ?? null ),
[549] Fix | Delete
'address_2' => \sanitize_text_field( $customer_data['shipping_address_2'] ?? null ),
[550] Fix | Delete
'city' => \sanitize_text_field( $customer_data['shipping_city'] ?? null ),
[551] Fix | Delete
'state' => \sanitize_text_field( $customer_data['shipping_state'] ?? null ),
[552] Fix | Delete
'postcode' => \sanitize_text_field( $customer_data['shipping_postcode'] ?? null ),
[553] Fix | Delete
'country' => \sanitize_text_field( $customer_data['shipping_country'] ?? null ),
[554] Fix | Delete
)
[555] Fix | Delete
);
[556] Fix | Delete
}
[557] Fix | Delete
}
[558] Fix | Delete
} catch ( \Exception $e ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
[559] Fix | Delete
// Graceful degradation - returns as much data as possible.
[560] Fix | Delete
}
[561] Fix | Delete
[562] Fix | Delete
return $shipping_data;
[563] Fix | Delete
}
[564] Fix | Delete
[565] Fix | Delete
/**
[566] Fix | Delete
* Get client IP address using WooCommerce geolocation utility.
[567] Fix | Delete
*
[568] Fix | Delete
* @since 10.5.0
[569] Fix | Delete
*
[570] Fix | Delete
* @return string|null IP address or null if not available.
[571] Fix | Delete
*/
[572] Fix | Delete
private function get_ip_address(): ?string {
[573] Fix | Delete
if ( class_exists( 'WC_Geolocation' ) ) {
[574] Fix | Delete
$ip = \WC_Geolocation::get_ip_address();
[575] Fix | Delete
return $ip ? $ip : null;
[576] Fix | Delete
}
[577] Fix | Delete
return null;
[578] Fix | Delete
}
[579] Fix | Delete
[580] Fix | Delete
/**
[581] Fix | Delete
* Get customer email with fallback chain.
[582] Fix | Delete
*
[583] Fix | Delete
* Tries logged-in user email first, then WC_Customer billing email,
[584] Fix | Delete
* then session customer data as fallback.
[585] Fix | Delete
*
[586] Fix | Delete
* @since 10.5.0
[587] Fix | Delete
*
[588] Fix | Delete
* @return string|null Email address or null if not available.
[589] Fix | Delete
*/
[590] Fix | Delete
private function get_email(): ?string {
[591] Fix | Delete
// Try logged-in user first.
[592] Fix | Delete
if ( \is_user_logged_in() ) {
[593] Fix | Delete
$user = \wp_get_current_user();
[594] Fix | Delete
if ( $user && $user->user_email ) {
[595] Fix | Delete
return \sanitize_email( $user->user_email );
[596] Fix | Delete
}
[597] Fix | Delete
}
[598] Fix | Delete
[599] Fix | Delete
// Try WC_Customer object.
[600] Fix | Delete
if ( WC()->customer instanceof \WC_Customer ) {
[601] Fix | Delete
$email = WC()->customer->get_billing_email();
[602] Fix | Delete
if ( $email ) {
[603] Fix | Delete
return \sanitize_email( $email );
[604] Fix | Delete
}
[605] Fix | Delete
}
[606] Fix | Delete
[607] Fix | Delete
// Fallback to session customer data if WC_Customer not available.
[608] Fix | Delete
if ( WC()->session instanceof \WC_Session ) {
[609] Fix | Delete
$customer_data = WC()->session->get( 'customer' );
[610] Fix | Delete
if ( is_array( $customer_data ) && ! empty( $customer_data['email'] ) ) {
[611] Fix | Delete
return \sanitize_email( $customer_data['email'] );
[612] Fix | Delete
}
[613] Fix | Delete
}
[614] Fix | Delete
[615] Fix | Delete
return null;
[616] Fix | Delete
}
[617] Fix | Delete
[618] Fix | Delete
/**
[619] Fix | Delete
* Get user agent string from HTTP headers.
[620] Fix | Delete
*
[621] Fix | Delete
* @since 10.5.0
[622] Fix | Delete
*
[623] Fix | Delete
* @return string|null User agent or null if not available.
[624] Fix | Delete
*/
[625] Fix | Delete
private function get_user_agent(): ?string {
[626] Fix | Delete
if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
[627] Fix | Delete
return sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) );
[628] Fix | Delete
}
[629] Fix | Delete
return null;
[630] Fix | Delete
}
[631] Fix | Delete
[632] Fix | Delete
/**
[633] Fix | Delete
* Get product category names as comma-separated list.
[634] Fix | Delete
*
[635] Fix | Delete
* Uses WooCommerce helper with caching for better performance.
[636] Fix | Delete
* Returns all categories for the product, not just the primary one.
[637] Fix | Delete
*
[638] Fix | Delete
* @since 10.5.0
[639] Fix | Delete
*
[640] Fix | Delete
* @param \WC_Product $product The product object.
[641] Fix | Delete
* @return string|null Comma-separated category names or null if none.
[642] Fix | Delete
*/
[643] Fix | Delete
private function get_product_category_names( \WC_Product $product ): ?string {
[644] Fix | Delete
$terms = WC()->call_function( 'wc_get_product_terms', $product->get_id(), 'product_cat' );
[645] Fix | Delete
if ( empty( $terms ) || ! is_array( $terms ) ) {
[646] Fix | Delete
return null;
[647] Fix | Delete
}
[648] Fix | Delete
$category_names = array_map(
[649] Fix | Delete
function ( $term ) {
[650] Fix | Delete
return $term->name;
[651] Fix | Delete
},
[652] Fix | Delete
$terms
[653] Fix | Delete
);
[654] Fix | Delete
return implode( ', ', $category_names );
[655] Fix | Delete
}
[656] Fix | Delete
[657] Fix | Delete
/**
[658] Fix | Delete
* Trim collected data array to ensure it stays within 1 MB size limit.
[659] Fix | Delete
*
[660] Fix | Delete
* Removes oldest entries from the array until the serialized size is under the limit.
[661] Fix | Delete
* Always keeps at least one entry (the most recent).
[662] Fix | Delete
*
[663] Fix | Delete
* @since 10.5.0
[664] Fix | Delete
*
[665] Fix | Delete
* @param array $data Array of collected event data.
[666] Fix | Delete
* @param int $base_size Size in bytes of additional data that will be combined with this array.
[667] Fix | Delete
* @return array Trimmed array that fits within the size limit.
[668] Fix | Delete
*/
[669] Fix | Delete
private function trim_to_max_size( array $data, int $base_size = 0 ): array {
[670] Fix | Delete
$max_size_bytes = 1 * 1024 * 1024 - $base_size; // 1 MB minus base data size.
[671] Fix | Delete
$data_count = count( $data );
[672] Fix | Delete
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize -- Used for size calculation only.
[673] Fix | Delete
$data_size = strlen( serialize( $data ) );
[674] Fix | Delete
[675] Fix | Delete
while ( $data_count > 1 && $data_size > $max_size_bytes ) {
[676] Fix | Delete
array_shift( $data );
[677] Fix | Delete
$data_count = count( $data );
[678] Fix | Delete
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize -- Used for size calculation only.
[679] Fix | Delete
$data_size = strlen( serialize( $data ) );
[680] Fix | Delete
}
[681] Fix | Delete
[682] Fix | Delete
return $data;
[683] Fix | Delete
}
[684] Fix | Delete
}
[685] Fix | Delete
[686] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function