Skip to content

Instantly share code, notes, and snippets.

@goranefbl
goranefbl / gist:afc081571482f1c44ff72d4c49cba508
Created March 30, 2021 19:15 — forked from mikejolley/gist:1604009
WooCommerce - Add a special field to the checkout, order emails and user/order meta
/**
* Add the field to the checkout
**/
add_action('woocommerce_after_order_notes', 'my_custom_checkout_field');
function my_custom_checkout_field( $checkout ) {
echo '<div id="my_custom_checkout_field"><h3>'.__('My Field').'</h3>';
/**
@goranefbl
goranefbl / 0_README.md
Created December 7, 2019 12:16 — forked from drazisil/0_README.md
Example code using react-filepond and multer to upload files to a server
$.ajax({
type: "POST",
url: 'https://blissco.sandbox.onample.com/api/v1/users/login',
data: 'username=user&password=pass',
success: function(data)
{
let headers = new Headers();
headers.set('Authorization', 'Basic ' + btoa("key:secret"));
headers.set('Content-Type','application/json');
@goranefbl
goranefbl / updates.php
Created January 2, 2018 13:34 — forked from digitalchild/updates.php
WooCommerce 3.0 Compatibility
<?php
# WooCommerce 2.6 -> 3.0 "Compatibility" Variables
$order_id = ( version_compare( WC_VERSION, '2.7', '<' ) ) ? $order->id : $order->get_id();
$order_date = ( version_compare( WC_VERSION, '2.7', '<' ) ) ? $order->order_date : $order->get_date_created();
$billing_first_name = ( version_compare( WC_VERSION, '2.7', '<' ) ) ? $order->billing_first_name : $order->get_billing_first_name();
$billing_last_name = ( version_compare( WC_VERSION, '2.7', '<' ) ) ? $order->billing_last_name : $order->get_billing_last_name();
@goranefbl
goranefbl / subscription-renewal-process.md
Created November 22, 2017 11:47 — forked from thenbrent/subscription-renewal-process.md
Brief developer's guide to the application flow during the subscription renewal process within WooCommerce Subscriptions

WoCommerce Subscriptions processes automatic renewal payments via the following flow:

  1. its scheduling system, Action Scheduler, will run every minute and find any woocommerce_scheduled_subscription_payment actions scheduled to run now or within the last minute
  2. if there are woocommerce_scheduled_subscription_payment actions scheduled for anytime before now, Action Scheduler will grab a batch of those actions and begin processing them (which just means triggering do_action( 'scheduled_subscription_payment', $subscription_id ) for any 3rd party code to handle)
  3. Subscriptions attaches two important functions as callbacks on the 'woocommerce_scheduled_subscription_payment' hook to process renewal for that subscription when it is called:
  4. WC_Subscriptions_Manager::prepare_renewal(), which is responsible for
/**
* Insert an attachment from an URL address.
*
* @param String $url
* @param Int $post_id
* @param Array $meta_data
* @return Int Attachment ID
*/
function crb_insert_attachment_from_url($url, $post_id = null) {
@goranefbl
goranefbl / formtocookie.js
Created April 3, 2017 11:08 — forked from themactep/formtocookie.js
How to save form to cookies, restore form from cookies. Requires jQuery and jQuery Cookie plugin.
/*
* Save Form To Cookie
* (cc) Paul Philippov, themactep@gmail.com
*
* This is rather a proof of concept than a production-ready solution.
* It does not handle radio buttons and such.
* You might want to extend it to suit your needs.
*
* Usage:
*
@goranefbl
goranefbl / auto-coupon-woo.php
Created January 29, 2017 19:42 — forked from jwebcat/auto-coupon-woo.php
Automatically apply coupon to cart WooCommerce
add_action( 'woocommerce_before_cart', 'apply_matched_coupons' );
function apply_matched_coupons() {
global $woocommerce;
$get1 = 'getonech'; // your coupon code here
$get2 = 'gettwoch'; // your coupon code here
$get3 = 'getthreech'; // your coupon code here
$get4 = 'getfourch'; // your coupon code here
$get5 = 'getfivech'; // your coupon code here
@goranefbl
goranefbl / GitHub curl.sh
Created November 2, 2016 23:57 — forked from Integralist/GitHub curl.sh
Download a single file from a private GitHub repo. You'll need an access token as described in this GitHub Help article: https://help.github.com/articles/creating-an-access-token-for-command-line-use
curl --header 'Authorization: token INSERTACCESSTOKENHERE' \
--header 'Accept: application/vnd.github.v3.raw' \
--remote-name \
--location https://api.github.com/repos/owner/repo/contents/path
# Example...
TOKEN="INSERTACCESSTOKENHERE"
OWNER="BBC-News"
REPO="responsive-news"
@goranefbl
goranefbl / gist:8eac228f6e8f7ae439222d24e482d129
Created November 2, 2016 23:48 — forked from madrobby/gist:9476733
Download a single file from a private GitHub repo. You'll need an access token as described in this GitHub Help article: https://help.github.com/articles/creating-an-access-token-for-command-line-use
curl -H 'Authorization: token INSERTACCESSTOKENHERE' -H 'Accept: application/vnd.github.v3.raw' -O -L https://api.github.com/repos/owner/repo/contents/path