Skip to content

Instantly share code, notes, and snippets.

View DeveloperWil's full-sized avatar

Wil Brown DeveloperWil

View GitHub Profile
@DeveloperWil
DeveloperWil / woocommerce-set-minimum-checkout-order-amount.php
Created March 9, 2021 00:30
WooCommerce: Set a minimum amount at checkout
/**
* Set a minimum amount for checkout
*/
function zpd_wc_minimum_order_amount(): void {
/**
* $minimum is the minimum value you want to set the checkout total order amount.
*/
$minimum = 50;
/**
@DeveloperWil
DeveloperWil / woocommerce-change-shop-page-order-by
Last active March 8, 2021 23:48
WooCommerce: Set default order on shop page to by price, title or date
/**
* Change the default shop page 'catalogue' order of how products are displayed
*
* You can use the following parameters:
* 'menu_order' – by the custom order first, then by product name (Default)
* 'popularity' – by the number of sales
* 'rating' – by the average rating
* 'date' – recently added products will be displayed first
* 'price' – cheapest products will be displayed first
* 'price-desc' – the most expensive first
@DeveloperWil
DeveloperWil / woocommerce-add-extra-email-recipient-completed-order
Created March 8, 2021 22:48
WooCommerce: Add an extra email recipient to the email sent when an order has been completed
/**
* Add extra emails to the WC email sent when an order has been completed.
*
* Make sure you separate multiple emails with a comma.
*
* @param $recipient
* @param $object
* @return string
*/
function zpd_wc_extra_email_recipient( $recipient, $object ): string {
@DeveloperWil
DeveloperWil / wordpress-remove-all-comments-support.php
Created February 2, 2021 03:01
WordPress: Remove All Comments Support
/**
* Removes commenting from WordPress
*
* Redirects edit comment URL to admin URL
* Removes comment meta box
* Removes comments and trackback support for all post types
*/
function zpd_remove_commenting () {
// Redirect any user trying to access comments page
global $pagenow;
@DeveloperWil
DeveloperWil / woocommerce-disable-out-of-stock-variations.js
Last active November 27, 2021 03:46
WooCommerce: Disable out-of-stock product variations from showing in the drop-down front-end UI add "Sold Out" label
/**
* Finds product varant option dropdown with " - sold out" and adds a "sold-out" class to the option.
* You can add the following CSS to grey-out the sold out option
* option.sold-out{ color:lightgray;}
*/
jQuery(window).load(function(){
jQuery('body.single-product .product.type-product table.variations td.value select option').each(function( index ){
var optionText = jQuery(this).text();
if( optionText.indexOf(" - sold out") >= 0 ){
jQuery(this).addClass( 'sold-out' );
@DeveloperWil
DeveloperWil / woocommerce-custom-order-number-based-on-billing-initials-and-random-number.php
Last active November 20, 2021 06:33
WooCommerce: Custom Order Number Based On Billing Customers Initials And Random Number between 10,000 and 99,999
/**
* Generate an order ID based on the billing customers initials and a random number between 10000 and 99999
*
* @author Wil Brown zeropointdevelopment.com
* @param $order_id
*
* @return string
* @throws Exception
*/
function zpd_change_woocommerce_order_number( $order_id ) {
@DeveloperWil
DeveloperWil / woocommerce-change-add-to-cart-button-text-and-url.php
Last active January 11, 2024 08:47
WooCommerce: Change Add To Cart Button Text and URL
/**
* Removes the default Add To Cart button from the WooCommerce loop
* This will affect all products site-wide
*
* @author Wil Brown zeropointdevelopment.com
*/
function zpd_remove_wc_loop_add_to_cart_button(){
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
}
@DeveloperWil
DeveloperWil / woocommerce-display-product-reviews-shortcode.php
Created December 4, 2020 01:55
WooCommerce: Display Product Reviews Shortcode
/**
* Use a shortcode to display product reviews.
* Format: [product_reviews id="123"]
* id = the product ID - you can get this from Products > All Products and hovering over the product title
*
* If there are no reviews for a product, nothing is returned to the browser.
*
* @author Wil Brown zeropointdevelopment.com
* @param $atts
*
@DeveloperWil
DeveloperWil / woocommerce-return-array-of-featured-product-ids
Last active November 16, 2020 04:27
WooCommerce: Return an array of featured product IDs
@DeveloperWil
DeveloperWil / woocommerce-rename-product-tabs
Created November 16, 2020 04:07
WooCommerce: Rename Product Tabs
/**
* Rename the default WooCommerce product tabs
*
* @author Wil Brown zeropointdevelopment.com
* @param $tabs
* @return mixed
*/
function zpd_wc_rename_product_tabs($tabs) {
global $post;