Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I use HTML in the Badge text field in the admin panel? #18

Closed
muhyal opened this issue Sep 7, 2022 · 8 comments
Closed

Can I use HTML in the Badge text field in the admin panel? #18

muhyal opened this issue Sep 7, 2022 · 8 comments

Comments

@muhyal
Copy link

muhyal commented Sep 7, 2022

Hi,

Can I use HTML in the Badge text field in the admin panel?

If I use HTML it shows the entered value as plain text:

2022-09-07_20-07-32

For example, for a badge that looks like this:

2022-09-07_20-06-16

I want to set it like this:

2022-09-07_20-06-22

I did some research and found a document like this, but I couldn't get a successful result:
https://carbonfields.net/docs/fields-html/

Thank you for your support.

@CharlieEtienne
Copy link
Owner

Hi @muhyal,

In fact this is not a limitation of carbon fields or my plugin, but a limitation from WooCommerce. The hook used to display the badge is escaping html.

So the workarounds would be to override the products pages in your theme, or to replace WC hook.

@muhyal
Copy link
Author

muhyal commented Sep 8, 2022

Thanks, @CharlieEtienne,

Do you have any guidance on how to do it?

@CharlieEtienne
Copy link
Owner

Wait, I'm not sure of what I told in my previous message... Let me check.

@CharlieEtienne
Copy link
Owner

CharlieEtienne commented Sep 8, 2022

I was completely wrong, sorry. I was thinking to another plugin. The HTML is actually escaped in my plugin, in wp-content/plugins/sold-out-badge-for-woocommerce/classes/Settings.php on line 125.

Could you try this code (in your theme's functions.php for example) and let me know if it works?

global $post, $product;
add_filter('wcsob_soldout', function($content) {
    return htmlspecialchars_decode($content, ENT_QUOTES);
}, $post, $product);

@muhyal
Copy link
Author

muhyal commented Sep 8, 2022

I tested it but this time the theme is broken.

It looks like this:

2022-09-08_11-07-19

@CharlieEtienne
Copy link
Owner

Yes, I forgot to specify the number of arguments. This is the right function to use:

global $post, $product;
add_filter('wcsob_soldout', function ($content, $post, $product) {
	return htmlspecialchars_decode($content, ENT_QUOTES);
}, 10, 3);

@muhyal
Copy link
Author

muhyal commented Sep 8, 2022

You've probably heard this a lot in your life @CharlieEtienne . "You are a great person" :) Thanks for your support.

Looks just like we imagined:

2022-09-08_15-56-31

@CharlieEtienne
Copy link
Owner

You're welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants