Skip to content

Instantly share code, notes, and snippets.

@danielcharrua
danielcharrua / woo-custom-field.php
Last active June 3, 2019 11:42
Añade el campo NIF a WooCommerce, para facturación en España
/**
* Añade el campo NIF a la página de checkout de WooCommerce
*/
add_action( 'woocommerce_before_checkout_billing_form', 'agrega_mi_campo_personalizado' );
function agrega_mi_campo_personalizado( $checkout ) {
woocommerce_form_field( 'nif', array(
'type' => 'text',
@danielcharrua
danielcharrua / WiFiWebClient_LaravelAuth.ino
Last active June 5, 2019 11:29
Arduino MKR1000 source code to make an authenticated request to our Laravel API
#include <SPI.h>
#include <WiFi101.h>
char ssid[] = "myNetwork"; // your network SSID (name)
char pass[] = "myPassword"; // your network password
int keyIndex = 0; // your network key Index number (needed only for WEP)
int status = WL_IDLE_STATUS;
const char server[] = "example.com"; // name address for Google (using DNS)
@danielcharrua
danielcharrua / WooCommerce_nif
Last active September 11, 2020 06:23 — forked from Miq3l/functions.php
Adding VAT to WooCommerce
<?php
/**
* Plugin Name: WooCommerce NIF
* Description: Adds NIF fields to WooCommerce
* Version: 1.0
* Author: Daniel Pereyra Costas
* Author URI: https://charrua.es
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
@danielcharrua
danielcharrua / laravelworker
Last active July 4, 2024 18:56 — forked from ibrunotome/supervisord.service
Install and configure supervisord on centos 7.
[program:app1-laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=<your-php-path> <your-artisan-path> queue:work --tries=3
autostart=true
autorestart=true
numprocs=2
redirect_stderr=true
stdout_logfile=<your-logfile-path>
[program:app2-laravel-worker]
@danielcharrua
danielcharrua / mysqldumpbk.sh
Last active January 12, 2021 17:59
BackupPC MySQL on Plesk server
#!/bin/bash
TXTDEST="/home/<username>/mysqlbackup/dblist.txt"
BKPDEST="/home/<username>/mysqlbackup"
PLESK="/usr/sbin/plesk"
DATEYMD=`date +"%Y-%m-%d"`
# Create Lockfile
LOCKFILE=/tmp/myBkup.lock
if [ -f $LOCKFILE ]; then
echo "Lockfile $LOCKFILE exists, exiting!"
@danielcharrua
danielcharrua / remove_emoji.php
Created April 2, 2020 11:23
Remove emoji from PHP string.
/**
* This function removes emoji from string
* Used to filter Twilio SMS/MMS for emoji characters and send messages using GSM instead of UCS-2
*
* Usage remove_emoji('Lorem ipsum 🥊dolor 🤒sit amet, consectetur adipiscing 🍂 elit. 🌰🍁🌿🌾🌼🌻');
*/
function remove_emoji($text){
return preg_replace('/[\x{1F3F4}](?:\x{E0067}\x{E0062}\x{E0077}\x{E006C}\x{E0073}\x{E007F})|[\x{1F3F4}](?:\x{E0067}\x{E0062}\x{E0073}\x{E0063}\x{E0074}\x{E007F})|[\x{1F3F4}](?:\x{E0067}\x{E0062}\x{E0065}\x{E006E}\x{E0067}\x{E007F})|[\x{1F3F4}](?:\x{200D}\x{2620}\x{FE0F})|[\x{1F3F3}](?:\x{FE0F}\x{200D}\x{1F308})|[\x{0023}\x{002A}\x{0030}\x{0031}\x{0032}\x{0033}\x{0034}\x{0035}\x{0036}\x{0037}\x{0038}\x{0039}](?:\x{FE0F}\x{20E3})|[\x{1F441}](?:\x{FE0F}\x{200D}\x{1F5E8}\x{FE0F})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F467}\x{200D}\x{1F467})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F467}\x{200D}\x{1F466})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F467})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F466}\x{200D}\x{1F466})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F466})|[\
@danielcharrua
danielcharrua / weight-required-field.php
Last active April 9, 2020 16:30 — forked from damiencarbery/add-required-attribute.js
Make the 'Weight' field required in WooCommerce Edit Product page.
<?php
/*
Plugin Name: Require Weight field (WooCommerce)
Plugin URI: https://charrua.es
Description: Make weight field required when adding/editing product. Usefull when using weight shipping.
Author: Daniel Pereyra Costas
Author URI: https://charrua.es
Version: 0.1
*/
@danielcharrua
danielcharrua / astra_blog_gutenberg_content.php
Last active December 9, 2023 23:28
Add Gutenberg content to blog page on Astra
//Please add this to your functions.php
/**
* This snippet adds Blog page Gutenberg content before the posts grid on Astra theme if you are using a static homepage.
*
* First create a page for displaying posts, for example "Blog", add any Gutenberg block.
* Then on settings assign a static frontpage and the created "Blog" page to blog posts.
*
* You can now add any block content to the "Blog" page and it will be shown before the posts loop.
*/
@danielcharrua
danielcharrua / gravity_forms_date_conditional.js
Created January 6, 2021 18:06
Add conditional fields depending on a date field
<script>
gform.addAction( 'gform_input_change', function( elem, formId, fieldId ) {
if ( fieldId == 13 ) {
valorCampoDate = elem.value;
var parts = valorCampoDate.split( '/' );
// Presta atención al mes ( parts[1] ); JavaScript cuenta los meses desde 0:
// Enero - 0, Febrero - 1, etc.
var myDate = new Date( parts[2], parts[1] - 1, parts[0] );
// Cambiar el valor del campo oculto.
@danielcharrua
danielcharrua / functions.php
Last active September 24, 2021 15:43
Restrict permission on WooCommerce REST API
<?php
/**
* Restrict permission on WooCommerce REST API based on user_login and request type
* Let 'daniel' access ONLY to products data
*/
add_filter( 'woocommerce_rest_check_permissions', 'charrua_allow_only_products', 10, 4 );
function charrua_allow_only_products( $permission, $context, $object_id, $type ) {