Modification of the plugin for woocommerce attribute grouping

elandeler

Member
May 8, 2020
46
27
18
First the foreword. I have spent a lot of time to find a solution that will allow me to break down the product characteristics into sections (categories). In the end I found only one obscure plugin that is too complex and requires a redux framework. In general, none of the fresh solutions suited me...

Recently I found a plugin in the wilderness, which was abandoned by a developer back in 2017, it almost works fine (almost), except for one function.

Here is the plugin itself:
JC WooCommerce Advanced Attributes 2.0.7
.

The essence is that the name of the attribute's group is specified through the attribute's name, through the point separation (Category name.Attribute name), and the attribute itself is displayed through the custom field, which is filled in the attribute's settings.

The problem is that the attribute's custom name is not displayed on the product page, but instead the original name of the attribute is displayed (Category name.Attribute's name). In other word, the function wc_attribute_label is called instead of jcaa_attribute_label in place of attribute name.

I have no idea where to dig, I don't know much about php. I suspect that the problem lies in the file /libs/jcaa-functions.php on line 202, who can help with that? I can prepare a test environment for the plugin.

I think I'm not the only one looking for an adequate solution for such a task, so you can create a fork for the plugin and post it here.
 
Last edited:
  • Like
Reactions: amamarar

frizzel

Well-known member
Trusted Uploader
Jun 13, 2019
485
253
63
Wherever my imagination takes me
So, you're basically saying that what is in the instructions does not work?

In the instructions it says this:
(Under Group Simple Product Attributes)
2. Under the advanced attributes display settings labelled Custom Label - enter the Name which you want it to appear under the Group e.g. (Bank, Elevation), this name will be displayed on the product information tab.
 

elandeler

Member
May 8, 2020
46
27
18
So, you're basically saying that what is in the instructions does not work?

In the instructions it says this:
(Under Group Simple Product Attributes)
2. Under the advanced attributes display settings labelled Custom Label - enter the Name which you want it to appear under the Group e.g. (Bank, Elevation), this name will be displayed on the product information tab.

Yes, I did according to the instructions, put the separator as a dot and checked that this attribute is group, also changed the name in the custom label (but this logically is not required).

Result on the screenshot:
screenshot.png
 

frizzel

Well-known member
Trusted Uploader
Jun 13, 2019
485
253
63
Wherever my imagination takes me
The problem is indeed in the function jcaa_attribute_label in jcaa-functions.php, as you suspected. The variable $name on line 210 is not properly defined. As a result $id is empty (or rather : NULL) and thus the rest of the code doesn't work either.

The solution is to sanitize $name. To do so put the following line directly after line 209 which reads 'global $wpdb;'

PHP:
$name = wc_sanitize_taxonomy_name( str_replace( 'pa_', '', $name ) );

On my local install, it works after I inserted above line.

A little more info: 'pa_' is the prefix WooCommerce uses for Product Attributes in the database. Your attribute name doesn't have that prefix, so to get the right details from the database, that prefix has first to be removed from the search, otherwise the search will always return NULL.
 
Last edited:
  • Like
Reactions: elandeler

About us

  • Our community has been around for many years and pride ourselves on offering unbiased, critical discussion among people of all different backgrounds. We are working every day to make sure our community is one of the best.

Quick Navigation

User Menu