Best Multi Vendor Marketplace Plugin for WordPress › Forums › WCFM › WCFM – Variable Products with Quotes in the Attribute names
- This topic has 3 replies, 2 voices, and was last updated 7 years, 8 months ago by
WCFM Forum.
- AuthorPosts
- January 19, 2019 at 9:45 pm #44417
ouija
GuestHi,
I just wanted to report a bug with WCFM and the front-end product manager not properly selecting the variation / attribute names when the name has a quote (“) in the name and viewing the list of variations on the front end.
This is likely due to the quote in the attribute name causing the javascript to fail because it isn’t being escaped, and thereby prevents the front end from selecting that variation name. This is also affecting the ‘default selections’ of variations, again, if the variation attribute has a quote in it.
I’ll try and resolve this issue myself and post back with my solution if/when I do.
Example:
<script async src=”//s.imgur.com/min/embed.js” charset=”utf-8″></script>
Thank you.
- January 19, 2019 at 9:47 pm #44418
ouija
GuestSorry, here’s an example of a variable product where one of the attributes has quotes in the names (for different sizes of pizza):
and here’s how it SHOULD load the product by default:
Hope this better illustrates the issue I’m describing.
- January 19, 2019 at 10:43 pm #44419
ouija
GuestI managed to resolve this for my needs by editing the /wp-content/plugins/wc-frontend-manager/core/class-wcfm-ajax.php file and modified the wcfm_generate_variation_attributes() function, by replacing all occurances of esc_attr within this function to use addslashes instead.
Here’s how the function looks now:
global $wpdb, $WCFM;
$wcfm_products_manage_form_data = array();
parse_str($_POST[‘wcfm_products_manage_form’], $wcfm_products_manage_form_data);
//print_r($wcfm_products_manage_form_data);if(isset($wcfm_products_manage_form_data[‘attributes’]) && !empty($wcfm_products_manage_form_data[‘attributes’])) {
$pro_attributes = ‘{‘;
$attr_first = true;
foreach($wcfm_products_manage_form_data[‘attributes’] as $attributes) {
if(isset($attributes[‘is_variation’])) {
if( isset( $attributes[‘is_active’] ) && !empty( $attributes[‘name’] ) && !empty( $attributes[‘value’] ) ) {
if(!$attr_first) $pro_attributes .= ‘,’;
if($attr_first) $attr_first = false;if($attributes[‘is_taxonomy’]) {
$pro_attributes .= ‘”‘ . sanitize_title( $attributes[‘tax_name’] ) . ‘”: { “name” : ” ‘ . $attributes[‘name’] . ‘ “, “data” : {‘;
if( !is_array($attributes[‘value’]) ) {
$att_values = explode( WC_DELIMITER , $attributes[‘value’]);
$is_first = true;
foreach($att_values as $att_value) {
if(!$is_first) $pro_attributes .= ‘,’;
if($is_first) $is_first = false;
$pro_attributes .= ‘”‘ . sanitize_title($att_value) . ‘”: “‘ . addslashes(trim($att_value)) . ‘”‘;
}
} else {
$att_values = $attributes[‘value’];
$is_first = true;
foreach($att_values as $att_value) {
if(!$is_first) $pro_attributes .= ‘,’;
if($is_first) $is_first = false;
$att_term = get_term( absint($att_value) );
if( $att_term ) {
$pro_attributes .= ‘”‘ . $att_term->slug . ‘”: “‘ . addslashes($att_term->name) . ‘”‘;
} else {
$pro_attributes .= ‘”‘ . sanitize_title($att_value) . ‘”: “‘ . addslashes(trim($att_value)) . ‘”‘;
}
}
}
$pro_attributes .= ‘} }’;
} else {
$pro_attributes .= ‘”‘ . sanitize_title( $attributes[‘name’] ) . ‘”: { “name” : ” ‘ . $attributes[‘name’] . ‘ “, “data” : {‘;
$att_values = explode( WC_DELIMITER, $attributes[‘value’]);
$is_first = true;
foreach($att_values as $att_value) {
if(!$is_first) $pro_attributes .= ‘,’;
if($is_first) $is_first = false;
$pro_attributes .= ‘”‘ . addslashes(trim($att_value)) . ‘”: “‘ . addslashes(trim($att_value)) . ‘”‘;
}
$pro_attributes .= ‘} }’;
}
}
}
}
$pro_attributes .= ‘}’;
echo $pro_attributes;
}die();
} - January 20, 2019 at 6:58 am #44448
WCFM Forum
MemberHi,
Thanks for the all details.
We understand this issue, we will take care of this in next update.
Well, you have tried well, but this will not resolve this fully. On edit, it will cause problem.
Thank You
- AuthorPosts
- The topic ‘WCFM – Variable Products with Quotes in the Attribute names’ is closed to new replies.