Skip to content

Instantly share code, notes, and snippets.

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

Caleb Burks WPprodigy

🖥️
🍕🍕🍕
View GitHub Profile
@WPprodigy
WPprodigy / example-product-fees-prefix.php
Last active August 27, 2015 10:54
An example plugin showing how WooCommerce Product Fees can be extended
<?php
/**
* Plugin Name: WooCommerce Product Fees Prefix Addition
* Description: Add a prefix to the additional fees that is shown at checkout in front of the fee name.
* Version: 1.0
* Author: Caleb Burks
* Author URI: http://calebburks.com
*/
// Exit if accessed directly
@WPprodigy
WPprodigy / gist:a2638976d6ad3c50635b
Created June 17, 2015 17:47
Make all WooCommerce products appear to be purchasable
add_filter('woocommerce_is_purchasable', '__return_true');
@WPprodigy
WPprodigy / gist:c24e88cd3904ad9ef41c
Created June 19, 2015 05:25
Remove '(Free)' or '(FREE!)' label text on cart page for Shipping and Handling if cost equal to $0
// Remove '(Free)' or '(FREE!)' label text on cart page for Shipping and Handling if cost equal to $0
function woo_ninja_custom_shipping_free_label( $label ) {
$label = str_replace( "(Free)", "New Text Here", $label );
$label = str_replace( "(FREE!)", "New Text Here", $label );
return $label;
}
add_filter( 'woocommerce_cart_shipping_method_full_label' , 'woo_ninja_custom_shipping_free_label' );
@WPprodigy
WPprodigy / external-product-embed-extensibility.php
Created August 29, 2015 14:59
Example of how you can add a settings fields, and retrieve the value in the shortcode template.
<?php
/**
* Add Product Settings Section to the Admin
*/
add_action( 'wcepe_after_transients_settings', 'wcepe_custom_settings_section' );
function wcepe_custom_settings_section() {
// Transient Section
@WPprodigy
WPprodigy / wc-ninja-free-shipping-for-a-user-role.php
Created October 27, 2015 08:01
Conditionally toggle Free Shipping based on the user's role and contents of the cart
function wc_ninja_free_shipping_for_a_user_role( $rates, $package ) {
// Only modify rates if free_shipping is present
if ( isset( $rates['free_shipping'] ) ) {
// Add a user role specific capability here
if ( ! current_user_can( 'manage_woocommerce' ) ) {
// Cart Subtotal
$subtotal = WC()->cart->subtotal;
// Number of products in the cart
add_action( 'woocommerce_after_shop_loop_item_title', 'wc_ninja_add_short_desc', 15 );
function wc_ninja_add_short_desc() {
global $post;
echo '<p>' . $post->post_excerpt . '</p>';
}
@WPprodigy
WPprodigy / example.php
Last active November 25, 2015 18:12
Show products from a category conditionally on the cart page
<?php
function get_products_in_cart2() {
$cart_ids = array();
foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
$cart_product = $values['data'];
$cart_ids[] = $cart_product->id;
}
return $cart_ids;
}
@WPprodigy
WPprodigy / functions.php
Created January 19, 2016 17:14
Add subtitle field to Storefront
<?php
// Display subtitle after the header for posts and pages
add_action( 'storefront_single_post', 'storefront_add_subtitle_after_header', 15 );
add_action( 'storefront_page', 'storefront_add_subtitle_after_header', 15 );
function storefront_add_subtitle_after_header() {
the_subtitle( "<h2 class='subtitle'>", "</h2>" );
}
// Display subtitle in the header for posts
@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 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;
}