Skip to content

Instantly share code, notes, and snippets.

View diogenesjup's full-sized avatar
🏠
Working from home

Diogenes Oliveira Junior diogenesjup

🏠
Working from home
View GitHub Profile
@paaljoachim
paaljoachim / functions.php
Last active December 16, 2024 16:27
Tutorial: WooCommerce Checkout: Add multiple custom fields to billing area. This code adds priority placement of field. Shows the custom fields in the backend Order Details screen and in e-mails to the admin and customer. I have also adjusted the checkbox field to give a text result instead of a value of 1. Checkbox is also pre-selected.
/* --------- Adds custom fields using filters. ------
The below custom fields shows various types one can use.
It is then displayed in the backend Order Details page and in admin and customer e-mails.
Checkboxes by default result only show the number 1 when clicked. I have added code so that when the a checkbox is clicked it will
show text such as On and Yes. Checkbox is also pre-selected.
Tutorial: https://easywebdesigntutorials.com/woocommerce-modifying-the-checkout-page/
*/
// Initial inspiration: https://businessbloomer.com/woocommerce-add-shipping-phone-checkout/
// My Custom Fields
@cyberwani
cyberwani / wordpress-upload-base64.php
Created September 13, 2019 10:19
Upload a base64 string as image to the WordPress media library
<?php
/**
* Save the image on the server.
*/
function save_image( $base64_img, $title ) {
// Upload dir.
$upload_dir = wp_upload_dir();
$upload_path = str_replace( '/', DIRECTORY_SEPARATOR, $upload_dir['path'] ) . DIRECTORY_SEPARATOR;
const map = new Map([[1, 2], [2, 4], [4, 8]]);
Array.from(map)
// [1, 2], [2, 4], [4, 8]
Array.from(map.values());
// [2, 4, 8]
Array.from(map.keys());
// [1, 2, 4]
function Range(start, stop, step) {
return Array.from({ length: (stop - start) / step + 1}, (_, i) => start + (i * step));
}
console.log(Range(0,5,1)) // [0, 1, 2, 3, 4, 5]
console.log(Range(0,9,3)) // [0, 3, 6, 9]
console.log(Range('A'.charCodeAt(0), 'Z'.charCodeAt(0), 1).map(x => String.fromCharCode(x)));
// ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']