Skip to content

Instantly share code, notes, and snippets.

@NickGreen
NickGreen / maps_tags.php
Last active September 22, 2020 22:47 — forked from tiagonoronha/maps_tags.php
MAPS add tags to posts - wrapped in CLI command
<?php
class MAPS_Tags extends WP_CLI_COMMAND {
function __invoke() {
$lines = file( dirname(__FILE__) . '/tags.csv', FILE_SKIP_EMPTY_LINES | FILE_IGNORE_NEW_LINES );
foreach ( $lines as $line ) {
$line = str_getcsv( $line );
@NickGreen
NickGreen / gallery_shortcode_filter.php
Last active September 15, 2020 19:46
Filter classic editor gallery shortcodes
@NickGreen
NickGreen / phpcs.yml
Created July 17, 2020 22:07
GH action for running PHPCS checks
on: pull_request
name: Code tests
jobs:
runPHPCSInspection:
name: Run PHPCS inspection
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
@NickGreen
NickGreen / phpcs.xml
Created July 17, 2020 22:02
phpcs.xml ruleset
<?xml version="1.0"?>
<!--This entire file can be optionally deleted if this issue is fixed: https://github.com/rtCamp/action-phpcs-code-review/issues/35 -->
<ruleset name="">
<description>PHPCS declaration for A8CTeam51</description>
<rule ref="WordPress-Extra">
<exclude name="WordPress.Files.FileName.NotHyphenatedLowercase" />
<exclude name="WordPress.Files.FileName.InvalidClassFileName" />
</rule>
@NickGreen
NickGreen / sonos_control.html
Created June 19, 2020 15:30
SONOS API webpage
<!DOCTYPE html>
<html>
<head>
<style>
body {
background:black;
}
#favorites_container {
width:89%;
display:inline-block;
@NickGreen
NickGreen / recipient_custom_field.php
Created May 25, 2020 23:01
Add "recipient" to subscriptions export, for use with Gifting for WooCommerce Subscriptions
<?php
/**
* Add custom headers to the list of default headers exported in the CSV
*
* @param array $headers
* @return array
*/
function my_custom_export_headers( $headers = array() ) {
return array_merge( $headers, array(
'_recipient_user' => 'Recipient',
@NickGreen
NickGreen / storefront_best_seller_args.php
Created April 3, 2020 22:52
Filters out a specific category from Storefront best sellers section on home page
<?php // dont copy this line
add_filter( 'storefront_best_selling_products_shortcode_args', 'custom_storefront_best_selling_products');
function custom_storefront_best_selling_products( $args ) {
$args['category'] = 'installation';
$args['cat_operator'] = 'NOT IN';
return $args;
}
@NickGreen
NickGreen / replace_coupon_amount_with_string.php
Created April 3, 2020 21:47
Replace coupon amount display with a string
<?php // don't copy this line
add_filter( 'woocommerce_cart_totals_coupon_html', 'custom_cart_totals_coupon_html', 30, 3 );
function custom_cart_totals_coupon_html( $coupon_html, $coupon, $discount_amount_html ) {
$discount_amount_html = '<span>Redeemed</span>';
$coupon_html = $discount_amount_html . ' <a href="' . esc_url( add_query_arg( 'remove_coupon', urlencode( $coupon->get_code() ), defined( 'WOOCOMMERCE_CHECKOUT' ) ? wc_get_checkout_url() : wc_get_cart_url() ) ) . '" class="woocommerce-remove-coupon" data-coupon="' . esc_attr( $coupon->get_code() ) . '">' . __( '[Remove]', 'woocommerce' ) . '</a>';
return $coupon_html;
}
@NickGreen
NickGreen / delivery_date.php
Created March 20, 2020 23:16
Add Delivery Date to Order Export CSV
<?php
/**
* Plugin Name: Add delivery date to export
* Plugin URI:
* Description:
* Version: 1.0
* Author:
* Author URI:
**/
@NickGreen
NickGreen / get_subs_by_products.php
Last active March 9, 2020 18:17
Getting subs for known product IDs
<?php
// for troubleshooting specific site.
add_action( 'wp', 'get_subs_by_products' );
function get_subs_by_products() {
$product_ids = array(39002, 39001, 27181, 26017, 73821, 4178);
$subscriptions = wcs_get_subscriptions( array( 'product_id' => $product_ids, 'subscriptions_per_page' => -1, 'subscription_status' => array( 'wc-active', 'wc-on-hold' ) ) );
$number_of_subs = count($subscriptions);