Allow HTML in Term (Category, tag) Descriptions

foreach (array(‘pre_term_description’) as $filter) { remove_filter($filter, ‘wp_filter_kses’); if (!current_user_can(‘unfiltered_html’)) { add_filter($filter, ‘wp_filter_post_kses’); } } foreach (array(‘term_description’) as $filter) { remove_filter($filter, ‘wp_kses_data’); }Continue reading

Automatically Add Product to Cart on Visit

function g9_add_product_to_cart() { if (!is_admin()) { $product_id = 64; //replace with your own product id $found = false; //check if product already in cart if (sizeof(WC()->cart->get_cart()) > 0) { foreach (WC()->cart->get_cart() as $cart_item_key => $values) { $_product = $values[‘data’]; if…Continue reading

Change Add to Cart text on Single & Archive Product Page

// Change add to cart text on single product page function g9_woocommerce_add_to_cart_button_text_single() { return __(‘Add to Cart Button Text’, ‘woocommerce’); } add_filter(‘woocommerce_product_single_add_to_cart_text’, ‘g9_woocommerce_add_to_cart_button_text_single’); // Change add to cart text on product archives page function g9_woocommerce_add_to_cart_button_text_archives() { return __(‘Add to Cart…Continue reading

Remove Product Content Based on Category

function g9_remove_product_content() { // If a product in the ‘Cookware’ category is being viewed… if (is_product() && has_term(‘Cookware’, ‘product_cat’)) { //… Remove the images remove_action(‘woocommerce_before_single_product_summary’, ‘woocommerce_show_product_images’, 20); // For a full list of what can be removed please see woocommerce-hooks.php…Continue reading

Set a Minimum Order Amount for Checkout

function g9_minimum_order_amount() { // Set this variable to specify a minimum order value $minimum = 50; if (WC()->cart->total < $minimum) { if (is_cart()) { wc_print_notice( sprintf( 'Your current order total is %s — you must have an order with a…Continue reading

Adjust the Quantity Input Values (Min/Max)

function g9_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…Continue reading

Show Product Weight on Archive Pages

function g9_show_weights() { global $product; $weight = $product->get_weight(); if ($product->has_weight()) { echo ‘ Weight: ‘ . $weight . get_option(‘woocommerce_weight_unit’) . ‘ ‘; } } add_action(‘woocommerce_after_shop_loop_item’, ‘g9_show_weights’, 9);Continue reading

Apply a Coupon for Minimum Cart Total

function g9_add_coupon_notice() { $cart_total = WC()->cart->get_subtotal(); $minimum_amount = 50; $currency_code = get_woocommerce_currency(); wc_clear_notices(); if ($cart_total < $minimum_amount) { WC()->cart->remove_coupon(‘COUPON’); wc_print_notice(“Get 50% off if you spend more than $minimum_amount $currency_code!”, ‘notice’); } else { WC()->cart->apply_coupon(‘COUPON’); wc_print_notice(‘You just got 50% off your…Continue reading

Support for WebP Images

function g9_mime_types($mime_types) { $mime_types[‘webp’] = ‘image/webp’; //Adding webp extension return $mime_types; } add_filter(‘woocommerce_rest_allowed_image_mime_types’, ‘g9_mime_types’, 1, 1);Continue reading