Automattic\WooCommerce\Blocks\BlockTypes

Checkout::update_local_pickup_title()publicWC 1.0

Update the local pickup title in WooCommerce Settings when the checkout page containing a Checkout block is saved.

Method of the class: Checkout{}

No Hooks.

Return

null. Nothing (null).

Usage

$Checkout = new Checkout();
$Checkout->update_local_pickup_title( $post_id, $post );
$post_id(int) (required)
The post ID.
$post(\WP_Post) (required)
The post object.

Checkout::update_local_pickup_title() code WC 9.5.1

public function update_local_pickup_title( $post_id, $post ) {

	// This is not a proper save action, maybe an autosave, so don't continue.
	if ( empty( $post->post_status ) || 'inherit' === $post->post_status ) {
		return;
	}

	// Check if we are editing the checkout page and that it contains a Checkout block.
	// Cast to string for Checkout page ID comparison because get_option can return it as a string, so better to compare both values as strings.
	if ( ! empty( $post->post_type ) && 'wp_template' !== $post->post_type && ( false === has_block( 'woocommerce/checkout', $post ) || (string) get_option( 'woocommerce_checkout_page_id' ) !== (string) $post_id ) ) {
		return;
	}

	if ( ( ! empty( $post->post_type ) && ! empty( $post->post_name ) && 'page-checkout' !== $post->post_name && 'wp_template' === $post->post_type ) || false === has_block( 'woocommerce/checkout', $post ) ) {
		return;
	}
	$pickup_location_settings = LocalPickupUtils::get_local_pickup_settings( 'edit' );

	if ( ! isset( $pickup_location_settings['title'] ) ) {
		return;
	}

	if ( empty( $post->post_content ) ) {
		return;
	}

	$post_blocks = parse_blocks( $post->post_content );
	$title       = $this->find_local_pickup_text_in_checkout_block( $post_blocks );

	// Set the title to be an empty string if it isn't a string. This will make it fall back to the default value of "Pickup".
	if ( ! is_string( $title ) ) {
		$title = '';
	}

	$pickup_location_settings['title'] = $title;
	update_option( 'woocommerce_pickup_location_settings', $pickup_location_settings );
}