Skip to content

Instantly share code, notes, and snippets.

@Farmatique
Farmatique / gist:c3f8e60cdd68943af197fe9233e9c6cd
Created August 26, 2020 11:03
Woocommerce Wordpress loop through all countries (country code)
$all_countries = WC()->countries->get_countries();
foreach($all_countries as $country_code => $country){
var_dump($country_code);
};
@Farmatique
Farmatique / gist:4ff2ca371a3ba7c81b892d1b847cb660
Created August 25, 2020 20:00
Add fields to woocommerce checkout page
/**
* Add fields to the checkout page based on products in cart.
*
* @how-to https://remicorson.com/?p=7871
* @author Remi Corson
* @testedwith WooCommerce 3.4.0
*/
add_action( 'woocommerce_checkout_fields', 'woo_add_conditional_checkout_fields' );
@Farmatique
Farmatique / gist:0dac4fbc12117c863c69d9d9e8cbffff
Created August 21, 2020 12:15
Get each item of menu in Wordpress
$menu_items = wp_get_nav_menu_items( 'social-menu' );
foreach( $menu_items as $item ) {
print_r($item);
}
@Farmatique
Farmatique / gist:ef9ea8dedb1af4c6264a367d9bbba764
Created July 28, 2020 11:39
Full-width section inside limited container
https://css-tricks.com/full-width-containers-limited-width-parents/
.full-width {
margin-left: calc(-100vw / 2 + 500px / 2); // 500 is container width
margin-right: calc(-100vw / 2 + 500px / 2);
}
@Farmatique
Farmatique / gist:daef40d50e90de05e09f4cf0f2d7473e
Created July 24, 2020 10:39
Catch time of playing HTML5 video
//https://stackoverflow.com/questions/53921097/html5-video-pause-for-a-few-seconds-then-continue-playback
<video id="video" playsinline muted loop controls autoplay width='300'>
<source src="https://html5demos.com/assets/dizzy.mp4" type="video/mp4"/>
</video>
var video = document.getElementById('video');
video.addEventListener("timeupdate", tick);
function tick(e) {
var t = this.currentTime;
if (t >= 3) {
@Farmatique
Farmatique / gist:1c02a108c0abd5ed3632ccfc03eba3aa
Created July 2, 2020 10:59
Bootstrap Go to Tab by url hash
//https://stackoverflow.com/questions/7862233/twitter-bootstrap-tabs-go-to-specific-tab-on-page-reload-or-hyperlink
// Javascript to enable link to tab
var url = document.location.toString();
if (url.match('#')) {
jQuery('.nav-tabs a[href="#' + url.split('#')[1] + '"]').tab('show');
}
// Change hash for page-reload
jQuery('.nav-tabs a').on('shown.bs.tab', function (e) {
window.location.hash = e.target.hash;
$skill = ["Advanced", "Essentials", "Intermediate"];
$custom_order = [3, 1, 2];
array_multisort($custom_order, $skill);
// after that: $skill becomes ["Essentials", "Intermediate", "Advanced"]
//from here: https://stackoverflow.com/a/8888498/6775194
function formatAMPM(date) {
var hours = date.getHours();
var minutes = date.getMinutes();
var ampm = hours >= 12 ? 'pm' : 'am';
hours = hours % 12;
hours = hours ? hours : 12; // the hour '0' should be '12'
minutes = minutes < 10 ? '0'+minutes : minutes;
var strTime = hours + ':' + minutes + ' ' + ampm;
return strTime;
@Farmatique
Farmatique / gist:b4a0766d56b392e5e670b98b0ddb765d
Last active June 30, 2020 20:13
Send data from form iframe using postMessage
// somewhere inside iframe on succesfull form submit at https://websitewhereiframelives.com(Pardot)
window.parent.postMessage({eventId: 'customEvent', data: {val1: '500'}}, "*");
// inside script on webpage
window.addEventListener('message', function(message) {
if(message.origin === 'https://websitewhereiframelives.com'){
if(message.data.eventId === 'customEvent'){
console.log(message.data.data.val1);
}
}
@Farmatique
Farmatique / gist:93183d0ce548c0d45f42d37746beac51
Created May 12, 2020 15:45
Add dynamic full year pure js
//you can put that inside any html-element
<script>document.write(new Date().getFullYear())</script>