Skip to content

Instantly share code, notes, and snippets.

@be-mohand
be-mohand / conditionnal_custom_display.liquid
Created July 3, 2023 13:43
Display a customizable text depending on the category selected and the facet.
{% if category.title == "Vases et cache-pots" and request.query_params.marque.208768 == '1' %}
<p>Je teste une fonctionnalité</p>
{% endif %}
@be-mohand
be-mohand / add_redirect_url_to_listing_form.js
Created March 23, 2023 10:24
Redirect the vendor to a custom script so you can ask for more information about its profile or the listing.
// Add a redirect_url to the form to create an extra step
let redirectUrlInput = document.createElement("input");
redirectUrlInput.setAttribute('name', 'redirect_url');
redirectUrlInput.setAttribute('value', 'https://your-script-url.com');
redirectUrlInput.setAttribute('type', 'hidden');
document.getElementById('listingForm').appendChild(redirectUrlInput);
@be-mohand
be-mohand / banner.html
Last active November 23, 2022 10:54
Add a banner on top of all your pages.
<style>
#announcement-bar {
position: relative;
background: #000000;
width: 100%;
color: #FFFFFF;
text-align: center;
padding: 5px;
}
#announcement-bar p { margin-bottom: 0; }
@be-mohand
be-mohand / addons_as_shipping.js
Created February 22, 2022 15:44
Use this JavaScript snippet to make sure at least one shipping method is selected if shipping is enabled when we use the AddOns as shipping selector
/**
* Making sure at least one shipping method is selected if shipping is enabled
*/
if(typeof Kr !== 'undefined' && typeof Kr.Listing !== 'undefined' && Kr.Listing !== null && document.querySelectorAll('input[name="addons"]').length > 0)
{
let checkIfShippingHasBeenSelected = function() {
if(document.querySelectorAll('input[name="addons"]:checked').length === 0) {
[].forEach.call(document.querySelectorAll('input[name="addons"]:first-child'), function (el) {el.checked = true});
}
}
@be-mohand
be-mohand / password_strength.js
Created April 20, 2021 15:30
Check password strength in javascript
/**
* Thank You Douglas Karr for this javascript function
* @link https://martech.zone/javascript-password-strength/
*/
if($('#signupForm').length > 0 && $('#password').length > 0) {
$('#password-input-div').append('<span id="passwordStrength"></span>');
$('#password').on('keyup', function(){
var strength = document.getElementById("passwordStrength");
var strongRegex = new RegExp("^(?=.{14,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
@be-mohand
be-mohand / insert_iframe_listing_page.js
Created April 13, 2021 14:34
Display an iFrame on a listing page
if(typeof Kr !== 'undefined' && typeof Kr.Listing !== 'undefined' && Kr.Listing !== null){
if(Kr.Listing.id === YOUR_LISTING_ID) {
var iframe = document.createElement('iframe');
iframe.style.width="100%";
iframe.style.height="300px";
iframe.src = "YOUR_IFRAME_URL_SRC";
let container = document.getElementsByClassName('container listing_container_main_wrapper');
container[0].appendChild(iframe);
}
}
@be-mohand
be-mohand / check_valid_fr_postcode.js
Last active April 29, 2021 11:50
Shipping price are not the same when you ship to West Indies or inside French borders. You may need postcode is correct.
// https://vicopo.selfbuild.fr/
jQuery(function($){var _host=(location.protocol==="http:"?"http:":"https:")+"//vicopo.selfbuild.fr";var _cache={};var _sort=function(a,b){return a.city-b.city};var _filter=function(){return true};$.extend({vicopoSort:function($sort){_sort=$sort},vicopoFilter:function($filter){_filter=$filter},vicopoPrepare:function($cities){$cities=$cities.filter(_filter);return $cities.sort(_sort)},vicopo:function(_input,_done){_input=_input.trim();return this.getVicopo(/^\d+$/.test(_input)?"code":"city",_input,_done)},codePostal:function(_input,_done){return this.getVicopo("code",_input,_done)},ville:function(_input,_done){return this.getVicopo("city",_input,_done)},getVicopo:function(_name,_input,_done){if(_input.length>1){_input=_input.trim();_cache[_name]=_cache[_name]||{};if(_cache[_name][_input]){_done(_input,$.vicopoPrepare(_cache[_name][_input]||[]),_name)}else{var _data={};_data[_name]=_input;return $.getJSON(_host,_data,function(_answer){_cache[_name][_input]=_answer.cities;_done(_an
@be-mohand
be-mohand / hide_ratings_stars.css
Created November 25, 2020 17:27
Hide rating stars
// listing page
.listing_container .rate {
display:none;
}
// Shop view
.profile-view .rate {
display:none;
}
@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>');
}
});
@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();
}
});