Skip to content

Instantly share code, notes, and snippets.

@jessepearson
jessepearson / lets-confirm-some-cod-bookings.php
Last active August 7, 2023 14:47
Place Bookings into a confirmed status if they have been paid for via COD - for WooCommerce Bookings
<?php // only copy this line if needed
// related blog post: https://jessepearson.net/2016/11/woocommerce-bookings-cod-payments/
/**
* Function that will put bookings into a Confirmed status if they were paid for via COD
*
* @param int/string $order_id The order id
* @return null
*/
function lets_confirm_some_cod_bookings( $order_id ) {
global $wpdb;
@jessepearson
jessepearson / wc_auto_complete_virtual.php
Created July 4, 2016 20:38
Auto Complete all WooCommerce virtual orders
<?php // only copy this line if needed
/**
* Auto Complete all WooCommerce virtual orders.
*
* @param int $order_id The order ID to check
* @return void
*/
function custom_woocommerce_auto_complete_virtual_orders( $order_id ) {
@jessepearson
jessepearson / jp_filter_edit_shop_order_views.php
Last active December 11, 2022 07:20
WordPress will automatically create a Mine view for post types that have multiple authors. With a recent change to WooCommerce core, the customers are now the author of the orders, so Mine is showing and causing confusion. This filter will remove Mine from orders.
<?php // do not copy this line
/**
* WordPress will automatically create a Mine view for post types that have multiple authors.
* With a recent change to WooCommerce core, the customers are now the author of the orders, so Mine is
* showing and causing confusion. This filter will remove Mine from orders.
*
* @param arr $views The current views being used for orders.
* @return arr The edited views array.
*/
@jessepearson
jessepearson / add-nav-parent-count.php
Created March 4, 2015 17:13
Functions to add a parent count to WordPress nav menus. This is useful if you need to change nav element size based on the number of parent/top level elements.
<?php
/**
* Gets the count of the parent items in a nav menu based upon the id specified.
*
* @param string $nav_id The id of the nav item to get the parent count for.
* @return bool|int False on fail, or the count of how many parent items there are.
* @uses wp_get_nav_menu_items
*/
function count_nav_parent_items( $nav_id = null ) {
@jessepearson
jessepearson / functions.php
Last active October 12, 2022 05:59
Disables opening Terms and Conditions on WooCommerce Checkout page in an inline form and instead open in a new tab or window.
<?php // do not copy this line
/**
* Disables opening the Terms and Conditions page in an inline form on the Checkout page.
* The Terms and Conditions link will then open in a new tab/window.
*/
add_action( 'wp', function() {
remove_action( 'woocommerce_checkout_terms_and_conditions', 'wc_checkout_privacy_policy_text', 20 );
remove_action( 'woocommerce_checkout_terms_and_conditions', 'wc_terms_and_conditions_page_content', 30 );
} );
@jessepearson
jessepearson / jp_change_brand_thumbnail_size.php
Last active October 3, 2022 18:38
Filter to change the thumbnail size for WooCommerce Brands.
<?php // do not copy this line
function jp_change_brand_thumbnail_size( $size ) {
// You would need to create a new size, or use an existing size.
// The plugin https://wordpress.org/plugins/simple-image-sizes/ is perfect for this.
return 'new_brand_thumbnail_size';
}
add_filter( 'woocommerce_brand_thumbnail_size', 'jp_change_brand_thumbnail_size' );
@jessepearson
jessepearson / functions.php
Created July 16, 2020 11:40
Allows for modifying the coupon that is created when AutomateWoo Refer A Friend is used.
<?php // do not copy this line
/**
* Allows for modifying the coupon that is created when AutomateWoo Refer A Friend is used.
*
* It works by modifying the coupon data that is used when creating the new coupon in the cart. The data that is
* able to be applied can be found here: https://github.com/woocommerce/woocommerce/blob/4.3.0/includes/class-wc-coupon.php#L26-L50
* Any edits will make the automatically generated coupon behave like a coupon created under WooCommerce > Coupons.
*
* This example make it so that if either categories 24 or 25 are in the cart, the referral is then applied.
@jessepearson
jessepearson / increase-variation-threshold.php
Last active March 29, 2022 17:46
Increase the number of variations loaded in the WooCommerce front end for dynamic filtering of available variations in the drop down lists.
<?php //only copy this line if needed
/**
* Function filters the threshold for the amount of variables to load in the front end.
*
* @see https://woocommerce.wordpress.com/2015/07/13/improving-the-variations-interface-in-2-4/
*
* @return int 100 The new threshold.
*/
add_filter( 'woocommerce_ajax_variation_threshold', function() { return 100; } );
<?php // do not copy this line
if( ! function_exists( 'mc_child_custom_woocommerce_states' ) ) {
function mc_child_custom_woocommerce_states( $states ) {
$states['LK'] = array(
'LK1001' => __( 'Colombo 1', 'woocommerce' ),
'LK1002' => __( 'Colombo 2', 'woocommerce' ),
'LK1003' => __( 'Colombo 3', 'woocommerce' ),
'LK1004' => __( 'Colombo 4', 'woocommerce' ),
@jessepearson
jessepearson / add_bcc_to_certain_emails.php
Created October 31, 2016 17:19
Add a BCC to certain defined emails sent from WooCommerce
<?php // only copy this line if needed
/**
* Function adds a BCC header to emails that match our array
*
* @param string $headers The default headers being used
* @param string $object The email type/object that is being processed
*/
function add_bcc_to_certain_emails( $headers, $object ) {