Community
Administrator
Staff member
So this is something we've done a few times on clients stores, for this you will need to paste these codes in to your code snippet plugin, or themes functions.php
First we add the function for the new status, you can add remove or change text where you see appropriate, just remember to do it through out all of the below snippets.
Add the available text and CSS classes for the text on the front end.
Finally add the status checks to the back end for single, variable etc
First we add the function for the new status, you can add remove or change text where you see appropriate, just remember to do it through out all of the below snippets.
PHP:
function filter_woocommerce_product_stock_status_options( $status ){$status['made_to_order'] = __( 'Made to order', 'woocommerce' );
$status['one_three_days'] = __( '1-3 days', 'woocommerce' );
$status['one_two_days'] = __( '1-2 days', 'woocommerce' );
$status['two_three_days'] = __( '2-3 days', 'woocommerce' );
$status['seven_four_days'] = __( '7-14 days', 'woocommerce' );
$status['delivery_request'] = __( 'Delivery on Request', 'woocommerce' );
$status['direct_factory'] = __( 'Direct from Factory', 'woocommerce' );
return $status;
}
add_filter( 'woocommerce_product_stock_status_options', 'filter_woocommerce_product_stock_status_options', 10, 1 );
Add the available text and CSS classes for the text on the front end.
PHP:
function filter_woocommerce_get_availability_text( $availability, $product ){switch( $product->get_stock_status() ){case 'made_to_order':
$availability = __( 'Made to order', 'woocommerce' );
break;
case 'one_two_days':
$availability = __( '1-2 days', 'woocommerce' );
break;
case 'one_three_days':
$availability = __( '1-3 days', 'woocommerce' );
break;
case 'two_three_days':
$availability = __( '2-3 days', 'woocommerce' );
break;
case 'seven_four_days':
$availability = __( '7-14 days', 'woocommerce' );
break;
case 'delivery_request':
$availability = __( 'Delivery on Request', 'woocommerce' );
break;
case 'direct_factory':
$availability = __( 'Direct from Factory', 'woocommerce' );
break;
}
return $availability;
}
add_filter( 'woocommerce_get_availability_text', 'filter_woocommerce_get_availability_text', 10, 2 );
function filter_woocommerce_get_availability_class( $class, $product ){switch( $product->get_stock_status() ){case 'made_to_order':
$class = 'made-to-order';
break;
case 'one_two_days':
$class = 'one-two-days';
break;
case 'one_three_days':
$class = 'one-three-days';
break;
case 'two_three_days':
$class = 'two-three-days';
break;
case 'seven_four_days':
$class = 'seven_four_days';
break;
case 'delivery_request':
$class = 'Delivery on Request';
break;
case 'direct_factory':
$class = 'Direct from Factory';
break;
}
return $class;
}
add_filter( 'woocommerce_get_availability_class', 'filter_woocommerce_get_availability_class', 10, 2 );
Finally add the status checks to the back end for single, variable etc
PHP:
function filter_woocommerce_admin_stock_html( $stock_html, $product ){if ( $product->is_type( 'simple' ) ){$product_stock_status = $product->get_stock_status();
} elseif ( $product->is_type( 'variable' ) ){foreach( $product->get_visible_children() as $variation_id ){$variation = wc_get_product( $variation_id );
$product_stock_status = $variation->get_stock_status();
/*
Currently the status of the last variant in the loop will be displayed.
So from here you need to add your own logic, depending on what you expect from your custom stock status.
By default, for the existing statuses. The status displayed on the admin products list table for variable products is determined as:
- Product should be in stock if a child is in stock.
- Product should be out of stock if all children are out of stock.
- Product should be on backorder if all children are on backorder.
- Product should be on backorder if at least one child is on backorder and the rest are out of stock.
*/
}
}
switch( $product_stock_status ){case 'made_to_order':
$stock_html = '<mark class="pre-order" style="background:transparent none;color:#33ccff;font-weight:700;line-height:1;">' . __( 'Made to order', 'woocommerce' ) . '</mark>';
break;
case 'one_two_days':
$stock_html = '<mark class="contact-us" style="background:transparent none;color:#cc33ff;font-weight:700;line-height:1;">' . __( '1-2 days', 'woocommerce' ) . '</mark>';
break;
case 'one_three_days':
$stock_html = '<mark class="contact-us" style="background:transparent none;color:#cc33ff;font-weight:700;line-height:1;">' . __( '1-3 days', 'woocommerce' ) . '</mark>';
break;
case 'two_three_days':
$stock_html = '<mark class="contact-us" style="background:transparent none;color:#cc33ff;font-weight:700;line-height:1;">' . __( '2-3 days', 'woocommerce' ) . '</mark>';
break;
case 'seven_four_days':
$stock_html = '<mark class="contact-us" style="background:transparent none;color:#cc33ff;font-weight:700;line-height:1;">' . __( '7-14 days', 'woocommerce' ) . '</mark>';
break;
case 'delivery_request':
$stock_html = '<mark class="contact-us" style="background:transparent none;color:#cc33ff;font-weight:700;line-height:1;">' . __( 'Delivery on Request', 'woocommerce' ) . '</mark>';
break;
case 'direct_factory':
$stock_html = '<mark class="contact-us" style="background:transparent none;color:#cc33ff;font-weight:700;line-height:1;">' . __( 'Direct from Factory', 'woocommerce' ) . '</mark>';
break;
}
return $stock_html;
}
add_filter( 'woocommerce_admin_stock_html', 'filter_woocommerce_admin_stock_html', 10, 2 );