Hello,
We apologize if our previous response did not fully meet your expectations. However, as your request falls outside the scope of our basic support, we referred you to a company that provides customization services.
If you are a developer and would like to create a shortcode (or similar functionality) to display only the product variations that are available on backorder, you will need to:
1. Create a shortcode.
2. Review the WooCommerce functions that display product attributes, as you will need to filter them to show only those marked as “on backorder.”
Useful functions and files may include:
– get_variation_attributes()
– woocommerce/includes/class-wc-product-variable.php
– woocommerce/includes/class-wc-product-variation.php
3. Once you have created the shortcode, ensure that you first display all attributes from the current product. You can use the global $product variable (see https://prnt.sc/X-qLu0j8ZfRi) at the beginning of your code before checking for attributes.
As a simple starting point, you may use the following php snippet:
function etheme_child_onbackorder_variations_shortcode( $atts ) {
$atts = shortcode_atts(
array(
'product_id' => '',
'show_price' => false,
'show_sku' => false,
'no_items_msg' => '',
),
$atts,
'onbackorder_variations'
);
// Get product.
if ( ! empty( $atts['product_id'] ) ) {
$product = wc_get_product( (int) $atts['product_id'] );
} else {
global $product;
}
if ( ! $product || ! $product->is_type( 'variable' ) ) {
return '';
}
$backorder_variations = array();
// Get all variation IDs for the product.
$variation_ids = $product->get_children();
foreach ( $variation_ids as $variation_id ) {
$variation = wc_get_product( $variation_id );
if ( ! $variation || ! $variation->exists() ) {
continue;
}
if ( 'onbackorder' !== $variation->get_stock_status() ) {
continue;
}
$backorder_variations[] = $variation;
}
if ( empty( $backorder_variations ) ) {
if ( ! empty( $atts['no_items_msg'] ) ) {
return wp_kses_post( $atts['no_items_msg'] );
}
return '';
}
ob_start();
echo '<ul class="onbackorder-variations-list">';
foreach ( $backorder_variations as $variation ) {
$attributes = $variation->get_attributes();
$parts = array();
foreach ( $attributes as $taxonomy => $value_slug ) {
if ( ! $value_slug ) {
continue;
}
$label = $taxonomy;
if ( 0 === strpos( $taxonomy, 'pa_' ) ) {
$label = wc_attribute_label( $taxonomy );
}
$value_label = $value_slug;
if ( taxonomy_exists( $taxonomy ) ) {
$term = get_term_by( 'slug', $value_slug, $taxonomy );
if ( $term && ! is_wp_error( $term ) ) {
$value_label = $term->name;
}
} else {
$value_label = wc_clean( str_replace( '-', ' ', $value_slug ) );
}
$parts[] = sprintf(
'%s: %s',
esc_html( $label ),
esc_html( $value_label )
);
}
echo '<li class="onbackorder-variation" data-variation_id="' . esc_attr( $variation->get_id() ) . '">';
if ( ! empty( $parts ) ) {
echo '<span class="onbackorder-variation-attributes">' . esc_html( implode( ', ', $parts ) ) . '</span>';
}
if ( !!$atts['show_price'] ) {
echo ' <span class="onbackorder-variation-price">' . wp_kses_post( $variation->get_price_html() ) . '</span>';
}
if ( !!($atts['show_sku'] ) && $variation->get_sku() ) {
echo ' <span class="onbackorder-variation-sku">SKU: ' . esc_html( $variation->get_sku() ) . '</span>';
}
echo '</li>';
}
echo '</ul>';
return ob_get_clean();
}
add_shortcode( 'etheme_child_onbackorder_variations', 'etheme_child_onbackorder_variations_shortcode' );
Please note that providing additional customization is beyond the scope of our basic support.
Best regards,
Jack Richardson
8Theme Team















