Automattic\WooCommerce\Internal\StockNotifications\Frontend

ProductPageIntegration::maybe_render_formpublicWC 1.0

Handle BIS form.

Method of the class: ProductPageIntegration{}

No Hooks.

Returns

null. Nothing (null).

Usage

$ProductPageIntegration = new ProductPageIntegration();
$ProductPageIntegration->maybe_render_form();

ProductPageIntegration::maybe_render_form() code WC 10.3.6

public function maybe_render_form() {

	if ( ! Config::allows_signups() ) {
		return;
	}

	global $product;
	if ( ! is_product() || ! is_a( $product, 'WC_Product' ) ) {
		return;
	}

	if ( isset( $this->rendered[ $product->get_id() ] ) ) {
		return;
	}

	$this->rendered[ $product->get_id() ] = true;

	$is_variable = $product->is_type( 'variable' );
	// Check if the product is in stock.
	// Hint: This is negative logic. If the product is eligible for notifications, skip rendering.
	// We avoid checking for variable products here because we want to render the form for out of stock variations.
	if ( ! $is_variable && $this->eligibility_service->is_stock_status_eligible( $product->get_stock_status() ) ) {
		return;
	}

	if ( ! $this->eligibility_service->is_product_eligible( $product ) ) {
		return;
	}

	if ( ! $this->eligibility_service->product_allows_signups( $product ) ) {
		return;
	}

	// Enqueue the script.
	wp_enqueue_script( 'wc-back-in-stock-form' );

	$this->render_form( $product );
}