Skip to content

Instantly share code, notes, and snippets.

Avatar

Wil Brown DeveloperWil

View GitHub Profile
@DeveloperWil
DeveloperWil / wordpress-remove-all-comments-support.php
Created Feb 2, 2021
WordPress: Remove All Comments Support
View wordpress-remove-all-comments-support.php
/**
* 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.php
Last active Jan 18, 2021
WooCommerce: Disable out-of-stock product variations from showing in the drop-down front-end UI add "Sold Out" label
View woocommerce-disable-out-of-stock-variations.php
/**
* Disable out-of-stock variations
*
* Make sure you check "Manage Stock" on each variation.
* Set the stock level to zero and in the front-end drop-down variations list
* the variation will be greyed-out on the product drop-down
*
* @author Wil Brown zeropointdevelopment.com
* @param $active
* @param $variation
@DeveloperWil
DeveloperWil / woocommerce-custom-order-number-based-on-billing-initials-and-random-number.php
Last active Dec 7, 2020
WooCommerce: Custom Order Number Based On Billing Customers Initials And Random Number between 10,000 and 99,999
View woocommerce-custom-order-number-based-on-billing-initials-and-random-number.php
/**
* 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
Created Dec 4, 2020
WooCommerce: Change Add To Cart Button Text and URL
View woocommerce-change-add-to-cart-button-text-and-url.php
/**
* 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 );
}
add_action('init','zpd_remove_wc_loop_add_to_cart_button');
@DeveloperWil
DeveloperWil / woocommerce-display-product-reviews-shortcode.php
Created Dec 4, 2020
WooCommerce: Display Product Reviews Shortcode
View woocommerce-display-product-reviews-shortcode.php
/**
* 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 Nov 16, 2020
WooCommerce: Return an array of featured product IDs
View woocommerce-return-array-of-featured-product-ids
@DeveloperWil
DeveloperWil / woocommerce-rename-product-tabs
Created Nov 16, 2020
WooCommerce: Rename Product Tabs
View 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;
@DeveloperWil
DeveloperWil / woocommerce-display-product-already-in-cart
Created Nov 16, 2020
WooCommerce: Display "Already in cart - add again?" for Add to Cart button
View woocommerce-display-product-already-in-cart
/**
* Change "Add to cart" button text on single product page
*
* @author Wil Brown zeropointdevelopment.com
* @return string|void
*/
function zpd_wc_add_to_cart_again_button() {
global $woocommerce;
@DeveloperWil
DeveloperWil / woocommerce-change-out-of-stock-to-sold
Created Nov 16, 2020
WooCommerce: Change "Out of stock" message to "Sold"
View woocommerce-change-out-of-stock-to-sold
/**
* Change "Out of stock" with "Sold"
*
* @author Wil Brown zeropointdevelopment.com
* @param $availability
* @return mixed
*/
function zpd_availability_filter_func($availability)
{
$availability['availability'] = str_ireplace( 'Out of stock', 'Sold', $availability['availability'] );
@DeveloperWil
DeveloperWil / woocommerce-add-custom-currency-label-description-and-symbol
Created Nov 16, 2020
WooCommerce: Add A Custom Currency Label, Description and Symbol
View woocommerce-add-custom-currency-label-description-and-symbol
/**
* Add custom currency label to WooCommerce
*
* @author Wil Brown zeropointdevelopment.com
* @param $currencies
* @return mixed
*/
function zpd_add_wc_currency( $currencies ) {
$currencies['BANANA'] = __( 'Banana', 'woocommerce' );