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 / 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 / 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 / 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 / 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 ) {
@danielcharrua
danielcharrua / functions.php
Created September 26, 2021 06:46
Only generate invoices when company field is filled on WooCommerce PDF Invoices & Packing Slips
<?php
/**
* Generate invoices only when company field (on WooCommerce checkout) is filled
*
* Plugin: WooCommerce PDF Invoices & Packing Slips
*/
add_filter( 'wpo_wcpdf_document_is_allowed', 'wpo_wcpdf_only_allow_invoices_for_companies', 10, 2 );
function wpo_wcpdf_only_allow_invoices_for_companies( $allowed, $document ) {
if ( $document->type == 'invoice' && !empty( $order = $document->order ) ) {
@danielcharrua
danielcharrua / functions.php
Created September 27, 2021 15:03
Disable loading YITH gift card code on coupon field on cart/checkout
<?php
/**
* Disable loading gift card code on coupon field on cart/checkout
*
* Plugin: YITH WooCommerce Gift Cards (free version)
*/
if ( ! function_exists( 'yith_ywgc_dont_allow_gift_cards_in_coupons' ) ) {
function yith_ywgc_dont_allow_gift_cards_in_coupons() {
@danielcharrua
danielcharrua / functions.php
Created October 7, 2021 14:41
Hide shipping rates when free shipping is available, but keep "Local pickup"
<?php
/**
* Hide shipping rates when free shipping is available, but keep "Local pickup"
* Updated to support WooCommerce 2.6 Shipping Zones
*/
function hide_shipping_when_free_is_available( $rates, $package ) {
$new_rates = array();
foreach ( $rates as $rate_id => $rate ) {
@danielcharrua
danielcharrua / functions.php
Last active November 12, 2021 11:25
WooCommerce Importer - custom JSON meta field and decode it on import
<?php
//https://github.com/woocommerce/woocommerce/wiki/Product-CSV-Importer-&-Exporter
/**
* Process the data read from the CSV file
* If the field yikes_woo_products_tabs exists as a meta field, read it and decode the JSON. Then WooCommerce will insert it as serialized data to DB.
* This just saves the decoded JSON in meta data, but you can do anything you want here with the data.
*
* @param WC_Product $object - Product being imported or updated.