Skip to content

Instantly share code, notes, and snippets.

View ChrisFlannagan's full-sized avatar

Chris Flannagan ChrisFlannagan

View GitHub Profile
<?php
function email_past_due() {
global $wpdb;
$mailer = WC_Emails::instance();
$date = date( "Y-m-d H:i:s", current_time( 'timestamp' ) + 86400 * 7 );
$due_orders = $wpdb->get_col( $wpdb->prepare( "
SELECT posts.ID
FROM {$wpdb->posts} AS posts
<?php
/**
* Only allow one payment plan purchase (Subscription) at a time
*/
add_filter( 'woocommerce_add_to_cart_validation', 'woo_block_sub', 10, 2 );
function woo_block_sub( $valid, $product_id ) {
// Get the current product
$current_product = wc_get_product( $product_id );
@ChrisFlannagan
ChrisFlannagan / remove-hidden-products-query.php
Last active October 9, 2022 12:12
Woo doesn’t filter out products with hidden catalog visibility outside of main shop loop. This is important to remember when using the REST API for front end display or general search results. This code snippet will keep them from showing outside of the admin. Source: whoischris.com
<?php
/**
* https://whoischris.com/remove-catalog-visibility-hidden-products-in-woocommerce-from-search-wp-rest-api-results/
*/
add_action( 'pre_get_posts', 'hidden_search_query_fix' );
public function hidden_search_query_fix( $query = false ) {
if ( ! is_admin() && isset( $query->query['post_type'] ) && $query->query['post_type'] === 'product' ) {
$tax_query = $query->get( 'tax_query' );
$tax_query[] = [
<?php
/**
* Plugin Name: Give - Free
**/
/**
* Register our plugin so it shows up as an option in the Give gateway settings
*/
add_filter( 'give_payment_gateways', function() {
// Here replace 'give_free' with a unique slug for your plugin. You will use this slug throughout this plugin.
<?php
/**
* If inserting a gif always place the full size image
*
* @param string $html
* @param int $send_id
* @param array $attachment
*
* @return string
*/
@ChrisFlannagan
ChrisFlannagan / geodistance.php
Created October 13, 2017 16:52
Calculate distance between to coordinates of latitude and longitude using the WP REST API and return posts ordered by distance from user's coordinates
<?php
/**
* Heavily borrowed from: http://xplus3.net/2010/08/08/filtering-on-a-non-standard-database-field-with-wordpress/
**/
class CoordinatesTable extends DB {
protected $db_option = "coordinates_db";
<?php
class BP_SelectHome extends BP_Component {
function __construct() {
global $bp;
parent::start(
'bp-select-home',
__( 'Select Home', 'fp-stroke-community' ),
dirname( __FILE__ )
);
<?php
class Login {
public function hook(){
add_filter( 'determine_current_user', [ $this, 'login_via_token' ], 20 );
add_action( 'rest_api_init', [ $this, 'register_routes' ], 10 );
}
public function register_routes(){
<?php
add_filter( 'rest_product_query', function( $query_args, $request ) {
if ( isset( $_GET['search'] ) && ! empty( $_GET['search'] ) && class_exists( '\SWP_Query' ) ) {
$query_args['orderby'] = 'post__in';
}
return $query_args;
}, 99, 2 );
<?php
add_action( 'pre_get_posts', function( $query ) {
if ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST ) {
return
}
if ( is_admin() || ! isset( $query->query['post_type'] ) || $query->query['post_type'] !== 'product' ) {
return;
}