This file contains hidden or 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
// code added to theme functions.php file | |
add_action( 'woocommerce_after_shop_loop_item', 'show_product_excerpt' ); | |
function show_product_excerpt() { | |
the_excerpt(); | |
} |
This file contains hidden or 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 | |
// Code goes in theme functions.php or a custom plugin | |
add_filter( 'pre_option_woocommerce_enable_guest_checkout', 'conditional_guest_checkout_based_on_product' ); | |
function conditional_guest_checkout_based_on_product( $value ) { | |
$restrict_ids = array( 1, 2, 3 ); // Replace with product ids which cannot use guest checkout | |
if ( WC()->cart ) { | |
$cart = WC()->cart->get_cart(); |
This file contains hidden or 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
if ( taxonomy_exists( 'job_listing_category' ) ) { | |
$categories = get_terms( 'category' ); | |
foreach ( $categories as $category ) { | |
if ( ! term_exists( $category->name, 'job_listing_category' ) ) { | |
wp_insert_term( $category->name, 'job_listing_category' ); | |
} | |
} | |
} |
This file contains hidden or 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
/** | |
* This function loops over cart items, and moves any item with shipping class 'special-class' into a new package. | |
* The new package in this example only takes flat rate shipping. | |
*/ | |
function split_special_shipping_class_items( $packages ) { | |
$found_item = false; | |
$special_class = 'special-class'; // edit this with the slug of your shippig class | |
$new_package = current( $packages ); | |
$new_package['contents'] = array(); | |
$new_package['contents_cost'] = 0; |
This file contains hidden or 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
// Simple products | |
add_filter( 'woocommerce_quantity_input_args', 'jk_woocommerce_quantity_input_args', 10, 2 ); | |
function jk_woocommerce_quantity_input_args( $args, $product ) { | |
if ( is_singular( 'product' ) ) { | |
$args['input_value'] = 2; // Starting value (we only want to affect product pages, not cart) | |
} | |
$args['max_value'] = 80; // Maximum value | |
$args['min_value'] = 2; // Minimum value | |
$args['step'] = 2; // Quantity steps |
This file contains hidden or 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
add_shortcode( 'custom_product_price', 'custom_product_price_shortcode' ); | |
function custom_product_price_shortcode( $atts ) { | |
if ( empty( $atts ) ) { | |
return ''; | |
} | |
if ( isset( $atts['id'] ) ) { | |
$product = wc_get_product( $atts['id'] ); | |
return $product->get_price_html(); |
This file contains hidden or 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 | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; | |
} | |
/** | |
* Sample instance based method. | |
*/ | |
class WC_Shipping_Test_Method extends WC_Shipping_Method { |
This file contains hidden or 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
add_filter( 'woocommerce_get_order_item_totals', 'adjust_woocommerce_get_order_item_totals' ); | |
function adjust_woocommerce_get_order_item_totals( $totals ) { | |
unset($totals['cart_subtotal'] ); | |
return $totals; | |
} |
This file contains hidden or 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 | |
/** | |
* Show the size switcher. | |
*/ | |
function size_switcher_display() { | |
global $product; | |
echo '<div class="wc-size-switcher">'; | |
echo __( 'Display sizes as:', 'woocommerce-size-switcher' ) . ' '; |
This file contains hidden or 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
// code added to theme functions.php file | |
add_action( 'woocommerce_after_shop_loop_item', 'show_product_category_name' ); | |
function show_product_category_name() { | |
global $post; | |
echo get_the_term_list( $post->ID, 'product_cat' ); | |
} |