Skip to content

Instantly share code, notes, and snippets.

@keefyhub
keefyhub / woocommerce-add-multiple-to-cart.js
Last active May 30, 2017 09:56
Recursively adds each product in the array to the cart as WooCommerce cannot handle more than 1 request at a time (will need to create an array of products for this to work)
// Recursively adds each product in the array to the cart as WooCommerce cannot handle more than 1 request at a time
// (will need to create an array for this to work)
function addItemsToCart() {
var buttonTarget = $(".add-multiple-to-cart");
if (productsToAdd.length > 0) {
var product = productsToAdd.shift();
var url = '?add-to-cart=' + product.product_id + '&quantity=' + product.quantity;
$.post(url, function() {
// Based on https://stackoverflow.com/questions/39596477/woocommerce-get-active-subscriptions-in-a-list-between-start-end-date
// This will remove duplicates and only return unique customers
function active_subscription_list($from_date = null, $to_date = null)
{
// Get all customer orders
$subscriptions = get_posts([
'numberposts' => -1,
'post_type' => 'shop_subscription', // Subscription post type
'post_status' => 'wc-active', // Active subscriptions. could also use wc-completed, wc-pending, wc-pending-cancel, wc-cancelled
UPDATE `wp_posts` SET post_author={{NEW_AUTHOR_ID}} WHERE `post_author` = {{OLD_AUTHOR_ID}} AND `post_type` = '{{POST_TYPE}}'
editor.addButton('add_dummy_content', {
title: 'Add dummy content',
onclick: function () {
editor.windowManager.open({
title: 'Add dummy content',
body: [
{
type: 'checkbox',
name: 'title',
text: 'Title'
@keefyhub
keefyhub / functions.php
Created September 17, 2018 08:57
Log in as another user for testing
if (!is_user_logged_in()) {
$user_id = 4;
$user = get_user_by('id', $user_id);
if ($user) {
wp_set_current_user($user_id);
wp_set_auth_cookie($user_id);
}
}
@keefyhub
keefyhub / functions.php
Created October 2, 2018 10:09
Resend Woocommerce emails
<?php
function resend_email()
{
if (!isset($_GET['resend_email'])) return;
if (!$_GET['resend_email']) return;
if (!is_user_logged_in()) return;
$customer_id = $_GET['resend_email'];
$email = WC()->mailer()->emails['WC_Email_Customer_New_Account'];
@keefyhub
keefyhub / functions.php
Created January 28, 2019 11:57
Get available layouts from flexible content class
$class = new ReflectionClass('\SS_ACF\Components\FlexibleContent');
$methods = $class->getMethods(ReflectionMethod::IS_PUBLIC);
asort($methods);
foreach ($methods as $function) {
if ($function->class === 'SS_ACF\Components\FlexibleContent') {
echo "'{$function->name}',<br>";
}
}
@keefyhub
keefyhub / functions.php
Created March 20, 2019 12:08
Set random images from library
$args = [
'post_type' => 'post',
'posts_per_page' => -1
];
$results = new WP_Query($args);
while ($results->have_posts()): $results->the_post();
$images = [
793,
@keefyhub
keefyhub / functions.php
Created June 20, 2019 13:29
Validate ACF licence
add_filter('acf/settings/show_admin', '__return_false');
add_action('admin_action_auto_set_license_keys', 'auto_set_license_keys');
add_filter('plugin_action_links_advanced-custom-fields-pro/acf.php', 'add_action_to_acf');
function add_action_to_acf($actions)
{
$actions[] = '<a href="' . wp_nonce_url('admin.php?action=auto_set_license_keys', basename(__FILE__), 'duplicate_nonce') . '">Validate Licence</a>';
return $actions;
}
@keefyhub
keefyhub / functions.php
Created June 21, 2019 11:57
ACF colour editor
<?php
add_action('after_setup_theme', 'prefix_register_colors');
function prefix_register_colors()
{
add_theme_support(
'editor-color-palette', [
[
'name' => esc_html__('Black', 'prefix_textdomain'),
'slug' => 'black',
'color' => '#333',