Skip to content

Instantly share code, notes, and snippets.

@MCKLtech
MCKLtech / woocommerce-add-fee-to-order.php
Created March 7, 2019 20:52
HOWTO: Adding A Discount or Fee to a WooCommerce Order Programmatically
<?php
/*
* The following code assumes you have an WC Order object already. We'll be adding a discount to an order.
* This code cannot be added directly anywhere, it is merely an explanation of how this can be done.
* We will add a discount to the order using Fees
*/
/* Assume order is set up already */
@MCKLtech
MCKLtech / wordpress-ajax-endpoint.php
Created March 7, 2019 20:58
HOWTO: Create a WordPress AJAX Endpoint for a JSON Payload
<?php
/*
* In this GIST, we register a webhook that will be available for other applications to call e.g. JSON
* This code could be added to functions.php or your own plugin.
*/
//Register an end point for logged in users
add_action("wp_ajax_my_webhook", "my_webhook");
//Register an end point for logged out users
@MCKLtech
MCKLtech / spark-add-team-member.php
Created September 13, 2019 14:50
This gist demonstrates a method of adding a Spark User to an existing Spark Team
<?php
use App\Team;
use Laravel\Spark\Spark;
use Laravel\Spark\Contracts\Interactions\Settings\Teams\AddTeamMember;
//Get a Spark User
$sparkUser = Spark::user()->where('email', '[email protected]')->first();
//TODO: Check user exists
@MCKLtech
MCKLtech / spark-new-user-team.php
Created September 13, 2019 14:52
This gist demonstrates a method of creating a Spark User and setting up their initial Team
<?php
use App\Team;
use Laravel\Spark\Spark;
use Laravel\Spark\Interactions\Settings\Teams\CreateTeam;
//Create a User
$sparkUser = Spark::user();
$sparkUser->forceFill([
<?php
/* An example of two methods to retrieve only WooCommerce Bookings Products */
use WC_Product_Booking_Data_Store_CPT;
$booking_products_ids = WC_Product_Booking_Data_Store_CPT::get_bookable_product_ids();
foreach($booking_products_ids as $id) {
@MCKLtech
MCKLtech / wcs-functions.php
Created May 25, 2020 14:20
An overview of how to use Gravity Forms to cancel a WooCommerce Subscription programically
/* This code is NOT safe for production usage. Do not use in live systems */
/* Add to functions.php */
add_action( 'gform_after_submission', 'wc_demo_cancel_sub', 10, 2 );
function wc_demo_cancel_sub( $entry, $form ) {
//Get the subscription id from the form
//We assume the field wc_sub_id contains the subscription ID
@MCKLtech
MCKLtech / create-order-square-php-sdk.php
Last active June 19, 2023 03:06
This gist gives a high level overview of how to create an order in Square using the PHP SDK. For an order to show in the Dashboard you must create, fulfill AND pay for the order.
$body = new \Square\Models\CreateOrderRequest;
//Add 5 of the same line items
//We are creating them dynamically
$qty = 5;
$lineItem = new \Square\Models\OrderLineItem($qty);
$lineItem->setName('Latte');
$money = new \Square\Models\Money;
$money->setCurrency('CAD');
//Amount in Cents e.g. $5.50
<?php
namespace GroundhoggDisposable;
use Groundhogg\Contact;
/*
* Plugin Name: Groundhogg - Disposable Email Checker
* Plugin URI: https://www.wooninja.io/?utm_source=wp-plugins&utm_campaign=groundhogg-disposable&utm_medium=wp-dash
* Description: Remove disposable emails from your Groundhogg List
<?php
/*
* Plugin Name: Groundhogg - Loom Replacements
* Plugin URI:
* Description: Adds a replacement code to embed Loom videos in Groundhogg Emails
* Version: 1.0
* Author: Colin Longworth
* Author URI: http://www.wooninja.io
* Developer: Colin Longworth
@MCKLtech
MCKLtech / woocommerce-groundhogg-blocker.php
Last active January 24, 2022 21:20
A basic blocker for WooCommerce that works on Groundhogg.io Tags
<?php
/*
* Plugin Name: WooCommerce Customer Blocker for Groundhogg
* Plugin URI:
* Description: Block customers at the checkout using tags in Groundhogg
* Version: 1.0
* Author: Colin Longworth
* Author URI: http://www.wooninja.io
* Developer: Colin Longworth