Skip to content

Instantly share code, notes, and snippets.

@be-mohand
be-mohand / Minimum listing price
Last active April 29, 2019 14:26
Checking in javascript (with jQuery) that the entered price is equal or greater than the minimum listing price.
// Always check that jQuery is available before executing the script
$(document).ready(function() {
// Execute only if the listing form exists in the page
if($('#listingForm').length > 0) {
var checkMinimumListingPrice = function() {
// Check if the price is equal or greater than 1
if($('#ListingPrice').val() < 1) {
alert('Price should be equal or greater than 1');
$(document).ready(function() {
// Calcul price dynamically
if($('#listingForm').length > 0) {
var foreignRates = $.get('https://api.exchangeratesapi.io/latest?base=USD');
var foreignExchangeFunction = function() {
@be-mohand
be-mohand / split_category_select.js
Created June 27, 2019 21:26
Create a new select dynamically based on the optgroups
$(function() {
if($('select#category-id').length > 0) {
$('select#category-id').each(function() {
var select = $(this),
groupName = 'Choose a category',
optgroups = select.find('optgroup'),
options = select.find('optgroup option'),
groupSelect = $('<select>'),
emptyGroupOption = makeOption(groupName);
// Hide the div
document.getElementById('bank_account_bank_account_type_div').style.display = "none";
// Select the "GB" value and trigger a change to update the fields to display
var bank_account_bank_account_type_input = document.getElementById('bank-account-type');
bank_account_bank_account_type_input.value = 'GB';
bank_account_bank_account_type_input.dispatchEvent(new Event('change'));
@be-mohand
be-mohand / dyanmic_tos_label.js
Created November 25, 2019 06:49
Update the TOS label depending on the selected user group in the signup form
$(document).on('change', 'form#signupForm #userTypeID', function(e) {
var elem = $(this);
if(elem.val() === "group_id_1") {
tos_label = 'TOS group 1';
} else {
tos_label = 'TOS group 2';
}
$('#tosLabelMessage').empty().text(tos_label);
});
$(document).ready(function() {
// Set default location to Paris
if($('.homepage-body').length > 0 && $('#gmap-input-area').length > 0) {
$('#gmap-input-area').val('Paris');
if($('#lat_search').length > 0) {
$('#lat_search').val('48.8485765');
}
if($('#lng_search').length > 0) {
$('#lng_search').val('2.3421943');
}
@be-mohand
be-mohand / random_listings_on_homepage
Created April 26, 2020 12:48
Display random listings on your Kreezalid homepage
1. Configure your homepage to load enough listings on your homepage. Let's say 100.
2. Update the homepage-listings snippets in the theme editor:
2.1. Add {% assign shuffled_listings = listings-section.listings | shuffle %} at the beginning of the snippet
2.2. Update the for loop to iterate on shuffled_listings instead of listings-section.listings. You can also limit the number of listing to display with the limit parameter:
{% for listing in shuffled_listings limit:8 %}
$(document).ready(function() {
// Apply only on product page
// If the user is not logged in, we hide the price and the purchase btn, and we display a login btn
if($('.listing-show').length > 0 && Kr.AuthenticatedUser === null) {
$('.listing_details_list .price').remove();
$('.add-to-cart-panel').empty();
// Create a login Button
var loginBtn = document.createElement('a');
loginBtn.href = '/login';
@be-mohand
be-mohand / hide_price_range
Last active September 2, 2020 12:07
Hide price range filter on search page
$(document).ready(function() {
// Hide the prive range filter if exists
if($('.price_filter_side').length > 0) {
$('.price_filter_side').remove();
}
});
@be-mohand
be-mohand / update_shipping_countries.js
Created November 16, 2020 13:37
Update Shipping countries in list
$(document).ready(function() {
// Keep only France as authorized Shipping countries
if($('#shipping-country').length > 0) {
$('#shipping-country')
.empty()
.append('<option selected="selected" value="FR">France</option>');
}
});