• Skip to main content
  • Skip to primary sidebar

WordPress, Genesis Framework and Storefront customization tutorials

  • Archive
    • Free
    • Premium
  • Blog
  • About
  • Contact
  • Newsletter
  • Membership
  • Login
Home » WooCommerce » Page 3

WooCommerce

How to show custom message based on shipping class on single product page

// =========================================================================
// Custom Text on Product Page based on Shipping Class 
// =========================================================================
function display_shipping_class_on_product_page() {
    $product = wc_get_product();

    $shipping_class = $product->get_shipping_class();

    switch ( $shipping_class ) {
        case 'your_shipping_class_1':
            echo '';
            break;
        case 'your_shipping_class_2':
            echo '';
            break;
    }
}
add_action( 'woocommerce_single_product_summary', 'display_shipping_class_on_product_page', 10 );

Filed Under: Free Tagged With: WooCommerce

Disable payment method for specific country in WooCommerce

To view the full content, please sign up for the membership.

If You are already a member, please log in below:

 
 
Forgot Password

Filed Under: Premium Tagged With: WooCommerce

Add fee to specific payment gateway only for physical products

To view the full content, please sign up for the membership.

If You are already a member, please log in below:

Filed Under: Premium Tagged With: WooCommerce

Add custom out of stock message for specific product category

To view the full content, please sign up for the membership.

If You are already a member, please log in below:

Filed Under: Premium Tagged With: WooCommerce

WooCommerce free shipping over amount and hide other shipping methods

To view the full content, please sign up for the membership.

If You are already a member, please log in below:

Filed Under: Premium Tagged With: WooCommerce

Disable Payment Gateway For Specific Product Category

To view the full content, please sign up for the membership.

If You are already a member, please log in below:

Filed Under: Premium Tagged With: WooCommerce

Disable Payment Gateway For Specific Shipping Method

To view the full content, please sign up for the membership.

If You are already a member, please log in below:

Filed Under: Premium Tagged With: WooCommerce

If product is out of stock echo something – WooCommerce product single

//Echo something if product is out of stock
add_action( 'woocommerce_share', 'add_out_of_stock_custom_message', 5 );
function add_out_of_stock_custom_message() {
    global $product;
    if ( ! $product->is_in_stock() ) {
            echo '';
        }

}

Filed Under: Free Tagged With: WooCommerce

How to send custom email based on product ID in WooCommerce

To view the full content, please sign up for the membership.

If You are already a member, please log in below:

Filed Under: Premium Tagged With: WooCommerce

Disable Barion if shipping method is free shipping

//Disable Payment Gateway For Specific Shipping Method
 
add_filter( 'woocommerce_available_payment_gateways', 'wpninja_gateway_disable_shipping_326' );
 
function wpninja_gateway_disable_shipping_326( $available_gateways ) {
 
    global $woocommerce;
     
    if ( !is_admin() ) {
         
        $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
         
        $chosen_shipping = $chosen_methods[0];
         
        if ( isset( $available_gateways['cod'] ) && 0 === strpos( $chosen_shipping, 'free_shipping' ) ) {
            unset( $available_gateways['barion'] );
        }
        
    }
     
return $available_gateways;
     
}

Filed Under: Free Tagged With: WooCommerce

How to apply coupon when specific product ID in the cart?

To view the full content, please sign up for the membership.

If You are already a member, please log in below:

Filed Under: Premium Tagged With: WooCommerce

How to add Taxonomy Filter to WooCommerce admin

To view the full content, please sign up for the membership.

If You are already a member, please log in below:

Filed Under: Premium Tagged With: WooCommerce

Search by product SKU

/**
 * Search by product SKU
 */
function wpninja_product_search_sku( $join, $query ) {
	if ( ! $query->is_main_query() || is_admin() || ! is_search() || ! is_woocommerce() ) {
		return $join;
	}

	global $wpdb;

	$join .= " LEFT JOIN {$wpdb->postmeta} wpninja_post_meta ON {$wpdb->posts}.ID = wpninja_post_meta.post_id ";

	return $join;
}

add_filter( 'posts_join', 'wpninja_product_search_sku', 10, 2 );

/**
 * Modify the search query with posts_where.
 */
function wpninja_product_search_where( $where, $query ) {
	if ( ! $query->is_main_query() || is_admin() || ! is_search() || ! is_woocommerce() ) {
		return $where;
	}

	global $wpdb;

	$where = preg_replace(
		"/\(\s*{$wpdb->posts}.post_title\s+LIKE\s*(\'[^\']+\')\s*\)/",
		"({$wpdb->posts}.post_title LIKE $1) OR (wpninja_post_meta.meta_key = '_sku' AND wpninja_post_meta.meta_value LIKE $1)", $where );

	return $where;
}

add_filter( 'posts_where', 'wpninja_product_search_where', 10, 2 );

Filed Under: Free Tagged With: WooCommerce

Show SKU above the product title

//Show SKU above the product title
function fdesign_show_sku(){
    global $product;
    echo '<small>Cikkszám:</small> <small>' . $product->get_sku() .'</small>';
}
add_action( 'woocommerce_before_single_product_summary', 'fdesign_show_sku', 5 );

Filed Under: Free Tagged With: WooCommerce

Show Product Search in Header

//Show Product Search in Header
function new_nav_menu_items($items, $args) {
    
    $my_product_search = get_product_search_form( $echo );
    
    if($args->theme_location == 'main_navigation'){
       $items = $items . $my_product_search;
    }

    return $items;
}
add_filter('wp_nav_menu_items', 'new_nav_menu_items', 10, 2);

Filed Under: Free Tagged With: WooCommerce

How to fix WooCommerce Terms and Conditions link on Checkout Page

jQuery(function($){
    $( "a.woocommerce-terms-and-conditions-link" ).unbind( "click" );
    $( "body" ).on('click', 'a.woocommerce-terms-and-conditions-link', function( event ) {

         $(this).attr("target", "_blank");
        window.open( $(this).attr("href"));

        return false;
    });

});

Filed Under: Free Tagged With: WooCommerce

Add Product to WooCommerce Cart Automatically


add_action( 'template_redirect', 'snippet_add_product_to_cart' );

function snippet_add_product_to_cart() {

// select ID
$product_id = 21874;

//check if product already in cart
if ( WC()->cart->get_cart_contents_count() == 0 ) {

// if no products in cart, add it
WC()->cart->add_to_cart( $product_id );

}

}

Filed Under: Free Tagged With: WooCommerce

Add Product to Cart When Visiting a Specific Page ID


add_action( 'wp', 'add_product_to_cart_on_page_id_load' );

function add_product_to_cart_on_page_id_load() {

// product ID to add to cart
$product_id = 21874;

// page ID to target
if ( is_page( 19473 ) ) {
WC()->cart->empty_cart();
WC()->cart->add_to_cart( $product_id );
}

}

Filed Under: Free Tagged With: WooCommerce

Add custom field to single product page


//ADD CUSTOM FIELD TO SINGLE PRODUCT BEFORE ADD TO CART BUTTON
add_action( 'woocommerce_single_variation', 'add_custom_field_before_addtocart', 5 );
function add_custom_field_before_addtocart() {
include('woo/custom-field.php');
}


<?php the_field('custom'); ?>

Filed Under: Free Tagged With: WooCommerce

Add custom text below the table of email notification


add_action('woocommerce_email_after_order_table', 'add_email_shipping_text');
function add_email_shipping_text(){
echo '';
}

Filed Under: Free Tagged With: WooCommerce

  • « Go to Previous Page
  • Go to page 1
  • Go to page 2
  • Go to page 3
  • Go to page 4
  • Go to page 5
  • Go to Next Page »

Primary Sidebar

Gabor Flamich

Hi! I'm Gabor.
I write tutorials on WordPress and WooCommerce.

MacBook

12 Essential Snippets for Genesis Developers

Subscribe to my Newsletter to view my basic collection of Genesis snippets that I use for my projects!

Sign Up for Free
  • Facebook
  • GitHub
  • Instagram
  • LinkedIn
  • Twitter
  • YouTube
UpdraftPlus Premium

Tags

ACF Ajax Analytics API Bootstrap Breadcrumb category CPT CSS fetch Genesis Google Maps Gutenberg HTML Isotope JavaScript jQuery loop Map Menu Parallax PHP SASS SEO SQL Storefront SVG tab tag manager tags Taxonomy Tool upsell Webpack Wholesale WooCommerce WordPress WPML

Disclosure: Some of the links in this site are affiliate links. I will be paid a commission if you use this link to make a purchase.

  • Privacy Policy / Terms of Service
© 2023 WP Flames - All Right Reserved