Skip to content

Instantly share code, notes, and snippets.

@kidunot89
kidunot89 / apollo-client.js
Last active July 10, 2020 05:43
useCartMutations - React Hook that use "@apollo-react-hooks", and "uuid" to bundle WooGraphQL cart mutations in a modular tool.
// Node modules
import { ApolloClient } from 'apollo-client';
import { HttpLink } from 'apollo-link-http';
import { InMemoryCache, defaultDataIdFromObject } from 'apollo-cache-inmemory';
import { ApolloLink } from 'apollo-link';
import { onError } from 'apollo-link-error';
import { get, isEmpty } from 'lodash';
// Local imports
import { typeDefs, resolvers } from './schema';
@jasonbahl
jasonbahl / order-by-acf-like-count.php
Last active June 13, 2023 16:29
Shows how to add a custom order value to a connection to order by a custom field.
add_filter( 'graphql_PostObjectsConnectionOrderbyEnum_values', function( $values ) {
$values['LIKE_COUNT'] = [
'value' => 'like_count',
'description' => __( 'The number of likes on the post', 'wp-graphql' ),
];
return $values;
} );
add_action( 'graphql_register_types', function() {
$post_types = WPGraphQL::$allowed_post_types;
if ( ! empty( $post_types ) && is_array( $post_types ) ) {
foreach ( $post_types as $post_type ) {
$post_type_object = get_post_type_object( $post_type );
/**
* Get the Type name with ucfirst
@lukecav
lukecav / Command
Last active January 22, 2021 13:07 — forked from BronsonQuick/gist:5185918001f4df5c5d15
Delete ActionScheduler comments and scheduled-action post types in WooCommerce using WP-CLI
wp comment list --field=comment_ID --'comment_author'='ActionScheduler' --number=1000 | xargs wp comment delete --force
wp post list --field=ID --post_type=scheduled-action --posts_per_page=1000 | xargs wp post delete --force
wp post list --field=ID --post_type=scheduled-action --posts_per_page=1000 --post_status=trash | xargs wp post delete --force
wp post list --field=ID --post_type=scheduled-action --posts_per_page=1000 --post_status=cancel | xargs wp post delete --force
@jacobarriola
jacobarriola / markup.html
Created October 31, 2016 15:49
Blurry to awesome images
<figure class="placeholder" data-large="{path to large image}">
<img src="{path to small image}" class="img-small loaded" alt="{alt}" /> <!-- small image about 50px wide and height to match ratio; keep to less than 3k -->
<div style="padding-bottom: {image ratio}%;"></div> <!-- ratio is height-in-px/width-in-px * 100 -->
</figure>
@mike-north
mike-north / enemy_of_the_state.md
Last active January 11, 2017 04:29
EmberFest 2016 - Enemy of the state
@mikejolley
mikejolley / functions.php
Created March 10, 2016 09:39
WooCommerce Disable guest checkout for certain products
<?php
// Code goes in theme functions.php or a custom plugin
add_filter( 'pre_option_woocommerce_enable_guest_checkout', 'conditional_guest_checkout_based_on_product' );
function conditional_guest_checkout_based_on_product( $value ) {
$restrict_ids = array( 1, 2, 3 ); // Replace with product ids which cannot use guest checkout
if ( WC()->cart ) {
$cart = WC()->cart->get_cart();
sudo curl -o /usr/local/bin/imgcat -O https://raw.githubusercontent.com/gnachman/iTerm2/master/tests/imgcat && sudo chmod +x /usr/local/bin/imgcat
# If you have a better way to fix the permissions, comment below!
anonymous
anonymous / bonfire-reverse-a-string#.js
Created December 7, 2015 00:15
http://www.freecodecamp.com/jacobarriola 's solution for Bonfire: Reverse a String
// Bonfire: Reverse a String
// Author: @jacobarriola
// Challenge: http://www.freecodecamp.com/challenges/bonfire-reverse-a-string#
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function reverseString(str) {
return str.split("").reverse().join("");
}
reverseString("hello");