Skip to content

Instantly share code, notes, and snippets.

@chrismccoy
chrismccoy / gutenberg.txt
Last active March 13, 2025 19:11
Gutenberg Resources
Eliminate All Blocks from Editor
wp.data.dispatch( 'core/block-editor' ).resetBlocks([]);
How to disable and lock Gutenberg blocks
https://kinsta.com/blog/disable-gutenberg-blocks/
Convert group of file blocks to ACF block
https://bdwm.be/gutenberg-case-study-convert-group-of-file-blocks-to-acf-block/
Enabling Gutenberg-Based Custom Post Types and Taxonomies
@alordiel
alordiel / cart.php
Created January 24, 2018 08:52
[WooCommerce 3.2.6] Get product variations from cart items (used in cart.php)
<?php
//Loop through each item from the cart
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
//get the current product ID
$product_id = $cart_item['product_id'];
//first - check if product has variations
if(isset($cart_item['variation']) && count($cart_item['variation']) > 0 ){
//get the WooCommerce Product object by product ID
$current_product = new WC_Product_Variable($product_id);
//get the variations of this product
@diggeddy
diggeddy / Elementor - Check Radio button by default
Created January 2, 2018 00:08
Make a Elementor form radio button checked by default
/*---- JavaScript Check radio button ------*/
/*---- change ElementID to match the ------*/
<script type="text/javascript">
window.onload = function check() {
document.getElementById("form-field-LABEL-#").checked = true;
}
</script>
@ajmorris
ajmorris / functions.php
Created December 7, 2017 04:13
Code for WooCommerce to check if products in the cart belong to one of the categories we're looking for.
<?php
/**
* Check if a specific product category is in the cart
*/
function wc_ninja_category_is_in_the_cart() {
// Add your special category slugs here
$categories = array( 'clothing', 'posters' );
// Products currently in the cart
$cart_ids = array();
@ajmorris
ajmorris / functions.php
Created December 7, 2017 04:08
Remove checkout field if product IDs exist. WooCommerce / WordPress
<?php
/**
* Conditionally remove a checkout field based on products in the cart
*/
function wc_ninja_remove_checkout_field( $fields ) {
if ( ! wc_ninja_product_is_in_the_cart() ) {
unset( $fields['billing']['billing_company'] );
}
return $fields;
@ajmorris
ajmorris / functions.php
Created December 7, 2017 04:06
Check for specific Product IDs in your cart to return true if they are there. WooCommerce/WordPress
<?php
/**
* Check if a specific product ID is in the cart
*/
function wc_ninja_product_is_in_the_cart() {
// Add your special product IDs here
$ids = array( '45', '70', '75' );;
// Products currently in the cart
$cart_ids = array();
@igorbenic
igorbenic / refund_order.php
Last active November 5, 2021 00:32
How to Create WooCommerce Refunds Programmatically | ibenic.com/how-to-create-woocommerce-refunds-programmatically
<?php
/**
* Process Order Refund through Code
* @return WC_Order_Refund|WP_Error
*/
function ibenic_wc_refund_order( $order_id, $refund_reason = '' ) {
$order = wc_get_order( $order_id );
// IF it's something else such as a WC_Order_Refund, we don't want that.
@spivurno
spivurno / gw-gravity-forms-rotating-values.php
Last active September 1, 2021 20:54
Gravity Wiz // Gravity Forms // Rotating Values
<?php
/**
* WARNING! THIS SNIPPET MAY BE OUTDATED.
* The latest version of this snippet can be found in the Gravity Wiz Snippet Library:
* https://github.com/gravitywiz/snippet-library/blob/master/gravity-forms/gw-round-robin.php
*/
/**
* Gravity Wiz // Gravity Forms // Rotating Values
* http://gravitywiz.com/
*/
@mgibbs189
mgibbs189 / functions.php
Created February 10, 2017 17:14
FacetWP - WooCommerce Memberships fix
<?php
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
if ( 'wc_user_membership' == $query->get( 'post_type' ) ) {
$is_main_query = false;
}
return $is_main_query;
}, 10, 2 );
@bekarice
bekarice / registration-order-link-for-woocommerce.php
Last active December 16, 2024 05:07
Automatically link previous orders to new WooCommerce customer accounts upon registration