Skip to content

Instantly share code, notes, and snippets.

@ajmorris
ajmorris / functions.php
Created March 28, 2018 18:40
WooCommerce - Adds stock status to the dropdown on product pages
<?php
add_action( 'woocommerce_after_add_to_cart_form', 'dropdown_waitlist_label' );
function dropdown_waitlist_label() {
echo "
<script>
jQuery(document).ready(function($) {
var variation_data = $('form.variations_form').attr('data-product_variations');
var variation_data = JSON.parse(variation_data);
$('#pa_size > option').each(function() {
for (var i = 0; i < variation_data.length; i++) {
@ajmorris
ajmorris / functions.php
Last active August 6, 2018 18:08
making the description display for menu items with description filled out
<?php
// Adds the descriptions to menu output
function prefix_nav_description( $item_output, $item, $depth, $args ) {
if ( !empty( $item->description ) ) {
$item_output = str_replace( $args->link_after . '</a>', '<p class="menu-item-description">' . $item->description . '</p>' . $args->link_after . '</a>', $item_output );
}
return $item_output;
}
@ajmorris
ajmorris / functions.php
Created December 7, 2017 03:41
Remove checkout fields from WooCommerce Checkou
<?php
function wc_ninja_remove_checkout_field( $fields ) {
unset( $fields['billing']['billing_company'] );
return $fields;
}
add_filter( 'woocommerce_checkout_fields' , 'wc_ninja_remove_checkout_field' );
// list of fields can be found here, https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/
@ajmorris
ajmorris / functions.php
Created April 18, 2018 17:54 — forked from mikejolley/functions.php
WooCommerce - Notify admin when a new customer account is created
<?php // Do not include this if already open!
/**
* Code goes in theme functions.php.
*/
add_action( 'woocommerce_created_customer', 'woocommerce_created_customer_admin_notification' );
function woocommerce_created_customer_admin_notification( $customer_id ) {
wp_send_new_user_notifications( $customer_id, 'admin' );
}
@ajmorris
ajmorris / dropdown-stock-status.php
Created April 18, 2018 17:49 — forked from lawkwok/dropdown-stock-status.php
WooCommerce - Adds stock status to the dropdown on product pages
<?php
add_action( 'woocommerce_after_add_to_cart_form', 'dropdown_waitlist_label' );
function dropdown_waitlist_label() {
echo "
<script>
jQuery(document).ready(function($) {
var variation_data = $('form.variations_form').attr('data-product_variations');
var variation_data = JSON.parse(variation_data);
@ajmorris
ajmorris / functions.php
Created April 18, 2018 17:33 — forked from claudiosanches/functions.php
WooCommerce - Change ajax variation threshold
function custom_wc_ajax_variation_threshold( $qty, $product ) {
return 10;
}
add_filter( 'woocommerce_ajax_variation_threshold', 'custom_wc_ajax_variation_threshold', 10, 2 );
@ajmorris
ajmorris / functions.php
Created March 28, 2018 18:45
Notify admin when a new customer account is created - WooCommerce
<?php // Do not include this if already open!
/**
* Code goes in theme functions.php.
*/
add_action( 'woocommerce_created_customer', 'woocommerce_created_customer_admin_notification' );
function woocommerce_created_customer_admin_notification( $customer_id ) {
wp_send_new_user_notifications( $customer_id, 'admin' );
@ajmorris
ajmorris / functions.php
Created March 28, 2018 18:30
Add this to create a Facebook and Twitter URL fields to both the WP-Admin and the customer checkout form in WooCommerce.
/**
* Register term fields
*/
add_action( 'init', 'register_vendor_custom_fields' );
function register_vendor_custom_fields() {
add_action( WC_PRODUCT_VENDORS_TAXONOMY . '_add_form_fields', 'add_vendor_custom_fields' );
add_action( WC_PRODUCT_VENDORS_TAXONOMY . '_edit_form_fields', 'edit_vendor_custom_fields', 10 );
add_action( 'edited_' . WC_PRODUCT_VENDORS_TAXONOMY, 'save_vendor_custom_fields' );
add_action( 'created_' . WC_PRODUCT_VENDORS_TAXONOMY, 'save_vendor_custom_fields' );
}
@ajmorris
ajmorris / functions.php
Created March 28, 2018 18:13
WooCommerce - Change ajax variation threshold
function custom_wc_ajax_variation_threshold( $qty, $product ) {
return 10;
}
add_filter( 'woocommerce_ajax_variation_threshold', 'custom_wc_ajax_variation_threshold', 10, 2 );
@ajmorris
ajmorris / custom-woo-acf-tabs.php
Created March 28, 2018 18:05
Create custom product details tabs within WooCommerce using an ACF (Advanced Custom Fields) Repeater field.
<?php
function hwid_load_custom_tab( $tab_key, $tab_info ) {
echo apply_filters( 'the_content', $tab_info['tabContent'] );
}
function hwid_add_content_tabs( $tabs ) {
global $post;
$custom_tabs = get_field( 'tabs', $post->ID );
foreach( $custom_tabs as $index => $tab ) {
$tabs['customTab-' . $index] = array(
'title' => $tab['tab_title'],