Personalized checkout and custom promotions with Shopify Scripts
Hi Everyone, I am trying to get a product metafield to display as a pseudo element on my collection card information ".collection .card__information:before." So, Ideally the site would be able to know if a product metafield was added to a specific product and if so, it would display it like so:
I was able to get the pseudo element to display the collection title via this code:
<script>
document.addEventListener("DOMContentLoaded", function() {
var cardInformation = document.querySelector('.collection .card__information');
var title = document.title.replace(/roro revival/i, '').replace(/page \d+/i, '').trim();
var cleanTitle = title.replace(/-/g, ''); // Replacing hyphens with spaces
// Remove all non-alphabetical characters from cleanTitle
var alphabeticTitle = cleanTitle.replace(/[^a-zA-Z\s]/g, '');
// Debugging
console.log("Original Title:", title);
console.log("Clean Title:", cleanTitle);
console.log("Alphabetic Title:", alphabeticTitle);
if (cardInformation) {
var newStyle = document.createElement('style');
newStyle.innerHTML = `
.collection .card__information::before {
content: "${alphabeticTitle}";
display: block; /* Ensure content is displayed */
}
`;
document.head.appendChild(newStyle);
}
});
</script>
but, no luck in adjusting this code to populate the specific metafields vs the collection title.
Hello, Will you please tell me what you like to achieve? Are you able to print your meta-filed value in the markup? Why the meta filed value need to set in sudo code.
Wating for your response to help you to solve this issues.
Thank you
Syncora: Backup & Restore [Free] - Automated real-time store backup with one-click easy restore.
Slider Revolution - Create sliders, theme sections, banners, videos, pages, advanced animation, and social feeds.
Essential Grid Gallery - Create photo galleries, video galleries, portfolio galleries, product gallery, collection gallery, and more.
EasyDisplay: Product Showcase - Easily display collections, related products, discounts, recently viewed items, and best sellers.
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025