Skip to content

Instantly share code, notes, and snippets.

/* Derek's Sum Code */
// Add Shortcode
function calculator_shortcode() {
$post_args = array(
'post_type' => 'post',
'posts_per_page' => 10000,
'no_found_rows' => true,
'update_post_term_cache' => false,
/******************************** MODELS SHORTCODE ********************************/
function models_shortcode($atts){
extract( shortcode_atts( array(
'expand' => '',
), $atts) );
$mod_args = array(
'post_type' => 'model',
'orderby' => 'menu_order',
'order' => 'ASC',
@TimbreDesign
TimbreDesign / gist:532c2b816f6c15ef3ba392a10ddb8337
Last active May 19, 2019 01:04
WooCommerce - Conditional if product is in order
/* CHECK IF PRODUCT IS IN ORDER TEMPLATE */
function tb_check_order_product_id( $order_id ){
$order = new WC_Order( $order_id );
$items = $order->get_items();
foreach ( $items as $item ) {
$product_id = $item['product_id'];
if ( $product_id == XYZ ) {
// do something
}
}
@TimbreDesign
TimbreDesign / gist:015b50efee274a408096b37d7f3d70cc
Created May 19, 2019 00:23
WooCommerce - Simplify checkout for free products
/* FREE PRODUCTS SIMPLIFY CHECKOUT */
function mtpt_free_checkout_fields() {
// Bail we're not at checkout, or if we're at checkout but payment is needed
if ( function_exists( 'is_checkout' ) && ( ! is_checkout() || ( is_checkout() && WC()->cart->needs_payment() ) ) ) {
return;
}
// remove coupon forms since why would you want a coupon for a free cart??
@TimbreDesign
TimbreDesign / gist:74d9a6b50df9894646ca95525495201e
Created May 19, 2019 00:20
WooCommerce - Change User Role for New Customers
/* CHANGE USER ROLE FOR NEW CUSTOMERS */
/* 1. ADD NEW ROLE */
add_role( 'pending', __('Pending' ),array(
'read' => true,
)
);
/* 2. ASSIGN NEW ROLE */
function tb_assign_custom_role($args) {
@TimbreDesign
TimbreDesign / gist:cb16a8265b5f792f66a4d84560f77899
Created May 19, 2019 00:18
WooCommerce - Add to cart redirect per product
/* ADD TO CART REDIRECT PER PRODUCT */
/* STEP 1 - REMOVE ADD TO CART BUTTON ON PRODUCT ARCHIVE (SHOP) */
function remove_loop_button(){
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
}
add_action('init','remove_loop_button');
/*STEP 2 -ADD NEW BUTTON THAT LINKS TO PRODUCT PAGE FOR EACH PRODUCT */
function replace_add_to_cart() {
@TimbreDesign
TimbreDesign / gist:51e8e9aeb154a09947e23ad8c41127b7
Created May 19, 2019 00:14
WooCommerce - Hide category in shop
/* HIDE CATEGORY FROM SHOP */
add_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
function custom_pre_get_posts_query( $q ) {
if ( ! $q->is_main_query() ) return;
if ( ! $q->is_post_type_archive() ) return;
if ( ! is_admin() && is_shop() ) {
@TimbreDesign
TimbreDesign / gist:c802f4cd239b9837247052022fb0cac9
Last active May 19, 2019 00:13
Hide all shipping options when free shipping is available
/* Hide all shipping options when free shipping is available */
/* @param array $available_methods*/
function hide_all_shipping_when_free_is_available( $available_methods ) {
if( isset( $available_methods['free_shipping'] ) ) :
// Get Free Shipping array into a new array
$freeshipping = array();
$freeshipping = $available_methods['free_shipping'];
/******************************** FOOTER COPYRIGHT ********************************/
function tb_footer_copyright() {
?>
<p>
&copy; <?php echo date("Y"); echo " "; echo "Sunado Vans"; ?> <a href="/privacy-policy/" title="Our Privacy Policy" class="Privacy">Privacy Policy</a>
</p>
<?php
}
add_filter( 'generate_copyright','tb_footer_copyright' );
@TimbreDesign
TimbreDesign / gist:666cac72d9c562379423414f8abe5707
Created May 19, 2019 00:04
WooCommerce - products pagination
/* Display products pagination */
add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 18;' ), 20 );