Skip to content

Instantly share code, notes, and snippets.

View lukecav's full-sized avatar
🙏
Please watch out for each other

Luke Cavanagh lukecav

🙏
Please watch out for each other
View GitHub Profile
/**
* 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' );
}
@lukecav
lukecav / functions.php
Created August 29, 2016 21:34 — forked from woogist/functions.php
Redirect to a custom page after login based on the user role
<?php
/**
* Redirect users to custom URL based on their role after login
*
* @param string $redirect
* @param object $user
* @return string
*/
function wc_custom_user_redirect( $redirect, $user ) {
// Get the first of all the roles assigned to the user
@lukecav
lukecav / wc-ac.php
Created September 19, 2016 22:32 — forked from bryceadams/wc-ac.php
<?php
/**
* Autocomplete Paid Orders (WC 2.2+)
*/
add_filter( 'woocommerce_payment_complete_order_status', 'bryce_wc_autocomplete_paid_paypal_orders' );
function bryce_wc_autocomplete_paid_paypal_orders( $order_status, $order_id ) {
$order = wc_get_order( $order_id );
if ( $order->payment_method == 'paypal' ) {
if ( $order_status == 'processing' && ( $order->status == 'on-hold' || $order->status == 'pending' || $order->status == 'failed' ) ) {
jQuery('.ninja-forms-form').on('submitResponse', function(e, response) {
var $popup = jQuery('#pum-123'),
errors = response.errors;
if (errors === false) {
$popup.popmake('open');
}
});
@lukecav
lukecav / use-popup-for-edd-terms-link.php
Created September 22, 2016 21:56 — forked from danieliser/use-popup-for-edd-terms-link.php
Replace the Easy Digital Downloads Show Terms slide down with a Popup Maker popup.
@lukecav
lukecav / author.php
Created September 27, 2016 16:56 — forked from portfola/author.php
Custom User Taxonomies in WordPress
<?php
/**
* The template for displaying Profile pages.
*
* Used for Artist and Cultural Org "mini" pages.
*
* @package ArtsWestchester
* @since ArtsWestchester 1.0
*/
@lukecav
lukecav / file.php
Created September 27, 2016 17:54 — forked from khromov/file.php
Advanced Custom Fields get_field() sanitization
<?php
/**
* Helper function to get sanitized field
* and also normalize values.
*
* @param $field_key
* @param bool $post_id
* @param bool $format_value
* @param string $sanitization_method esc_html / esc_attr or NULL for none
* @return array|bool|string
@lukecav
lukecav / woocommerce-optimize-scripts.php
Created September 28, 2016 18:08 — forked from DevinWalker/woocommerce-optimize-scripts.php
Only load WooCommerce scripts on shop pages and checkout + cart
/**
* Optimize WooCommerce Scripts
* Remove WooCommerce Generator tag, styles, and scripts from non WooCommerce pages.
*/
add_action( 'wp_enqueue_scripts', 'child_manage_woocommerce_styles', 99 );
function child_manage_woocommerce_styles() {
//remove generator meta tag
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
@lukecav
lukecav / functions.php
Created September 28, 2016 20:41 — forked from eduwass/functions.php
Hide WooCommerce subscriptions text (in product and cart pages) from products with a set Price but no Subscription Fee
// Define which products we should hide the subscription text for
function should_hide_subscription_text($product){
$is_subscription = (get_class($product) == 'WC_Product_Variable_Subscription');
$has_price = (intval($product->subscription_price)>0);
$has_fee = (intval($product->subscription_sign_up_fee)>0);
if($is_subscription && $has_price && !$has_fee){
return true;
} else {
return false;
}
@lukecav
lukecav / wc-shop-loop-columns.php
Created October 4, 2016 20:03 — forked from coenjacobs/wc-shop-loop-columns.php
Change the number of columns in which products will be shown on product archives
<?php
add_filter( 'loop_shop_columns', 'wc_loop_shop_columns', 1, 10 );
/*
* Return a new number of maximum columns for shop archives
* @param int Original value
* @return int New number of columns
*/
function wc_loop_shop_columns( $number_columns ) {