Tips on how to customise Woocommerce Single Product Web page | 14 Helpful Hacks

On this video I’m going to indicate you 14 helpful Woocommerce single product web page hacks you need to use in each retailer. If you need to make use of these snippets right here beneath then simply add those you want inside your little one theme’s capabilities.php file or higher but, use Code Snippets plugin. This manner you’re not going to lose these modifications in case you’re switching your theme.

WpCodeBox is my favourite code snippets supervisor for WordPress. It is a premium plugin and in the event you’re , then seize WPCodeBox with a pleasant 20% low cost right here (SAVE 20% Coupon WPSH20).

Additionally, check out the video tutorial right here beneath after which it is going to in all probability be a bit simpler to know what’s what.

Video: Tips on how to use Woocommerce Single Product Web page Hacks

Tips on how to create and show {custom} product subject?

First, let’s create a brand new Woocommerce single product {custom} subject and let’s output it within the desired place. The tip outcome will appear like the one right here beneath on the screenshot.

Woocommerce Single Product Page Hacks

So, simply seize this code and use it accordingly.

<span position="button" tabindex="0" data-code="// Add {custom} subject to Woocommerce backend beneath Common tab
add_action( 'woocommerce_product_options_general_product_data', 'wpsh_add_text_field' );
perform wpsh_add_text_field() {
woocommerce_wp_text_input( array(
'id' => '_shipping_time',
'label' => __( 'Delivery information', 'woocommerce' ),
'description' => __( 'It is a {custom} subject, you may write right here something you need.', 'woocommerce' ),
'desc_tip' => 'true',
'kind' => 'textual content'
) );
}

// Save {custom} subject values
add_action( 'woocommerce_admin_process_product_object', 'wpsh_save_field', 10, 1 );
perform wpsh_save_field( $product ) {
if ( isset( $_POST['_shipping_time'] ) ) {
$product->update_meta_data( '_shipping_time', sanitize_text_field( $_POST['_shipping_time'] ) );
}
}

// Show this practice subject on Woocommerce single product pages
add_action( 'woocommerce_product_meta_end', 'wpsh_display_on_single_product_page', 10 );
perform wpsh_display_on_single_product_page() {
world $product;

// Is a WC product
if ( is_a( $product, 'WC_Product' ) ) {
// Get meta
$textual content = $product->get_meta( '_shipping_time' );
// NOT empty
if ( ! empty ( $textual content ) ) {
echo '<div class="woocommerce-message">Estimated transport time: ' . $textual content . '</div>';
}
}
}
// Show this practice subject on Woocommerce archive pages
add_action( 'woocommerce_after_shop_loop_item', 'wpsh_display_on_archive_page', 10 );
perform wpsh_display_on_archive_page() {
world $product;
// Is a WC product
if ( is_a( $product, 'WC_Product' ) ) {
// Get meta
$textual content = $product->get_meta( '_shipping_time' );
// NOT empty
if ( ! empty ( $textual content ) ) {
echo '<div class="custom-text">Estimated transport time: ' . $textual content . '

// Add {custom} subject to Woocommerce backend beneath Common tab
add_action( 'woocommerce_product_options_general_product_data', 'wpsh_add_text_field' );
perform wpsh_add_text_field() {
    woocommerce_wp_text_input( array(
        'id'            => '_shipping_time',
        'label'         => __( 'Delivery information', 'woocommerce' ),
        'description'   => __( 'It is a {custom} subject, you may write right here something you need.', 'woocommerce' ),
        'desc_tip'      => 'true',
        'kind'          => 'textual content'
    ) );
}


// Save {custom} subject values
add_action( 'woocommerce_admin_process_product_object', 'wpsh_save_field', 10, 1 );
perform wpsh_save_field( $product ) {
    if ( isset( $_POST['_shipping_time'] ) ) {        
        $product->update_meta_data( '_shipping_time', sanitize_text_field( $_POST['_shipping_time'] ) );
    }
}

// Show this practice subject on Woocommerce single product pages
add_action( 'woocommerce_product_meta_end', 'wpsh_display_on_single_product_page', 10 );
perform wpsh_display_on_single_product_page() {
    world $product;
    
    // Is a WC product
    if ( is_a( $product, 'WC_Product' ) ) {
        // Get meta
        $textual content = $product->get_meta( '_shipping_time' );
        // NOT empty
        if ( ! empty ( $textual content ) ) {
            echo '<div class="woocommerce-message">Estimated transport time: ' . $textual content . '</div>';
        }
    }
}
// Show this practice subject on Woocommerce archive pages
add_action( 'woocommerce_after_shop_loop_item', 'wpsh_display_on_archive_page', 10 );
perform wpsh_display_on_archive_page() {
    world $product;
    // Is a WC product
    if ( is_a( $product, 'WC_Product' ) ) {
        // Get meta
        $textual content = $product->get_meta( '_shipping_time' );
        // NOT empty
        if ( ! empty ( $textual content ) ) {
            echo '<div class="custom-text">Estimated transport time: ' . $textual content . '</div>';
        }
    }
}

Tips on how to create {custom} tab?

This snippet right here beneath creates new {custom} Woocommerce single product tab and it accommodates textual content and call type. Simply substitute the content material as you want and also you’re good to go.

add_filter( 'woocommerce_product_tabs', 'custom_tab' );
perform custom_tab( $tabs ) {	
	// Provides the brand new tab
	$tabs['form'] = array(
		'title' 	=> __( 'Ship us an enquiry', 'woocommerce' ),
		'precedence' 	=> 30,
		'callback' 	=> 'custom_tab_content'
	);
	return $tabs;
}
perform custom_tab_content() {

	// The brand new tab content material

	echo '<h4>Ship us an enquiry</h4>';
	echo '<p>Lorem ipsum dolor sit amet consectetur adipiscing elit ultricies convallis volutpat, placerat proin scelerisque eget velit tellus at nibh risus. </p>';
	echo do_shortcode( '' );
}

It’s straightforward. If you wish to transfer Woocommerce associated merchandise in a tab then use this snippet.

/* Associated merchandise IN CUSTOM TAB */

// Take away associated merchandise from authentic location
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);
 
// Create a brand new {custom} tab
add_filter( 'woocommerce_product_tabs', 'related_product_tab' );
 
perform related_product_tab( $tabs ) {   
$tabs['related-products'] = array(
   'title'    => __( 'Associated merchandise', 'woocommerce' ),
   'precedence'    => 50,
   'callback'    => 'related_product_tab_content'
);
   return $tabs;
}
 
// Add associated merchandise inside new tab
perform related_product_tab_content() {
woocommerce_output_related_products();
}

If you wish to transfer Woocommerce upsell merchandise in a tab then use this snippet.

 /* UPSELLS IN CUSTOM TAB */

// Take away uplsells merchandise from authentic location
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 );
 
// Create a brand new {custom} tab
 
add_filter( 'woocommerce_product_tabs', 'upsells_product_tab' );
 
perform upsells_product_tab( $tabs ) {   
$tabs['upsells-products'] = array(
   'title'    => __( 'Appropriate merchandise', 'woocommerce' ),
   'precedence'    => 50,
   'callback'    => 'upsells_tab_content'
);
   return $tabs;
}
// Add upsells inside new tab
perform upsells_tab_content() {
woocommerce_upsell_display();
}

Tips on how to scroll on to Woocommerce product tab and open it routinely?

This code snippet right here beneath provides hyperlinks above add to cart button. If you happen to click on on the hyperlink it is going to scroll to the product tab and routinely opens it. If you happen to’re utilizing {custom} tabs then add a brand new hyperlink with the {custom} tab identify.

<span position="button" tabindex="0" data-code="add_action( 'woocommerce_single_product_summary', 'scroll_to_product_tab', 21 );

perform scroll_to_product_tab() {

world $put up, $product;

// LINK TO SCROLL TO DESC TAB
if ( $post->post_content ) {
echo '<p><a category="jump-to-tab" href="#tab-description">' . __( 'Learn extra', 'woocommerce' ) . ' →</a></p>';
}

// LINK TO SCROLL TO ADDITIONAL INFO TAB
if ( $product && ( $product->has_attributes() || apply_filters( 'wc_product_enable_dimensions_display', $product->has_weight() || $product->has_dimensions() ) ) ) {
echo '<p><a category="jump-to-tab" href="#tab-additional_information">' . __( 'Extra data', 'woocommerce' ) . ' →</a></p>';
}
// LINK TO SCROLL TO REVIEWS TAB
if ( comments_open() ) {
echo '<p><a category="jump-to-tab" href="#tab-reviews">' . __( 'Critiques', 'woocommerce' ) . ' →</a></p>';
}
?>
<script>
jQuery(doc).prepared(perform($){
$('a.jump-to-tab').click on(perform(e){
e.preventDefault();
var tabhash = $(this).attr("href");
var tabli = 'li.' + tabhash.substring(1);
var tabpanel = '.panel' + tabhash;
$(".wc-tabs li").every(perform() {
if ( $(this).hasClass("lively") ) {
$(this).removeClass("lively");
}
});
$(tabli).addClass("lively");
$(".woocommerce-tabs .panel").css("show","none");
$(tabpanel).css("show","block");
$('html,physique').animate({scrollTop:$(tabpanel).offset().high -150},'sluggish'); // Set your offset by altering -150 worth
});
});
</script>

add_action( 'woocommerce_single_product_summary', 'scroll_to_product_tab', 21 );
  
perform scroll_to_product_tab() {
     
    world $put up, $product; 
     
    // LINK TO SCROLL TO DESC TAB
    if ( $put up->post_content ) {
        echo '<p><a category="jump-to-tab" href="#tab-description">' . __( 'Learn extra', 'woocommerce' ) . ' →</a></p>';
    }
     
    // LINK TO SCROLL TO ADDITIONAL INFO TAB
    if ( $product && ( $product->has_attributes() || apply_filters( 'wc_product_enable_dimensions_display', $product->has_weight() || $product->has_dimensions() ) ) ) {
        echo '<p><a category="jump-to-tab" href="#tab-additional_information">' . __( 'Extra data', 'woocommerce' ) . ' →</a></p>';
    }
        // LINK TO SCROLL TO REVIEWS TAB
    if ( comments_open() ) {
        echo '<p><a category="jump-to-tab" href="#tab-reviews">' . __( 'Critiques', 'woocommerce' ) . ' →</a></p>';
    }
    ?>
        <script>
        jQuery(doc).prepared(perform($){
            $('a.jump-to-tab').click on(perform(e){
                e.preventDefault();
                var tabhash = $(this).attr("href");
                var tabli = 'li.' + tabhash.substring(1);
                var tabpanel = '.panel' + tabhash;
                $(".wc-tabs li").every(perform() {
                    if ( $(this).hasClass("lively") ) {
                        $(this).removeClass("lively");
                    }
                });
                $(tabli).addClass("lively");
                $(".woocommerce-tabs .panel").css("show","none");
                $(tabpanel).css("show","block");
                $('html,physique').animate({scrollTop:$(tabpanel).offset().high -150},'sluggish'); // Set your offset by altering -150 worth
            });
        });
        </script>
    <?php
}

Possibly that you must ship a hyperlink with the particular product critiques to somebody and isntead of sending him/her the product hyperlink you may ship the hyperlink to the overview tab itself. So, use this snippet right here beneath and ship the hyperlink in a type https://yoursite.com&/demo-product/#tab-reviews

If you wish to hyperlink to another tab then simply substitute #tab-reviews with the proper tab hyperlink.

<span position="button" tabindex="0" data-code="perform direct_link_to_product_tabs() {
if( is_product() ) {
?>
<script kind="textual content/javascript">
jQuery(doc).prepared(perform($) {

if( window.location.hash ) {
// Vars
var tab = window.location.hash.substitute('#', '');

// Tabs
$( 'li.description_tab' ).removeClass( 'lively' );
$( 'a[href="#' + tab + '"]' ).father or mother( 'li' ).addClass( 'lively' );

// Tabs content material
$( '#tab-description' ).cover();
$( '#tab-' + tab.substitute( 'tab-', '' ) ).present();
}

// when the tab is chosen replace the url with the hash
$( '.tabs a' ).click on( perform() {
window.location.hash = 'tab-' + $(this).father or mother('li').attr("class").substitute(' lively', '').substitute('_tab', '');
});

});
</script>

perform direct_link_to_product_tabs() {
	if( is_product() ) {
	?>
		<script kind="textual content/javascript">
			jQuery(doc).prepared(perform($) {

				if( window.location.hash ) {
					// Vars
					var tab = window.location.hash.substitute('#', '');

					// Tabs
					$( 'li.description_tab' ).removeClass( 'lively' );
					$( 'a[href="#' + tab + '"]' ).father or mother( 'li' ).addClass( 'lively' );

					// Tabs content material
					$( '#tab-description' ).cover();
					$( '#tab-' + tab.substitute( 'tab-', '' ) ).present();
				}

				// when the tab is chosen replace the url with the hash
				$( '.tabs a' ).click on( perform() { 
window.location.hash = 'tab-' + $(this).father or mother('li').attr("class").substitute(' lively', '').substitute('_tab', '');
				});

			});
		</script>
	<?php
	}
}
add_action( 'wp_footer', 'direct_link_to_product_tabs', 30 );

Tips on how to show “You save” on the market worth?

Check out the screenshot right here beneath. That is what these snippets are doing for you.

Useful Woocommerce Single Product Page Hacks

So, with a view to make it work like that use this snippet.

<span position="button" tabindex="0" data-code="perform you_save_text_for_product() {
world $product;

// works for Easy and Variable kind
$regular_price = get_post_meta( $product->get_id(), '_regular_price', true ); // 36.32
$sale_price = get_post_meta( $product->get_id(), '_sale_price', true ); // 24.99

if( !empty($sale_price) ) {

$saved_amount = $regular_price – $sale_price;
$currency_symbol = get_woocommerce_currency_symbol();

$proportion = spherical( ( ( $regular_price – $sale_price ) / $regular_price ) * 100 );
?>
<p class="you_save_price">You save: <?php echo $currency_symbol .''. number_format($saved_amount, 2, '.', ''); ?></p>

perform you_save_text_for_product() {
	world $product;

	// works for Easy and Variable kind
	$regular_price 	= get_post_meta( $product->get_id(), '_regular_price', true ); // 36.32
	$sale_price 	= get_post_meta( $product->get_id(), '_sale_price', true ); // 24.99
		
	if( !empty($sale_price) ) {
	
		$saved_amount 		= $regular_price - $sale_price;
		$currency_symbol 	= get_woocommerce_currency_symbol();

		$proportion = spherical( ( ( $regular_price - $sale_price ) / $regular_price ) * 100 );
		?>
			<p class="you_save_price">You save: <?php echo $currency_symbol .''. number_format($saved_amount, 2, '.', ''); ?></p>				
		<?php		
	} 
		
}
add_action( 'woocommerce_single_product_summary', 'you_save_text_for_product', 12 ); // hook precedence

If you need to customise the look of it then check out the you_save_price CCS class. Now go to Customizer >> Extra CSS and add this small pies of CSS to customise it.

.you_save_price {
	background: #f9f9f9;
	padding: 10px;
	border: 1px dashed #ddd;
	width: 150px;
	font-size: 14px;
	font-weight: 600;
	margin-top: 10px;
}

Now, this code above exhibits saved quantity solely for easy merchandise. If you need to indicate it additionally for variable merchandise, then add this piece of code.

<span position="button" tabindex="0" data-code="// For product variations (on variable merchandise)
add_filter( 'woocommerce_available_variation', 'variable_product_saving_amount', 10, 3 );
perform variable_product_saving_amount( $information, $product, $variation ) {

if( $variation->is_on_sale() ) {
$saved_amount = $information['display_regular_price'] – $information['display_price'];
$proportion = spherical( $saved_amount / $information['display_regular_price'] * 100 );

$information['price_html'] .= '<p id="you_save_price">'. __("You Save") .': ' . wc_price($saved_amount) . ' ('.$proportion.'%)

// For product variations (on variable merchandise)
add_filter( 'woocommerce_available_variation', 'variable_product_saving_amount', 10, 3 );
perform variable_product_saving_amount( $information, $product, $variation ) {

    if( $variation->is_on_sale() ) {
        $saved_amount  = $information['display_regular_price'] - $information['display_price'];
        $proportion    = spherical( $saved_amount / $information['display_regular_price'] * 100 );

        $information['price_html'] .= '<p id="you_save_price">'. __("You Save") .': ' . wc_price($saved_amount) . ' ('.$proportion.'%)</p>';
    }
    return $information;
}

Tips on how to add Again to class button on Woocommerce single product web page?

This items of code will add Again to class button on Woocommerce single product web page beneath the Meta block.

<span position="button" tabindex="0" data-code="add_action ('woocommerce_share','add_back_product_category_button', 5);
perform add_back_product_category_button(){

// Get the product classes set within the product
$phrases = wp_get_post_terms( get_the_id(), 'product_cat' );

// Test that there’s at leat one product class set for the product
if(sizeof($phrases) > 0){
// Get the primary product class WP_Term object
$time period = reset($phrases);
// Get the time period hyperlink (button hyperlink)
$hyperlink = get_term_link( $time period, 'product_cat' );

// Button textual content
$textual content = __('← Again to class','woocommerce') . ' <sturdy>' . $term->identify . '</sturdy>';

// Output
echo '<div class="back-to-category"><a href="'.esc_url($hyperlink).'" title="'.$textual content.'" '.$term->slug.'">'.$textual content.'</a>

add_action ('woocommerce_share','add_back_product_category_button', 5);
perform add_back_product_category_button(){

    // Get the product classes set within the product
    $phrases = wp_get_post_terms( get_the_id(), 'product_cat' );

    // Test that there's at leat one product class set for the product
    if(sizeof($phrases) > 0){
        // Get the primary product class WP_Term object
        $time period = reset($phrases);
        // Get the time period hyperlink (button hyperlink)
        $hyperlink = get_term_link( $time period, 'product_cat' );

        // Button textual content
        $textual content = __('← Again to class','woocommerce') . ' <sturdy>' . $time period->identify . '</sturdy>';

        // Output
        echo '<div class="back-to-category"><a href="'.esc_url($hyperlink).'" title="'.$textual content.'" '.$time period->slug.'">'.$textual content.'</a></div>';
    }
}

If you happen to woulkd prefer to customise this Woocommerce Again to class button then use this piece of CSS code.

.back-to-category {
	margin-top: 1.5em;
	border: 1px stable #ddd;
	border-radius: 50px;
	padding: 7px 20px;
	text-align: heart;
	transition: border-color 0.5s ease;
}
.back-to-category:hover {
	border: 1px stable #1e1e1e;
}

Tips on how to change Woocommerce add to cart button textual content if product is in backorder?

I’ve had clients who’re confused in regards to the backorders they usually haven’t realized that the product is out of inventory and it should be pre-ordered. Due to this fact I wanted to vary Woocommerce add to cart button textual content for backorder merchandise. Now, if I mix it with the {custom} subject (hack #1 above) then the tip outcome will appear like this:

How to change Woocommerce add to cart button text if product is in backorder?

Seems to be good, isn’t it? So, use this code snippet.

add_filter( 'woocommerce_product_single_add_to_cart_text', 'wc_ninja_change_backorder_button', 10, 2 );
perform wc_ninja_change_backorder_button( $textual content, $product ){
	if ( $product->is_on_backorder( 1 ) ) {
		$textual content = __( 'Pre-order', 'woocommerce' );
	}
	return $textual content;
}

add_filter( 'woocommerce_product_add_to_cart_text', 'wc_ninja_change_backorder_button1', 10, 2 );
perform wc_ninja_change_backorder_button1( $textual content, $product ){
    if ( $product->is_on_backorder( 1 ) ) {
        $textual content = __( 'Pre-order', 'woocommerce' );
    }
    return $textual content;
  }

Tips on how to add NEW badge for the Woocommerce merchandise newer than 30 days?

This snippet right here beneath will add NEW badge for the Woocommerce merchandise which can be newer than 30 days. In order for you it to be kind of than 30 days then change Newness in days quantity.

<span position="button" tabindex="0" data-code="// New badge
add_action( 'woocommerce_single_product_summary', 'new_badge', 5 );

perform new_badge() {
world $product;
$newness_days = 30; // Newness in days
$created = strtotime( $product->get_date_created() );
if ( ( time() – ( 60 * 60 * 24 * $newness_days ) ) < $created ) {
echo '<span class="itsnew">' . esc_html__( 'NEW', 'woocommerce' ) . '

// New badge
add_action( 'woocommerce_single_product_summary', 'new_badge', 5 );
          
perform new_badge() {
   world $product;
   $newness_days = 30; // Newness in days 
   $created = strtotime( $product->get_date_created() );
   if ( ( time() - ( 60 * 60 * 24 * $newness_days ) ) < $created ) {
      echo '<span class="itsnew">' . esc_html__( 'NEW', 'woocommerce' ) . '</span>';
   }
}

Now let’s customise this Woocommerce NEW badge. Add this piece of CSS into Extra CSS field.

.itsnew {
	background: #f37b21;
	padding: 5px 10px;
	font-size: 12px;
	font-weight: 700;
	shade: #fff;
}

Tips on how to add estimated supply date and time in your Woocommerce single product web page?

With the assistance of this snippet it is possible for you to so as to add a estimated supply date and time in your Woocommerce single product web page. Check out the screenshot right here beneath.

How to add estimated delivery date and time on your Woocommerce single product page?

add_action('woocommerce_after_add_to_cart_button', 'delivery_estimate');

perform delivery_estimate() {
    date_default_timezone_set('Europe/Tallinn');

    // if FRI/SAT/SUN supply can be MON
    if (date('N') >= 5) {
        $del_day = date("l jS F", strtotime("subsequent monday"));
        $order_by = "Monday";
    }

    // if MON/THU after 4PM supply can be day after tomorrow
    elseif (date('H') >= 16) {
        $del_day = date("l jS F", strtotime("tomorrow + 2 days"));
        $order_by = "day after tomorrow";
    }

    // if MON/THU earlier than 4PM supply can be TOMORROW
    else {
        $del_day = date("l jS F", strtotime("tomorrow"));
        $order_by = "at the moment";
    }

    $html = "<br><div class='woocommerce-message' type='clear:each'>Order by 4PM {$order_by} for supply on {$del_day}</div>";

    echo $html;
}

Tips on how to present estimated supply date for particular class?

If that you must present estimated supply date for particular product class then that you must add two traces of code. So, add this line slightly below your perform identify row. Additionally, you would want so as to add } signal to the final line.

 if ( has_term( 'furnishings', 'product_cat' ) ) { // Change "furnishings" with your personal class slug

Simply substitute “furnishings” slug with your personal product class slug. So, that is the total code that can present estimated supply date for Furnishings class.

add_action( 'woocommerce_after_add_to_cart_form', 'specific_category_delivery_estimate' );
    
perform specific_category_delivery_estimate() {
  if ( has_term( 'furnishings', 'product_cat' ) ) { // Change "furnishings" with your personal class slug
   date_default_timezone_set( 'Europe/Tallinn' );  
    
   // if FRI/SAT/SUN supply can be MON
   if ( date( 'N' ) >= 5 ) {
      $del_day = date( "l jS F", strtotime( "subsequent tuesday" ) );
      $order_by = "Monday";
   } 
    
   // if MON/THU after 4PM supply can be day after tomorrow
   elseif ( date( 'H' ) >= 16 ) {
      $del_day = date( "l jS F", strtotime( "tomorrow + 1 day" ) );
      $order_by = "tomorrow";
   } 
    
   // if MON/THU earlier than 4PM supply can be TOMORROW
   else {
      $del_day = date( "2 jS F", strtotime( "tomorrow" ) );
      $order_by = "at the moment";
   }
 
   $html = "<br><div class='woocommerce-message' type='clear:each'>Order by 4PM {$order_by} for supply on {$del_day}</div>";
    
   echo $html;
}
}

Tips on how to present estimated supply date for particular class or product?

Now, if that you must present this on a particular product web page then it really works equally as with the classes byt this time add this row as an alternative and substitute “426” with your personal product ID.

 if ( is_single( '426' ) ) { // Change "426" with your personal product ID

And the total code for a particular product is that this.

add_action( 'woocommerce_after_add_to_cart_form', 'specific_product_delivery_estimate' );
    
perform specific_product_delivery_estimate() {
 if ( is_single( '426' ) ) {
   date_default_timezone_set( 'Europe/Tallinn' );  
    
   // if FRI/SAT/SUN supply can be MON
   if ( date( 'N' ) >= 5 ) {
      $del_day = date( "l jS F", strtotime( "subsequent tuesday" ) );
      $order_by = "Monday";
   } 
    
   // if MON/THU after 4PM supply can be day after tomorrow
   elseif ( date( 'H' ) >= 16 ) {
      $del_day = date( "l jS F", strtotime( "tomorrow + 1 day" ) );
      $order_by = "tomorrow";
   } 
    
   // if MON/THU earlier than 4PM supply can be TOMORROW
   else {
      $del_day = date( "2 jS F", strtotime( "tomorrow" ) );
      $order_by = "at the moment";
   }
 
   $html = "<br><div class='woocommerce-message' type='clear:each'>Order by 4PM {$order_by} for supply on {$del_day}</div>";
    
   echo $html;
}
}

Tips on how to add Woocommerce product enquiry type?

This snippet right here provides a button beneath your Add to cart button. If you happen to click on on the button then the contact type opens up. Simply substitute the contact type shortcode inside this snippet (line 6).

add_action( 'woocommerce_single_product_summary', 'enquiry_form', 30 );
perform enquiry_form() {

echo '<button kind="submit" id="trigger_cf" class="button alt" type="margin-bottom: 20px;">Ship us your enquiry</button>';
echo '<div id="product_inq" type="show:none">';
echo do_shortcode('[your-shortcode-here]');
echo '</div>';
}
add_action( 'woocommerce_single_product_summary', 'enquiry_form_1', 40);
perform enquiry_form_1() {
  ?>
    <script kind="textual content/javascript">
        jQuery('#trigger_cf').on('click on', perform(){
        if ( jQuery(this).textual content() == 'Ship us your enquiry' ) {
                    jQuery('#product_inq').css("show","block");
            jQuery("#trigger_cf").html('Shut');
        } else {
            jQuery('#product_inq').cover();
            jQuery("#trigger_cf").html('Ship us your enquiry');
        }
        });
    </script>
    <?php    
}

You may also use conditionals. For instance, for the Clothes class merchandise I’m displaying one type and for all different merchandise one other type. simply substitute the class slug inside “clothes” a part of the code.

add_action( 'woocommerce_single_product_summary', 'enquiry_form', 30 );
perform enquiry_form() {
	if ( has_term( 'clothes', 'product_cat' ) ) {
echo '<button kind="submit" id="trigger_cf" class="button alt">Ship us your enquiry</button>';
echo '<div id="product_inq" type="show:none">';
echo do_shortcode('');
echo '</div>';
} else {
echo '<button kind="submit" id="trigger_cf" class="button alt" type="margin-bottom: 20px;">Ship us your enquiry</button>';
echo '<div id="product_inq" type="show:none">';
echo do_shortcode('');
echo '</div>';
}
}
add_action( 'woocommerce_single_product_summary', 'enquiry_form_1', 40);
perform enquiry_form_1() {
  ?>
    <script kind="textual content/javascript">
        jQuery('#trigger_cf').on('click on', perform(){
        if ( jQuery(this).textual content() == 'Ship us your enquiry' ) {
                    jQuery('#product_inq').css("show","block");
            jQuery("#trigger_cf").html('Shut');
        } else {
            jQuery('#product_inq').cover();
            jQuery("#trigger_cf").html('Ship us your enquiry');
        }
        });
    </script>
    <?php    
}

Tips on how to disable (gray out) number of out-of-stock variation?

On your clients it’s a lot simpler to decide on solely the variations which can be obtainable. Due to this fact, I’ll present you how you can disable /gray out) number of out-of-stock product variations.

add_filter( 'woocommerce_variation_is_active', 'disable_variations_out_of_stock', 10, 2 );
 
perform disable_variations_out_of_stock( $is_active, $variation ) {
    if ( ! $variation->is_in_stock() ) return false;
    return $is_active;
}

Tips on how to embrace a product thumbail alongside the identify and worth of Woocommerce grouped merchandise?

This small piece of code will add a product thumbnail for the Woocommerce product grouped merchandise desk. If you happen to wan to vary the picture measurement then simply modify the 40, 40 half.

<span position="button" tabindex="0" data-code="add_action( 'woocommerce_grouped_product_list_before_price', 'woocommerce_grouped_product_thumbnail' );

perform woocommerce_grouped_product_thumbnail( $product ) {
$image_size = array( 40, 40 ); // array( width, top ) picture measurement in pixel
$attachment_id = get_post_meta( $product->id, '_thumbnail_id', true );
?>
<td class="label">
<?php echo wp_get_attachment_image( $attachment_id, $image_size ); ?>
</td>

add_action( 'woocommerce_grouped_product_list_before_price', 'woocommerce_grouped_product_thumbnail' );

perform woocommerce_grouped_product_thumbnail( $product ) {
    $image_size = array( 40, 40 );  // array( width, top ) picture measurement in pixel 
    $attachment_id = get_post_meta( $product->id, '_thumbnail_id', true );
    ?>
    <td class="label">
        <?php echo wp_get_attachment_image( $attachment_id, $image_size ); ?>
    </td>
    <?php
}

Tips on how to take away Woocommerce critiques tab?

Additionally a straightforward activity. Use this snippet right here to take away Woocommerce critiques tab.

add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );

perform woo_remove_product_tabs( $tabs ) {
    unset( $tabs['reviews'] ); // Take away the critiques tab
    return $tabs;
}

Tips on how to cover Woocommerce product worth for out of inventory merchandise?

This snippet right here beneath hides Woocommerce product worth for out of inventory merchandise

add_filter( 'woocommerce_get_price_html', 'wpsh_hide_price', 9999, 2 );
 
perform wpsh_hide_price( $worth, $product ) {
   if ( is_admin() ) return $worth; // BAIL IF BACKEND
   if ( ! $product->is_in_stock() ) {
      $worth = apply_filters( 'woocommerce_empty_price_html', '', $product );
   }
   return $worth;
}

Would you like extra helpful Woocommerce suggestions?

  • 12 helpful Woocommerce snippets & hacks
  • Tips on how to Customise Woocommerce store and class web page? 17 helpful hacks
  • Tips on how to Cover Woocommerce Delivery Strategies (Conditionally) – 15 Hacks
  • Tips on how to customise Woocommerce cart web page? 21 helpful Woocommerce Cart Web page Hacks
  • Tips on how to Customise Woocommerce Checkout web page? 27 helpful hacks
  • Tips on how to Add Woocommerce Variation Pictures Gallery for Free?
  • Woocommerce – Disable Cost Strategies Primarily based on Consumer Roles
  • Tips on how to promote tickets with Woocommerce?
  • Tips on how to Add Woocommerce Pricing Guidelines & Dynamic Pricing for Free
  • Tips on how to export Woocommerce orders in CSV, XLS, XML, JSON and many others.

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart
Scroll to Top