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
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 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 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
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 13, 2017 22:20
Use unit pricing in WooCommerce
add_action( 'woocommerce_get_price_html', 'wc_ninja_customize_price_html', 2, 10 );
function wc_ninja_customize_price_html( $price, $product ) {
// Enter your product's ID here
$product_id = 87;
if ( $product_id == $product->id ) {
$price .= ' ($2.00 per piece)';
}
return $price;
@WPprodigy
WPprodigy / functions.php
Created January 17, 2017 17:14
Unhook cart addons from the cart page in WooCommerce
add_action( 'woocommerce_after_cart_table', 'wc_ninja_remove_cart_addons', 10 );
function wc_ninja_remove_cart_addons() {
global $sfn_cart_addons;
remove_action( 'woocommerce_after_cart_table', array( $sfn_cart_addons, 'cart_display_addons' ), 20 );
}
@WPprodigy
WPprodigy / functions.php
Last active June 23, 2017 04:25
Rename the flat rate shipping label when the cost is $0
// Rename the flat rate shipping label when the cost is $0
function wc_ninja_change_flat_rate_label( $label, $method ) {
if ( 'flat_rate' == $method->method_id && $method->cost <= 0 ) {
$label = "Free Shipping";
}
return $label;
}
add_filter( 'woocommerce_cart_shipping_method_full_label', 'wc_ninja_change_flat_rate_label', 10, 2 );
@WPprodigy
WPprodigy / index.js
Last active January 23, 2017 07:27
Find out how long you have spent watching videos at https://es6.io
const watched = document.querySelectorAll( '.video.completed' );
let totalSeconds = 0;
// Loop over each video watched.
watched.forEach( video => {
let videoTime = video.querySelector( 'span.duration' ).textContent.split( ':' );
// Turn minutes:seconds into just seconds and append to totalSeconds.
videoTime.map( array => {
totalSeconds += ( parseInt( array[0] ) * 60 ) + parseInt( array[1] );
@WPprodigy
WPprodigy / functions.php
Created January 25, 2017 23:52
Add an extra button on single product pages in WooCommerce
add_action( 'woocommerce_after_add_to_cart_button', 'wc_ninja_add_extra_button', 20 );
function wc_ninja_add_extra_button() {
echo "<a href='#' class='button'>Return to shop</a>";
}
@WPprodigy
WPprodigy / functions.php
Created January 26, 2017 23:42
Add billing phone and email to PIP invoice
function wc_ninja_add_to_billing_address( $formatted_billing_address, $type, $order ) {
if ( $order->billing_phone ) {
$formatted_billing_address .= "<br>" . $order->billing_phone;
}
if ( $order->billing_email ) {
$formatted_billing_address .= "<br>" . $order->billing_email;
}
return $formatted_billing_address;