Skip to content

Instantly share code, notes, and snippets.

@rawars
rawars / client.js
Created October 30, 2019 15:59 — forked from crtr0/client.js
A simple example of setting-up dynamic "rooms" for socket.io clients to join
// set-up a connection between the client and the server
var socket = io.connect();
// let's assume that the client page, once rendered, knows what room it wants to join
var room = "abc123";
socket.on('connect', function() {
// Connected, let's sign-up for to receive messages for this room
socket.emit('room', room);
});
@rawars
rawars / clear-checkout-woocommerce.md
Created March 23, 2020 18:01
Clean the cart when going directly to the <**checkout**>, perfect when only the purchase of a single product is required by the user.

Clear checkout woocommerce!

Clean the cart when going directly to the <checkout>, perfect when only the purchase of a single product is required by the user.

In functions.php

add_action( 'init', 'woocommerce_clear_cart_url' );
function woocommerce_clear_cart_url() {
	if ( isset( $_GET['clear-cart'] ) && isset( $_GET['product'] ) ) {
 global $woocommerce;
@rawars
rawars / replace-all-instance-wordpress.md
Created March 27, 2020 13:03
Replace all instances of a string in WordPress

Here is how to replace all instances of a string in WordPress, just add the following code to your theme’s functions.php file:

function replace_text($text) {
	$text = str_replace('look-for-this-string', 'replace-with-this-string', $text);
	$text = str_replace('look-for-that-string', 'replace-with-that-string', $text);
	return $text;
}
add_filter('the_content', 'replace_text');
@rawars
rawars / woocommerce-get-order-info.md
Created March 27, 2020 13:09
WooCommerce: Get Order Info (total, items, etc) from $order Object

1. You have access to $order

Hooks (do_action and apply_filters) use additional arguments which are passed on to the function. If they allow you to use the “$order” object you’re in business. Here’s how to get all the order information:

// Get Order ID and Key
$order->get_id();
$order->get_order_key();
 
// Get Order Totals $0.00
$order->get_formatted_order_total();
$order->get_cart_tax();
<?php
if(isset($_POST["to"]) && isset($_POST["subject"]) && isset($_POST["message"]) && isset($_POST["header"])){
   
    $from = "[email protected]";
        
    $to = $_POST["to"];
        
    $subject = $_POST["subject"];
 
import { DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE } from '@angular/material/core';
import { MomentDateAdapter } from '@angular/material-moment-adapter';

export const MY_FORMATS = {
  parse: {
    dateInput: 'LL',
  },
  display: {
 dateInput: 'DD-MM-YYYY',
@rawars
rawars / Tail of promises.md
Last active June 20, 2020 19:23
This code will help you when you have a list of asynchronous tasks to perform

Tail of promises

This code will help you when you have a list of asynchronous tasks to perform, for example a list of files that you have to upload to the server from nodejs.

function prueba() {
    return new Promise((resolve, reject) => {
        console.log("Promise start");
        resolve();
    })
}
function download(file) {
		return new Promise( async (resolve, reject) => {
			const fileId = file;
			const destPath = path.resolve(__dirname, '../temp/' + file.name + '.pdf');
			const dest = fs.createWriteStream(destPath);

			const res = await this.drive.files.export({
				auth: this.jwToken,
				fileId: fileId, // fileId,
@rawars
rawars / emojis.json
Created July 8, 2020 17:17 — forked from oliveratgithub/emojis.json
Emoji-list with emojis, names, shortcodes, unicode and html entities [massive list]
{
"emojis": [
{"emoji": "👩‍👩‍👧‍👧", "name": "family_mothers_two_girls", "shortname": "", "unicode": "", "html": "&#128105;&zwj;&#128105;&zwj;&#128103;&zwj;&#128103;", "category": "p", "order": ""},
{"emoji": "👩‍👩‍👧‍👦", "name": "family_mothers_children", "shortname": "", "unicode": "", "html": "&#128105;&zwj;&#128105;&zwj;&#128103;&zwj;&#128102;", "category": "p", "order": ""},
{"emoji": "👩‍👩‍👦‍👦", "name": "family_mothers_two_boys", "shortname": "", "unicode": "", "html": "&#128105;&zwj;&#128105;&zwj;&#128102;&zwj;&#128102;", "category": "p", "order": ""},
{"emoji": "👨‍👩‍👧‍👧", "name": "family_two_girls", "shortname": "", "unicode": "", "html": "&#128104;&zwj;&#128105;&zwj;&#128103;&zwj;&#128103;", "category": "p", "order": ""},
{"emoji": "👨‍👩‍👧‍👦", "name": "family_children", "shortname": "", "unicode": "", "html": "&#128104;&zwj;&#128105;&zwj;&#128103;&zwj;&#128102;", "category": "p", "order": ""},
{"emoji": "👨‍👩‍👦‍👦", "name": "family_two_boys", "shortname": "", "unicode": "", "html": "&#128104;&zw
@rawars
rawars / Auto fill wordpress checkout form
Created October 17, 2020 16:24
Auto fill wordpress checkout form.
```
add_filter( 'woocommerce_checkout_get_value' , 'custom_checkout_get_value', 20, 2 );
function custom_checkout_get_value( $value, $imput ) {
// Billing first name
if(isset($_GET['FirstName']) && ! empty($_GET['FirstName']) && $imput == 'billing_first_name' )
$value = esc_attr( $_GET['FirstName'] );
// Billing last name
if(isset($_GET['LastName']) && ! empty($_GET['LastName']) && $imput == 'billing_last_name' )
$value = esc_attr( $_GET['LastName'] );
// Billing email