Skip to content

Instantly share code, notes, and snippets.

View WPprodigy's full-sized avatar
🖥️
🍕🍕🍕

Caleb Burks WPprodigy

🖥️
🍕🍕🍕
View GitHub Profile
@WPprodigy
WPprodigy / functions.php
Last active June 23, 2017 04:25
WooCommerce: Add notices to the cart/checkout page when specific categories are together in the cart.
// Hook in to add notices to the cart and checkout pages
add_action( 'woocommerce_before_cart_contents', 'wc_ninja_add_cart_notice' );
add_action( 'woocommerce_before_checkout_form', 'wc_ninja_add_cart_notice' );
/**
* Add the cart/checkout notice
*/
function wc_ninja_add_cart_notice() {
$message = "Sorry, you cannot purchase products from the clothing and music category together.";
@WPprodigy
WPprodigy / functions.php
Created January 11, 2017 10:54
Chain a coupon in WooCommerce
add_action( 'woocommerce_applied_coupon', 'wc_ninja_chain_a_coupon' );
function wc_ninja_chain_a_coupon( $coupon_code ) {
$first_coupon = 'coupon-code-1';
$chained_coupon = 'coupon-code-2';
if ( $first_coupon == $coupon_code ) {
WC()->cart->add_discount( $chained_coupon );
}
}
@WPprodigy
WPprodigy / functions.php
Created January 5, 2017 04:56
Add author and publish date to storefront pages underneath the title
add_action( 'storefront_page', 'wc_ninja_add_pages_byline', 11 );
function wc_ninja_add_pages_byline() {
?>
<div class="author">
<?php
echo '<span class="label">' . esc_attr( __( 'Written by', 'storefront' ) ) . ' </span>';
the_author_posts_link();
echo "<br>";
storefront_posted_on();
?>
@WPprodigy
WPprodigy / functions.php
Created January 2, 2017 23:03
Remove order delivery area and add it back in at an earlier priority
add_action( 'wp', 'wc_ninja_test' );
function wc_ninja_test() {
$main_instance = WC_OD();
$checkout_class = $main_instance->checkout();
remove_action( 'woocommerce_checkout_shipping', array( $checkout_class, 'checkout_content' ), 99 );
add_action( 'woocommerce_checkout_shipping', array( $checkout_class, 'checkout_content' ), 15 );
}
@WPprodigy
WPprodigy / functions.php
Created December 15, 2016 11:22
Require bundled product input if it only contains optional products.
add_filter( 'woocommerce_bundle_requires_input', 'wc_ninja_require_bundle_input', 10, 2 );
function wc_ninja_require_bundle_input( $requires_input, $product ) {
if ( ! $product->contains( 'mandatory' ) && $product->contains( 'optional' ) ) {
$requires_input = true;
}
return $requires_input;
}
@WPprodigy
WPprodigy / functions.php
Created November 16, 2016 22:11
Filter products by visibility
add_action( 'restrict_manage_posts', 'wc_ninja_create_filter_dropdown' );
function wc_ninja_create_filter_dropdown(){
$type = 'product';
if ( isset( $_GET['post_type'] ) ) {
$type = $_GET['post_type'];
}
if ( 'product' == $type ){
$values = array(
'Catalog &amp; search' => 'visible',
@WPprodigy
WPprodigy / functions.php
Created November 5, 2016 16:07
Replace author url in WordPress with their twitter link based on their username in twitter.
add_filter( 'the_author_posts_link', 'wc_ninja_change_author_url' );
function wc_ninja_change_author_url($link) {
$username = get_the_author_meta('login');
return "<a href='http://twitter.com/" . $username . "'>" . get_the_author() . "</a>";
}
@WPprodigy
WPprodigy / functions.php
Created April 12, 2016 23:36
Make product brands sortable
add_filter( 'woocommerce_sortable_taxonomies','wt_sort_brands' );
function wt_sort_brands( $sortable ) {
$sortable[] = 'product_brand';
return $sortable;
}
@WPprodigy
WPprodigy / functions.php
Created April 12, 2016 23:12
Show brand image around the product short description.
add_action( 'woocommerce_single_product_summary', 'wc_ninja_add_brand_to_product_page', 19 );
function wc_ninja_add_brand_to_product_page() {
echo do_shortcode('[product_brand width="64px" height="64px" class="alignright"]');
}
@WPprodigy
WPprodigy / functions.php
Created March 31, 2016 21:36
Hide a shipping method based on a use role
function wc_ninja_role_base_shipping_method( $rates, $package ) {
// Make sure flat rate is available
if ( isset( $rates['flat_rate'] ) && ! current_user_can( 'wholesale' ) ) {
unset($rates['flat_rate']);
}
return $rates;
}
add_filter( 'woocommerce_package_rates', 'wc_ninja_role_base_shipping_method', 10, 2 );