Skip to content

Instantly share code, notes, and snippets.

View MadCowWeb's full-sized avatar

Jason Robie MadCowWeb

View GitHub Profile
@MadCowWeb
MadCowWeb / Create Shortcodes in WordPress
Last active April 17, 2024 15:46
Create Shortcodes in WordPress
add_action('init', 'madcowweb_shortcodes');
function madcowweb_shortcodes() {
add_shortcode('show-cows', 'show_cows');
}
//SIMPLE TEXT
function show_cows() {
$html = '<h1>I love cows</h1>';
return $html;
}
@MadCowWeb
MadCowWeb / relocate content on Woo Product Page
Created April 5, 2024 17:17
Relocating content on a WooCommerce Single Product Page
// move category above product title
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40);
add_action('woocommerce_single_product_summary', 'woocommerce_template_single_meta', 4);
@MadCowWeb
MadCowWeb / WooCommerce Custom Tabs
Created April 5, 2024 16:54
Add a custom tab to the WooCommerce Single Product Page
//ADD NEATO TEXT CUSTOM TAB
add_filter('woocommerce_product_tabs', 'madcow_neato_text_tab');
function madcow_neato_text_tab($tabs) {
$tabs['neato_text_tab'] = array(
'title' => __('Our Neato Text', 'woocommerce'),
'priority' => 5,
'callback' => 'madcow_neato_text_tab_content',
);
return $tabs;
}
@MadCowWeb
MadCowWeb / conditional cart checkout hook by product ID
Created April 4, 2024 17:15
Add custom content to cart and checkout pages (only if a certain product ID is in the cart) with an action hook
// CHECK FOR SPECIFIC PRODUCT ID IN CART
function madcow_custom_product_id_is_in_the_cart($ids) {
// Products currently in the cart
$cart_ids = array();
// Find each product in the cart and add it to the $cart_ids array
foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
$cart_product = $values['data'];
$cart_ids[] = $cart_product->id;
}
// If one of the special products are in the cart, return true.
@MadCowWeb
MadCowWeb / conditional cart checkout hook by catetory
Last active April 4, 2024 17:14
Add custom content to cart and checkout pages (only if a certain category is in the cart) with an action hook
// CHECK FOR SPECIFIC PRODUCT CATEGORY IN CART
function madcow_custom_category_is_in_the_cart($categories) {
// Products currently in the cart
$cart_ids = array();
// Categories currently in the cart
$cart_categories = array();
// Find each product in the cart and add it to the $cart_ids array
foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
$cart_product = $values['data'];
$cart_ids[] = $cart_product->id;
@MadCowWeb
MadCowWeb / cart checkout hook
Created April 4, 2024 15:08
Add custom content to cart and checkout pages with an action hook
//ADD BANNER TO CART PAGE
add_action('woocommerce_before_cart', 'madcow_above_cart_and_checkout_message');
add_action('woocommerce_after_order_notes', 'madcow_above_cart_and_checkout_message');
function madcow_above_cart_and_checkout_message() {
echo 'your-content-here';
}