Last active
April 6, 2018 18:12
-
-
Save h3nr1ke/56dc2e6b61a0376487b62938a7e23ba5 to your computer and use it in GitHub Desktop.
Useful Wordpress code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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