Skip to content

Instantly share code, notes, and snippets.

@h3nr1ke
Last active April 6, 2018 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h3nr1ke/56dc2e6b61a0376487b62938a7e23ba5 to your computer and use it in GitHub Desktop.
Save h3nr1ke/56dc2e6b61a0376487b62938a7e23ba5 to your computer and use it in GitHub Desktop.
Useful Wordpress code
<?php
//==================================
// ONLY ONE ITEM IN THE CART AT TIME
//==================================
add_filter( 'woocommerce_add_cart_item_data', 'woo_custom_add_to_cart' );
function woo_custom_add_to_cart( $cart_item_data ) {
global $woocommerce;
// REMOVE ALL OTHER ITEMS
$woocommerce->cart->empty_cart();
//RETURN JUST THE NEW ONE...
return $cart_item_data;
}
//==================================
// SHORTCODE CREATION
//==================================
// usage - [shortcodename] will display <h1>SHORTCODE HTML RETURN</h1>
add_shortcode('shortcodename', 'shortcode_function');
function shortcode_function($attrs){
//if you want to handle the attributes, it will be an item in the array
// ie. [shortcodename title="Title H1"] will populate the $attrs var
// $attrs["title"]
return "<h1>SHORTCODE HTML RETURN</h1>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment