Skip to content

Instantly share code, notes, and snippets.

View jamesgol's full-sized avatar

James Golovich jamesgol

  • Eastern Washington
View GitHub Profile
@jamesgol
jamesgol / gist:3d00dea11b1a0ea9e67f178739a64b51
Created September 17, 2021 17:34
WooCommerce Cart Stock Reducer, get virtual and actual stock in code
$csr = WC()->integrations->get_integration('woocommerce-cart-stock-reducer');
$actual_stock = $csr->get_actual_stock_available( $product );
$virtual_stock = $csr->get_virtual_stock_available( $product );
@jamesgol
jamesgol / gist:ac15afd39453fbee4367e5ac4c7c16ba
Last active May 28, 2021 17:10
Append post_status to WooCommerce orders menu
add_action( 'admin_init', 'woo_set_order_menu_default' );
function woo_set_order_menu_default() {
global $submenu;
$original_menu = 'edit.php?post_type=shop_order';
foreach ( $submenu['woocommerce'] as $id => &$menu ) {
if ( $menu[2] === $original_menu ) {
// Append post_status only to WooCommerce orders page
$menu[2] = $original_menu . '&post_status=wc-processing';
}
@jamesgol
jamesgol / gist:39f5404ba766563780f33b6ff3eaa1f8
Created October 25, 2019 04:19
Pods GF Capability quick fix
add_filter( 'pods_roles_get_capabilities', 'temp_fix_for_gf_pods', 10, 1 );
function temp_fix_for_gf_pods( $capabilities ) {
if ( version_compare( '2.7.15', PODS_VERSION, '<=' ) && is_callable( 'GFCommon::all_caps' ) ) {
$capabilities = array_merge( $capabilities, GFCommon::all_caps() );
}
return $capabilities;
}
@jamesgol
jamesgol / gist:a7bb7dfaee3d565822de189c210cd484
Created November 2, 2018 00:31
Add quantity to WooCommerce shop loop
add_action( 'woocommerce_after_shop_loop_item', 'jmg_woo_add_stock' );
function jmg_woo_add_stock() {
global $product;
if ( $product->managing_stock() ) {
// Only on products with managed stock
echo wc_get_stock_html( $product );
}
}
add_filter( 'pods_pod_form_success_message', 'jmg_success_message' );
function jmg_success_message( $message ) {
return 'So long and thanks for all the fish!';
}
@jamesgol
jamesgol / gist:e6b8d029d7b87593ba12e5d814734d3a
Created March 28, 2018 20:40
Keep WooCommerce from mentioning backorders unless the item is actually out of stock
add_filter( 'woocommerce_product_backorders_require_notification', 'jmg_backorders_notification', 10, 2 );
function jmg_backorders_notification( $notify, $product = null ) {
if ( $product && 'notify' === $product->get_backorders() && $product->is_in_stock() ) {
return false;
}
return $notify;
}
@jamesgol
jamesgol / gist:b7b97a17c18ae531f697c06edd32d628
Last active March 12, 2018 02:25
Allow Download Monitor tags and exclude_tags attributes to support AND and OR
<?php
namespace Example\DownloadMonitor;
/**
* Force DownloadMonitor WordPress plugin to handle tags + exclude_tags attributes the same was as Category is
* Duplicates behavior of https://github.com/download-monitor/download-monitor/pull/488
* without requiring patching the code. This will be unnecessary if the PR gets committed
*/
class Shortcodes {
@jamesgol
jamesgol / gist:605898274b696c3081bafad049ad606b
Created February 7, 2018 22:31
Stop WooCommerce.com nag
add_filter( 'woocommerce_helper_suppress_admin_notices', 'jmg_woocommerce_helper_suppress_admin_notices' );
// Don't show the 'Connect your store to WooCommerce.com to receive extensions updates and support.' nag
function jmg_woocommerce_helper_suppress_admin_notices( $default ) {
return true;
}
@jamesgol
jamesgol / gist:33eea04760b47c8bcd62132ac7108904
Created September 5, 2017 02:51
Allow WooCommerce variations to be added to cart via URL
add_action( 'init', 'woo_add_to_cart_fixup' );
function woo_add_to_cart_fixup() {
// Duplicate WooCommerce variation attributes from $_GET to $_POST because WC_Form_Handler->add_to_cart_handler_variable only looks in $_POST
if ( isset( $_GET, $_GET['add-to-cart'] ) ) {
foreach ( $_GET as $key => $value ) {
if ( false !== strpos( $key, 'attribute' ) ) {
$_POST[ $key ] = $value;
}
}
}
@jamesgol
jamesgol / CPT-Admin-Fields.php
Created October 25, 2016 21:45
Pods CPT Admin Fields
<?php
/**
* Name: CPT Admin Fields
*
* Description: Allow adding fields to the CPT editor table.
*
* Version: 2.3
*
* Category: Advanced
*