Skip to content

Instantly share code, notes, and snippets.

@brianleejackson
brianleejackson / scroll-sticky-widget-no-jquery.css
Last active October 16, 2020 14:28
Scroll sticky sidebar WordPress widget with no jQuery
@media (min-width: 769px) {
.site-content {
display: flex;
}
.inside-right-sidebar {
height: 100%;
}
.inside-right-sidebar aside:last-child {
position: -webkit-sticky;
position: sticky;
@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 {
@jamesdixon
jamesdixon / custom-fonts.php
Created March 9, 2015 21:54
Wordpress Allow Custom Font Upload
<?php
// add to your theme's functions.php file
add_filter('upload_mimes', 'add_custom_upload_mimes');
function add_custom_upload_mimes($existing_mimes) {
$existing_mimes['otf'] = 'application/x-font-otf';
$existing_mimes['woff'] = 'application/x-font-woff';
$existing_mimes['ttf'] = 'application/x-font-ttf';
$existing_mimes['svg'] = 'image/svg+xml';
$existing_mimes['eot'] = 'application/vnd.ms-fontobject';
return $existing_mimes;
@JeroenSormani
JeroenSormani / woocommerce-custom-no-shipping-available-message.php
Last active July 4, 2021 08:44
Add a custom 'No shipping methods available' message
<?php
add_filter( 'woocommerce_no_shipping_available_html', 'my_custom_no_shipping_message' );
add_filter( 'woocommerce_cart_no_shipping_available_html', 'my_custom_no_shipping_message' );
function my_custom_no_shipping_message( $message ) {
return __( 'A minimum of 6 products is required. Add more products to complete your purchase' );
}
@woogists
woogists / wc-override-loop-show-cart-buttons.php
Last active July 9, 2021 09:53
[Frontend Snippets] Override loop template and show quantities next to add to cart buttons.
/**
* Override loop template and show quantities next to add to cart buttons
*/
add_filter( 'woocommerce_loop_add_to_cart_link', 'quantity_inputs_for_woocommerce_loop_add_to_cart_link', 10, 2 );
function quantity_inputs_for_woocommerce_loop_add_to_cart_link( $html, $product ) {
if ( $product && $product->is_type( 'simple' ) && $product->is_purchasable() && $product->is_in_stock() && ! $product->is_sold_individually() ) {
$html = '<form action="' . esc_url( $product->add_to_cart_url() ) . '" class="cart" method="post" enctype="multipart/form-data">';
$html .= woocommerce_quantity_input( array(), $product, false );
$html .= '<button type="submit" class="button alt">' . esc_html( $product->add_to_cart_text() ) . '</button>';
$html .= '</form>';
@Balakrishnan-flycart
Balakrishnan-flycart / Woo Discount Rules v2 - Hide shipping when discount rules free shipping is available
Created July 12, 2021 09:59
Woo Discount Rules v2 - Hide shipping when discount rules free shipping is available
/**
* Hide shipping rates when discount rules free shipping is available.
* Updated to support WooCommerce 2.6 Shipping Zones.
*
* @param array $rates Array of rates found for the package.
* @return array
*/
function my_hide_shipping_when_free_is_available( $rates ) {
$free = array();
foreach ( $rates as $rate_id => $rate ) {
/*
* Function for post duplication. Dups appear as drafts. User is redirected to the edit screen
*/
function rd_duplicate_post_as_draft(){
global $wpdb;
if (! ( isset( $_GET['post']) || isset( $_POST['post']) || ( isset($_REQUEST['action']) && 'rd_duplicate_post_as_draft' == $_REQUEST['action'] ) ) ) {
wp_die('No post to duplicate has been supplied!');
}
/*
@blogjunkie
blogjunkie / functions.php
Last active November 24, 2021 09:52
Add 'Awaiting pre-order' custom status to WooCommerce with bulk edit and custom status color
<?php // Don't copy this line
/**
* Add 'Awaiting pre-order' custom status
*
* 1. Register new order status
* 2. Add to list of WC order statuses
* 3. Add your custom bulk action in dropdown
* 4. Bulk action handler
* 5. Admin notices for bulk action
add_filter( 'body_class', 'add_password_protected_body_class' );
function add_password_protected_body_class( $classes ) {
if ( post_password_required() )
$classes[] = 'password-protected';
return $classes;
}
@woogists
woogists / wc-unhook-remove-emails.php
Last active March 22, 2022 19:09
[General Snippets] Unhook and remove WooCommerce default emails.
/**
* Unhook and remove WooCommerce default emails.
*/
add_action( 'woocommerce_email', 'unhook_those_pesky_emails' );
function unhook_those_pesky_emails( $email_class ) {
/**
* Hooks for sending emails during store events
**/