Skip to content

Instantly share code, notes, and snippets.

View klihelp's full-sized avatar
🎯
Focusing on life and money farm

klihelp

🎯
Focusing on life and money farm
View GitHub Profile
add_action( 'template_redirect', 'wc_custom_redirect_after_purchase' );
function wc_custom_redirect_after_purchase() {
global $wp;
if ( is_checkout() && ! empty( $wp->query_vars['order-received'] ) ) {
$order_id = absint( $wp->query_vars['order-received'] );
$order_key = wc_clean( $_GET['key'] );
/**
* Replace {PAGE_ID} with the ID of your page
@rugor
rugor / gist:d2b109e3d4026a53679d
Last active January 19, 2016 20:53
CSS: Fade in element w/ keyframes #rugor #st
// Fade in
.some-element {
-webkit-animation: fadein 2s;
-ms-animation: fadein 2s;
animation: fadein 2s;
}
@-webkit-keyframes fadein {
from {
@BraadMartin
BraadMartin / filters-in-the-wp-rest-api-v2
Last active May 24, 2017 02:22
A list of all of the filters available in the WP REST API v2
rest_avatar_sizes
rest_prepare_attachment
rest_pre_insert_comment
rest_comment_type_trashable
comment_text
@JonS7
JonS7 / get-resource-availability.js
Last active September 27, 2015 13:53
Hacky way to show what resources are fully booked on a single product page using Woocommerce Bookings.
var $product = $('#product');
var $bookingForm = $product.find('.cart');
var $picker = $bookingForm.find('.picker');
var $resources = $('#resources');
function checkAvailability( el ) {
var fully_booked_ids = [];
var jsonArray = el.data( 'fully-booked-days' );
var booking_date_year = $bookingForm.find('#booking_date_year').val();
@JonS7
JonS7 / get-product-availability.php
Last active February 22, 2023 05:49
Couldn't figure out how to use Woocommerce Bookings functions to show if a product was fully booked or not, so came up with this.
function get_product_availability() {
global $product, $post;
// Get dates from custom field
$start_date = get_field('start_date');
$end_date = get_field('end_date');
// Get into class
$WC_Product_Booking = new WC_Product_Booking($product);
@Jany-M
Jany-M / WP_WC_auto-confirm-bookings.php
Last active June 29, 2022 10:52
[WordPress] [WooCommerce] [Bookings] Auto-Confirm Booking upon Order Complete
<?php
add_action( 'woocommerce_order_status_completed', 'mark_confirm_bookings', 20, 1 );
function mark_confirm_bookings( $order_id ) {
global $wpdb;
$order = new WC_Order( $order_id );
$bookings = array();
foreach ( $order->get_items() as $order_item_id => $item ) {
@aFarkas
aFarkas / focus-within.js
Last active August 20, 2020 10:49
simple focus-within polyfill
(function(window, document){
'use strict';
var slice = [].slice;
var removeClass = function(elem){
elem.classList.remove('focus-within');
};
var update = (function(){
var running, last;
var action = function(){
var element = document.activeElement;
@webaware
webaware / orderform-woo-extend-form.php
Last active September 27, 2015 19:59
Extend an Order Form for WooCommerce form with WordPress hooks, instead of hacking templates. Requires version 1.4.0 or higher. Save this file as a simple plugin in the WordPress plugins folder. http://orderform-woo.webaware.net.au/
<?php
/*
Plugin Name: Order Form for WooCommerce extend form
Plugin URI: https://gist.github.com/webaware/1fe598e60f9ad9a912ee
Description: example form extras using hooks
Author: WebAware
Author URI: http://webaware.com.au/
*/
@yoren
yoren / main.html
Last active December 4, 2015 10:44
Tidy Up Your AngularJS WordPress Theme With A Service
<!-- ... -->
<p>{{data.pageTitle}}</p>
<ul>
<li ng-repeat="post in data.posts">
<a href="blog/{{post.ID}}" ng-bind-html="post.title"></a>
<a href="blog/{{post.ID}}" ng-if="post.featured_image.attachment_meta.sizes.thumbnail.url"><img ng-src="{{post.featured_image.attachment_meta.sizes.thumbnail.url}}" alt="{{post.featured_image.title}}" /></a>
<div ng-bind-html="post.excerpt"></div>
</li>
</ul>
@MindyPostoff
MindyPostoff / variation-thumbnail.php
Last active September 27, 2015 13:44
Display product featured image in cart instead of variation thumbnail
// Add this to your child theme's functions.php file
function wc_custom_cart_thumb( $thumb, $cart_item ) {
return get_the_post_thumbnail( $cart_item['product_id'], 'shop_thumbnail' );
}
add_filter( 'woocommerce_cart_item_thumbnail', 'wc_custom_cart_thumb', 10, 2 );