Skip to content

Instantly share code, notes, and snippets.

View doubleedesign's full-sized avatar

Leesa Ward doubleedesign

View GitHub Profile
@doubleedesign
doubleedesign / widget-product-categories.php
Created January 17, 2021 06:27
Override the output of the WooCommerce product categories widget to be a Bootstrap accordion
<?php
/**
* Product Categories Widget
* Modifies the WooCommerce product categories widget to display as a Bootstrap accordion.
*
* @package WooCommerce/Widgets
* @version 2.3.0
*/
defined( 'ABSPATH' ) || exit;
@doubleedesign
doubleedesign / create-zip.php
Last active January 17, 2021 06:20
Add a "download all" option to emails for WooCommerce downloadable products. Zips all the files and stores the zip in a specified directory.
<?php
/**
* Utility function to create a zip file from an array of file URLs
* Used for download links in emails
* @param array $files
* @param string $filename
*
* @return string
*/
function doublee_zip_order_files(array $files, string $filename) {
@doubleedesign
doubleedesign / acf-tsf-integration.php
Last active December 9, 2022 13:06
Get meta descriptions in The SEO Framework from ACF flexible content fields
<?php
/**
* The SEO Framework + ACF flexible content integration
* TSF will look at the excerpt and then the content to generate the default meta description.
* If both of those are empty, this code looks for ACF flexible modules to get it from.
* // TODO: Make this work with archives as well as posts
* @param $description
* @param $args
*
* @return mixed|string
@doubleedesign
doubleedesign / _export-orders.php
Last active March 19, 2024 10:05
Export selected data about the currently shown WooCommerce orders to a CSV file
<?php
/**
* Function to export the orders list to a CSV download (not stored anywhere)
* CSV construction based on https://gist.github.com/vrushank-snippets/4274500
* Dev notes:
* - This file is designed to be called via AJAX, with that function providing the order IDs.
* - To use this without AJAX you would just need to define $order_ids = wp_list_pluck($wp_query->posts, 'ID') instead,
* and define $filename as something appropriate here.
*/
function doublee_export_orders() {
@doubleedesign
doubleedesign / current-menu-item.php
Created January 3, 2021 07:26
Add class to CPT archive link in menus when viewing a post of that type
<?php
// Add current-menu-item to post type archive link for this post's type
function doublee_menu_classes($classes, $item) {
global $post;
$id = (isset($post->ID) ? get_the_ID() : NULL);
if(isset($id) && $item->type == 'post_type_archive') {
$current_post_type = get_post_type($id);
$link_post_type = $item->object;
if($current_post_type == $link_post_type) {
@doubleedesign
doubleedesign / user-join-date-column.php
Created December 22, 2020 10:14
Add a join date column to the users table in wp-admin
<?php
/**
* Add custom columns in Users area in the CMS
* @param $columns
*
* @return mixed
*/
function doublee_manage_users_columns($columns) {
$columns['join_date'] = 'Join date';
@doubleedesign
doubleedesign / add-base-tier-option.php
Last active January 18, 2021 01:11
Automatically downgrade a WooCommerce subscription (to a free, no-expiry variation) instead of expiring it
<?php
/**
* Add base tier option to Advanced tab of subscription product
*/
function doublee_subscription_product_advanced_settings() {
$product = wc_get_product(get_the_id());
if($product->get_type() === 'variable-subscription') {
$variations = $product->get_available_variations();
$variation_options = array();
foreach ($variations as $variation) {
@doubleedesign
doubleedesign / scripts.js
Created May 18, 2020 09:05
Use Animate.css for Slick slider transitions
// Note: This assumes you already have the CSS set up for the classes you want to use.
function initCarousel() {
$('.my-carousel').slick({
slidesToShow: 1,
slidesToScroll: 1,
autoplay: false,
adaptiveHeight: false,
fade: true,
@doubleedesign
doubleedesign / query.php
Last active January 8, 2020 06:01
Wordpress Event CPT: Filter archive by ACF date field, with month from and two selected by the user
<?php
/**
* Archive filter queries using the drop-downs on each archive
*
* @see filters.php
* @param $query
*/
function wh_filter_archives($query) {
// Do not modify queries in the admin
@doubleedesign
doubleedesign / checkout-functions.php
Created May 17, 2019 06:50
Add reCaptcha v2 to WooCommerce Checkout
<?php
/**
* Add reCaptcha to checkout form
* Note: Can't place within the payment part of the form, WooCommerce just won't show it, choose an appropriate action to add it to accordingly
* @param $checkout
*/
function doublee_show_me_the_checkout_captcha($checkout) {
echo '<div class="g-recaptcha" data-sitekey="YOUR_KEY_HERE"></div>';
}
add_action('woocommerce_checkout_order_review', 'doublee_show_me_the_checkout_captcha', 18);