Home / eCommerce / WWOF – Hide the “In Stock Amount” column for non-wholesale customers
Duplicate Snippet

Embed Snippet on Your Site

WWOF – Hide the “In Stock Amount” column for non-wholesale customers

To hide a different column, swap the "elementClass" in line 29.

All available element classes in the form:
product-image
product-name
product-sku
product-price
in-stock-amount
quantity-input
add-to-cart-button
short-description

Code Preview
php
<?php
/**
 * Hide the "In Stock Amount" column in Wholesale Order Form for non-wholesale customers.
 *
 * Uses the wwof_order_form_body_meta filter to strip the in-stock-amount column
 * when the current user does not have a wholesale role.
 */
add_filter( 'wwof_order_form_body_meta', function ( $form_body, $form_id, $meta_key ) {
	// Only act on the form body (not header/footer meta).
	if ( 'form_body' !== $meta_key ) {
		return $form_body;
	}
	// Determine if the current user has a wholesale role.
	global $wc_wholesale_prices;
	$is_wholesale = false;
	if ( isset( $wc_wholesale_prices->wwp_wholesale_roles ) ) {
		$user_wholesale_role = $wc_wholesale_prices->wwp_wholesale_roles->getUserWholesaleRole();
		$is_wholesale        = ! empty( $user_wholesale_role );
	}
	// Non-wholesale users: remove the in-stock-amount column.
	if ( ! $is_wholesale && ! empty( $form_body['columns'] ) ) {
		$form_body['columns'] = array_values(
			array_filter(
				$form_body['columns'],
				function ( $column ) {
					return ( $column['elementClass'] ?? '' ) !== 'in-stock-amount';
				}
			)
		);
	}
	return $form_body;
}, 10, 3 );

Comments

Add a Comment