ACF\Pro\Forms

WC_Order::add_meta_boxespublicACF 6.4

Adds ACF metaboxes to the WooCommerce Order pages.

Метод класса: WC_Order{}

Возвращает

null. Ничего (null).

Использование

$WC_Order = new WC_Order();
$WC_Order->add_meta_boxes( $post_type, $post );
$post_type(строка) (обязательный)
The current post type.
$post(WP_Post) (обязательный)
The WP_Post object or the WC_Order object.

Список изменений

С версии 6.4 Введена.

Код WC_Order::add_meta_boxes() ACF 6.4.2

public function add_meta_boxes( $post_type, $post ) {
	// Storage for localized postboxes.
	$postboxes = array();

	$location = 'shop_order';
	$order    = ( $post instanceof \WP_Post ) ? wc_get_order( $post->ID ) : $post;
	$screen   = $this->is_hpos_enabled() ? wc_get_page_screen_id( 'shop-order' ) : 'shop_order';

	if ( $order instanceof \WC_Subscription ) {
		$location = 'shop_subscription';
		$screen   = function_exists( 'wcs_get_page_screen_id' ) ? wcs_get_page_screen_id( 'shop_subscription' ) : 'shop_subscription';
	}

	// Get field groups for this screen.
	$field_groups = acf_get_field_groups(
		array(
			'post_id'   => $order->get_id(),
			'post_type' => $location,
		)
	);

	// Loop over field groups.
	if ( $field_groups ) {
		foreach ( $field_groups as $field_group ) {
			$id       = "acf-{$field_group['key']}"; // acf-group_123
			$title    = $field_group['title'];       // Group 1
			$context  = $field_group['position'];    // normal, side, acf_after_title
			$priority = 'core';                      // high, core, default, low

			// Allow field groups assigned to after title to still be rendered.
			if ( 'acf_after_title' === $context ) {
				$context = 'normal';
			}

			/**
			 * Filters the metabox priority.
			 *
			 * @since 6.4
			 *
			 * @param string $priority    The metabox priority (high, core, default, low).
			 * @param array  $field_group The field group array.
			 */
			$priority = apply_filters( 'acf/input/meta_box_priority', $priority, $field_group );

			// Localize data
			$postboxes[] = array(
				'id'    => $id,
				'key'   => $field_group['key'],
				'style' => $field_group['style'],
				'label' => $field_group['label_placement'],
				'edit'  => acf_get_field_group_edit_link( $field_group['ID'] ),
			);

			// Add the meta box.
			add_meta_box(
				$id,
				acf_esc_html( $title ),
				array( $this, 'render_meta_box' ),
				$screen,
				$context,
				$priority,
				array( 'field_group' => $field_group )
			);
		}

		// Localize postboxes.
		acf_localize_data(
			array(
				'postboxes' => $postboxes,
			)
		);
	}

	// Removes the WordPress core "Custom Fields" meta box.
	if ( acf_get_setting( 'remove_wp_meta_box' ) ) {
		remove_meta_box( 'order_custom', $screen, 'normal' );
	}

	// Add hidden input fields.
	add_action( 'order_edit_form_top', array( $this, 'order_edit_form_top' ) );

	/**
	 * Fires after metaboxes have been added.
	 *
	 * @date    13/12/18
	 * @since   5.8.0
	 *
	 * @param string   $post_type    The post type.
	 * @param \WP_Post $post         The post being edited.
	 * @param array    $field_groups The field groups added.
	 */
	do_action( 'acf/add_meta_boxes', $post_type, $post, $field_groups );
}