Automattic\WooCommerce\Internal\OrderReviews

Endpoint::enqueue_assetsprivateWC 1.0

Enqueue the JS and CSS that progressively enhance the page.

Both files live under client/legacy/ and are built into assets/{js|css}/ by the classic-assets pipeline.

Method of the class: Endpoint{}

Hooks from the method

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->enqueue_assets(): void;

Endpoint::enqueue_assets() code WC 10.8.1

private function enqueue_assets(): void {
	$plugin_url = untrailingslashit( plugins_url( '', WC_PLUGIN_FILE ) );
	$suffix     = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
	$version    = Constants::get_constant( 'WC_VERSION' );
	$asset_url  = static function ( string $path ) use ( $plugin_url ): string {
		// phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment -- documented in includes/class-wc-frontend-scripts.php.
		return (string) apply_filters( 'woocommerce_get_asset_url', $plugin_url . $path, $path );
	};

	wp_enqueue_style( 'wc-order-review', $asset_url( '/assets/css/order-review.css' ), array(), $version );
	// Tell WP to swap to the *-rtl.css variant on RTL sites.
	wp_style_add_data( 'wc-order-review', 'rtl', 'replace' );

	wp_enqueue_script(
		'wc-order-review',
		$asset_url( '/assets/js/frontend/order-review' . $suffix . '.js' ),
		array(),
		$version,
		array(
			'strategy'  => 'defer',
			'in_footer' => true,
		)
	);

	wp_localize_script(
		'wc-order-review',
		'wcOrderReview',
		array(
			'i18n' => array(
				'ok'                 => __( 'Thanks, your review is live.', 'woocommerce' ),
				'pending_moderation' => __( 'Thanks, your review is pending approval.', 'woocommerce' ),
				'error'              => __( 'Something went wrong, please try again.', 'woocommerce' ),
				'rating_required'    => __( 'Please rate this product before submitting your review.', 'woocommerce' ),
			),
		)
	);
}