We have an affiliate-based fashion website with about 30 merchants. I have this code to map product sizes and it works great if the sizing for all merchants is in the same system. However, some merchants use the UK one, some the US, some Italian, some European. The sizes for Men and Women overlap, and also shoe sizes and clothes sizes get mixed up when we try to map them.
So my question is: does anyone know if we can add another parameter to the code below, to also add one of the following, depending on the occasion: AND merchant name is XYZ. AND merchant name is NOT XYZ. AND product category contains Clothing AND product category does NOT contain Clothing
Below is the current code:
**add_filter( 'dfrpswc_filter_attribute_value', 'mycode_add_size_attribute', 20, 6 );
function mycode_add_size_attribute( $value, $attribute, $post, $product, $set, $action ) {
if ( $attribute != 'pa_size' ) {
return $value;
}
if ( isset( $product['size'] ) ) {
return mycode_get_size( $product['size'], $product['size'] );
}
if ( isset( $product['custom1'] ) ) {
return mycode_get_size( $product['custom1'], $product['custom1'] );
}
if ( isset( $product['name'] ) ) {
return mycode_get_size( $product['name'] );
}
return $value;
}
/**
* A function to normalize size attribute names.
*
* This returns a normalized value of a term based on a supplied
* array of mappings of a key (desired word) mapped to an array of
* keywords (undesired words).
*
* @param string $field The value to normalize.
* @param string $default Optional. What to return if the $field value doesn't have a "normalized" value. Default: ''
*
* @return string Normalized attribute value.
*/
function mycode_get_size( $field, $default = '' ) {
$map = array();
// ++++++++++ Begin Editing Here ++++++++++
$map["XXXS"] = array( "" );
$map["XXS"] = array( "" );
$map["XS"] = array( "" );
// ++++++++++ Stop Editing Here ++++++++++
$terms = array();
foreach ( $map as $key => $keywords ) {
if ( preg_match( '/\b' . preg_quote( $key, '/' ) . '\b/iu', $field ) ) {
$terms[] = $key;
}
foreach ( $keywords as $keyword ) {
if ( preg_match( '/\b' . preg_quote( $keyword, '/' ) . '\b/iu', $field ) ) {
$terms[] = $key;
}
}
}
if ( ! empty( $terms ) ) {
return implode( WC_DELIMITER, array_unique( $terms ) );
}
return $default;
}**
The website is https://fashionfinder.online/ if anyone needs to take a look before replying.
Thank you all so much and kind regards, Dessislava