Wix Custom Product Page Code

If you are having any problem setting up the CODE, let me know in the comments, I will personally set it up for you in your website. 👍😊😊

Best Regards

Marshall

import wixData from 'wix-data';
 
$w.onReady(function () {
    const collectionId = "451aef11-5714-cf0e-6485-bebb0b70b595"; // Replace with your specific collection ID
 
    wixData.query("Stores/Products")
        .hasSome("collections", [collectionId])
        .find()
        .then((results) => {
            if (results.items.length > 0) {
                $w("#repeater1").data = results.items;
            } else {
                console.log("No products found in this collection.");
            }
        })
        .catch((error) => {
            console.error("Error querying products:", error);
        });
 
    // Set up repeater item data binding
    $w("#repeater1").onItemReady(($item, itemData, index) => {
        // Assuming price is the original price and discountedPrice is the discounted price
        const originalPrice = itemData.price;
        const discountedPrice = itemData.discountedPrice || itemData.price; // Fallback to original price if no discount
 
        // Set text values
        $item("#originalPrice").text = originalPrice.toString();
        $item("#originalPriceStrikethrough").text = originalPrice.toString();
        $item("#discountedPrice").text = discountedPrice.toString();
 
        // Price display logic
        if (originalPrice !== discountedPrice) {
            // Show strikethrough and discounted price, hide original price
            $item("#originalPrice").hide();
            $item("#originalPriceStrikethrough").show();
            $item("#discountedPrice").show();
        } else {
            // Show original price, hide strikethrough and discounted price
            $item("#originalPrice").show();
            $item("#originalPriceStrikethrough").hide();
            $item("#discountedPrice").hide();
        }
    });
});

Leave a Reply

Your email address will not be published. Required fields are marked *