Skip to content

Instantly share code, notes, and snippets.

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

Caleb Burks WPprodigy

🖥️
🍕🍕🍕
View GitHub Profile
@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 / 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 / external-product-embed-snippets.php
Last active December 28, 2020 22:00
Short snippets to edit the product data retrieved by the shortcodes.
<?php
/**
* Change the default shortcode button text for both shortcodes
*/
add_filter( 'wcepe_external_product_shortcode', 'wcepe_change_default_button_text' );
add_filter( 'wcepe_recent_external_products_shortcode', 'wcepe_change_default_button_text' );
function wcepe_change_default_button_text( $atts ) {
@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 / tracking-code-at-checkout.php
Last active August 19, 2020 20:00
Add analytics tracking to the WooCommerce order received / thank-you page
/**
* Add Tracking Code to the Order Recieved Page
*/
function wc_ninja_checkout_analytics( $order_id ) {
$order = new WC_Order( $order_id );
$currency = $order->get_order_currency();
$total = $order->get_total();
$date = $order->order_date;
?>
<!-- Paste Tracking Code Under Here -->
@WPprodigy
WPprodigy / wc-ninja-manipulate-shipping-rates.php
Created October 26, 2015 09:26
Example code for manipulating shipping rates in WooCommerce
function wc_ninja_manipulate_shipping( $rates, $package ) {
// All available rates and their costs
//print_r($rates);
// All products in the cart and their costs
//print_r($package);
// Example of manipulating the cost of
// a shipping method based on the above variables.
if ( isset( $rates['flat_rate'] ) ) {
@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
<?php
/**
* Plugin Name: Conditional WooCommerce Checkout Fields
* Description: Adds the abilitiy to conditionally show / hide checkout fields.
* Version: 1.0
* Author: Caleb Burks
* Author URI: http://calebburks.com
*/
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>';
}