-
Notifications
You must be signed in to change notification settings - Fork 215
Add static class name for product-details #6914
Conversation
…ranslatable string
|
The release ZIP for this PR is accessible via: |
|
Size Change: -107 B (0%) Total Size: 871 kB
ℹ️ View Unchanged
|
nielslange
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! ⛴
tarhi-saad
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @alexflorisca! We have two failing unit tests. I believe you need to update the test snapshots for it to pass. And make sure to update your branch with trunk!
|
@tarhi-saad This is causing problems for me with Mix and Match as now there's no way to distinguish between the meta items at all. There still needs to be a unique identifying class, and ideally have it stay consistent regardless of the site language. See also my comment here |
|
Hello, @helgatheviking! Thank you for reporting this issue! @alexflorisca's, if you can confirm that the class names aren't translatable, let's revert the changes of this PR! Otherwise, we can open a new issue to add support for |
|
@helgatheviking I tested this with the product addons plugin and these didn't translate for me. Can you tell us what plugin you're using and how you're seeing the classname strings translated so we can try to replicate? |
|
Hi @alexflorisca thanks for the update. I am working with my plugin WooCommerce Mix and Match Products... so add a Mix and Match product to the cart and then look at the checkout block. I believe the issue also existed with Bundled Products too. What is the specific commit I should test against? |
|
You can test against this commit: 6c68e0c |
|
Hi @alexflorisca I think that is the commit where this change was introduced no? The unique class names aren't present in that commit, so I think I need to go back to the one before it... |
|
Should be the one before it according to github: https://github.com/woocommerce/woocommerce-blocks/commits/trunk?after=22c1f242d856bb6d02d81e0eb20a5d198e11d64b+34&branch=trunk&qualified_name=refs%2Fheads%2Ftrunk You can try 6286a6f |
This reverts commit c410644.
|
Thanks, Alex. Maybe it's caching but I can't get the class name to render for anything. 😓 in typical fashion, I can't get the build tools to build. |
|
@helgatheviking We've just reverted this in #7191 so if you get the latest trunk, you should have the classname back. Apologies, I think I deleted that class too soon. |
|
Thanks @alexflorisca I still see the class name is translatable because the key that is displayed must be translatable to support multilingual sites. Here's a test case: When I switch my site to the French language, the class changes from If I change my above snippet to design key and name: Then class name is not translated, but neither is the user-facing text: I am still looking for a way to display the translated text to users but have a static class name. These two things shouldn't be linked in my opinion. |
|
Yeah I get you. So the problem we have is that with the scenario you described above, any item inside the |
|
I agree a number would be pretty useless. I would never be able to predict what position the item was in the cart. Can |
|
Unfortunately we can't decouple key from name as we need to support both to keep compatible with WC Core (more details in this issue). We could potentially introduce a |
|
Hey @alexflorisca, Thank you for investigating this further! The solution you propose is not 100% clear to me. Would you mind sharing an example of how the code would look like with this change? Moreover, can you please share a screenshot of the DOM structure in the frontend when your changes are active? Which classes will be available at the point where the deprecated class used to exist? |
|
My bad @jimjasson, that wasn't a great explanation. What I mean is that at the moment, we can add extra fields to a product by using the The screenshot below shows the class names of the two variant labels, colour and logo. Notice the two At the moment these are generated on the client from the const name = item?.key || item.name || '';
const className = name ? `wc-block-components-product-details__${ kebabCase(name) }` : '';The function kia_test_cart_item_data( $data, $cart_item ) {
$data[] = array(
'key' => esc_html__( 'Color', 'your-textdomain' ),
'value' => esc_html__( 'Blue', 'your-textdomain' ),
);
return $data;
}
add_filter( 'woocommerce_get_item_data', 'kia_test_cart_item_data', 10, 2 );What @helgatheviking is proposing is adding an extra function kia_test_cart_item_data( $data, $cart_item ) {
$data[] = array(
'key' => esc_html__( 'Color', 'your-textdomain' ),
'value' => esc_html__( 'Blue', 'your-textdomain' ),
'class' => esc_html__( 'wc-block-components-product-details__color', 'your-textdomain' ),
);
return $data;
}
add_filter( 'woocommerce_get_item_data', 'kia_test_cart_item_data', 10, 2 );So in this example, the final DOM will look the same, but the class name is explicitly given rather than derived from the name or key props. Does that make sense? |
|
I like it! A class name we can specify would give parity to the php cart/order row class filter too. |
|
Gotcha @alexflorisca -- thank you for the detailed explanation! Yes, that would be helpful for us too! |
|
Great, I've created an issue to do this. Bare in mind that once this solution is merged and released, your tests will probably start failing again @jimjasson, until you make the required change on your side. |
|
Thank you @alexflorisca !
Yes, this makes sense. I will keep a close eye on the progress of this issue -- I would really appreciate it though, if you could ping me when this is implemented + close to release. Thanks! 🚀 |
|
@jimjasson pinging you as this is now complete and merged to trunk in #7328 |
|
Thanks @alexflorisca for the ping. I just tested and I see the classes are back |
|
@PanosSynetos you should now be able to add a class that doesn't change via translation. |
|
Awesome :) Thanks for the ping Kathy! |
* Add a static class name for the product details item instead of the translatable string * Update Jest snapshot Co-authored-by: Saad Tarhi <[email protected]>



This fixes a bug where we were deriving a class name from a translatable string, which could be different depending on the language of the user and therefore pretty useless for styling for an international store.
Fixes #6512
Testing
User Facing Testing
wc-block-components-product-details__itemon the<li>element. This should be a child of<ul className="wc-block-components-product-details">WooCommerce Visibility
Performance Impact
Changelog