Skip to content

Instantly share code, notes, and snippets.

View jrick1229's full-sized avatar
☠️

Joey Ricketts jrick1229

☠️
  • VA
  • 19:03 (UTC -04:00)
View GitHub Profile
@jrick1229
jrick1229 / wc-hide-products-from-shop-search-widgets.php
Last active July 26, 2021 21:04
Use these snippets to hide a category of products from the shop page, search results, and product widgets. You'll also want to set your product visibility settings for each of these products to: "Shop only"
<?php
/* sourced from several StackOverflow posts */
/*
* YOU MUST CHANGE REFERENCES TO "corporate" TO YOUR
* OWN CATEGORY SLUG, ELSE THIS WILL BE USELESS (lines 16 & 28)
*/
function custom_pre_get_posts_query( $q ) {
@jrick1229
jrick1229 / wc_add_user_role_admin_order_details.php
Last active June 18, 2021 16:38
Add the user role to the 'General' section of the admin order details page
<?php
add_action( 'woocommerce_admin_order_data_after_order_details', 'wc_add_user_role_admin_order_details' );
function wc_add_user_role_admin_order_details( $order ){ ?>
<br class="clear" />
<?php
$user_id = $order->get_user_id();
$user_meta = get_userdata($user_id);
$roles = $user_meta->roles;
@jrick1229
jrick1229 / wc_hide_price_string_0.php
Created May 18, 2021 15:09
Hide the price string on the product/catalog pages if the price is === $0
<?php
/**
* Hide the price string if set to $0
*/
add_filter( 'woocommerce_get_price_html', 'wc_hide_price_string_0', 9999, 2 );
function wc_hide_price_string_0( $price, $product ){
if ( '' === $product->get_price() || 0 == $product->get_price() ) {
return;
@jrick1229
jrick1229 / pao-hide-none-radio.css
Created April 28, 2021 17:50
Hide the first 'None' option when using a non-required radio button layout in Product Add-Ons
div.wc-pao-addon-container.wc-pao-addon > p:nth-child(3) { display: none!important; }
@jrick1229
jrick1229 / wc_minimum_order_amount_surcharge.php
Last active July 21, 2021 18:46
If the cart subtotal is less than $0.99, add a surcharge of ($1 - WC()->cart->subtotal) - so that the total is always at least $1. DOES NOT CURRENTLY WORK WHEN TAXES ARE ENABLED.
<?php
add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount_surcharge' );
add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount_surcharge' );
add_action( 'woocommerce_cart_calculate_fees','wc_minimum_order_amount_surcharge' );
function wc_minimum_order_amount_surcharge() {
global $woocommerce;
// Set this variable to specify a minimum order value
$minimumTotal = .99;
@jrick1229
jrick1229 / wc_remove_shipping_billing_state.php
Created April 15, 2021 14:41
Remove the state field from both shipping and billing details section
<?php
add_filter( 'woocommerce_billing_fields', 'wc_remove_shipping_billing_state' );
add_filter( 'woocommerce_shipping_fields', 'wc_remove_shipping_billing_state' );
function wc_remove_shipping_billing_state( $fields ) {
unset( $fields[ 'billing_state' ] );
unset( $fields[ 'shipping_state' ] );
return $fields;
}
@jrick1229
jrick1229 / wc_backordered_notice.php
Created April 3, 2021 15:02
Display a notice on the product and cart page when a product is backordered.
<?php
add_filter('woocommerce_product_backorders_require_notification', '__return_true', 1);
@jrick1229
jrick1229 / PAO_remove_percentage.php
Created March 31, 2021 16:20
Remove % from Product Add-Ons percentage based add-on
<?php
add_filter( 'woocommerce_product_addons_option_price', 'PAO_remove_percentage', 1);
function PAO_remove_percentage() {
$price_raw = '( . $price_prefix . $price_raw )';
}
@jrick1229
jrick1229 / wc_price_add_USD.php
Created February 25, 2021 16:55
Append USD to price string in WooCommerce
<?php
add_filter( 'wc_price', 'wc_price_add_USD', 10, 3 );
function wc_price_add_USD( $return, $price, $args){
$price= "$" . $price . " USD";
return $price;
}
@jrick1229
jrick1229 / wc_disable_persistent_cart.php
Created February 5, 2021 17:40
Disable persistent cart
<?php
add_filter('woocommerce_persistent_cart_enabled', function () {
return false;
});