Automattic\WooCommerce\Blocks\BlockTypes\OrderConfirmation
Status::render_content │ protected │ WC 1.0
This renders the content of the block within the wrapper.
Метод класса: Status{}
Возвращает
string.
Использование
// protected - в коде основоного (родительского) или дочернего класса
$result = $this->render_content( $order, $permission, $attributes, $content );
- $order(WC_Order) (обязательный)
- Order object.
- $permission(строка|false)
- If the current user can view the order details or not.
По умолчанию: false
- $attributes(массив)
- Block attributes.
По умолчанию: []
- $content(строка)
- Original block content.
По умолчанию: ''
Код Status::render_content() Status::render content
WC 11.2.1
protected function render_content( $order, $permission = false, $attributes = [], $content = '' ) {
if ( ! $permission ) {
// phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
return '<p>' . wp_kses_post( apply_filters( 'woocommerce_thankyou_order_received_text', esc_html__( 'Thank you. Your order has been received.', 'woocommerce' ), null ) ) . '</p>';
}
$content = $this->get_hook_content( 'woocommerce_before_thankyou', [ $order->get_id() ] );
$status = $order->get_status();
// Unlike the core handling, this includes some extra messaging for completed orders so the text is appropriate for other order statuses.
switch ( $status ) {
case 'cancelled':
$content .= '<h1>' . wp_kses_post(
/**
* Filter the title shown after a checkout is complete.
*
* @since 9.6.0
*
* @param string $title The title.
* @param WC_Order|false $order The order created during checkout, or false if order data is not available.
*/
apply_filters(
'woocommerce_thankyou_order_received_title',
esc_html__( 'Order cancelled', 'woocommerce' ),
$order
)
) . '</h1>';
$content .= '<p>' . wp_kses_post(
// phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
apply_filters(
'woocommerce_thankyou_order_received_text',
esc_html__( 'Your order has been cancelled.', 'woocommerce' ),
$order
)
) . '</p>';
break;
case 'refunded':
$content .= '<h1>' . wp_kses_post(
// phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
apply_filters(
'woocommerce_thankyou_order_received_title',
esc_html__( 'Order refunded', 'woocommerce' ),
$order
)
) . '</h1>';
$content .= '<p>' . wp_kses_post(
sprintf(
// phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
apply_filters(
'woocommerce_thankyou_order_received_text',
// translators: %s: date and time of the order refund.
esc_html__( 'Your order was refunded %s.', 'woocommerce' ),
$order
),
wc_format_datetime( $order->get_date_modified() )
)
) . '</p>';
break;
case 'completed':
$content .= '<h1>' . wp_kses_post(
// phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
apply_filters(
'woocommerce_thankyou_order_received_title',
esc_html__( 'Order completed', 'woocommerce' ),
$order
)
) . '</h1>';
$content .= '<p>' . wp_kses_post(
// phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
apply_filters(
'woocommerce_thankyou_order_received_text',
esc_html__( 'Thank you. Your order has been fulfilled.', 'woocommerce' ),
$order
)
) . '</p>';
break;
case 'failed':
$default_order_failed_text = esc_html__( 'Your order cannot be processed as the originating bank/merchant has declined your transaction. Please attempt your purchase again.', 'woocommerce' );
// Null, not $order: passing the real order would let WC_Gateway_Paypal::order_received_text()
// overwrite this failure message with PayPal success copy, since that callback checks the
// payment method but not the order status.
// phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
$legacy_order_failed_text = apply_filters( 'woocommerce_thankyou_order_received_text', $default_order_failed_text, null );
$order_failed_text = is_string( $legacy_order_failed_text ) ? $legacy_order_failed_text : $default_order_failed_text;
/**
* Filters the message shown when an order has failed.
*
* Runs after the legacy order-received filter so callbacks can customize the final failed-order message.
*
* @param string $message The failed order message.
* @param \WC_Order $order The failed order.
*
* @since 11.2.0
*/
$filtered_order_failed_text = apply_filters( 'woocommerce_thankyou_order_failed_text', $order_failed_text, $order );
$order_failed_text = is_string( $filtered_order_failed_text ) ? $filtered_order_failed_text : $order_failed_text;
$actions = '<a href="' . esc_url( $order->get_checkout_payment_url() ) . '" class="button">' . esc_html__( 'Try again', 'woocommerce' ) . '</a> ';
if ( wc_get_page_permalink( 'myaccount' ) ) {
$actions .= '<a href="' . esc_url( wc_get_page_permalink( 'myaccount' ) ) . '" class="button">' . esc_html__( 'My account', 'woocommerce' ) . '</a> ';
}
$content .= '<h1>' . wp_kses_post(
// phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
apply_filters(
'woocommerce_thankyou_order_received_title',
esc_html__( 'Order failed', 'woocommerce' ),
$order
)
) . '</h1>';
$content .= '
<p>' . wp_kses_post( $order_failed_text ) . '</p>
<p class="wc-block-order-confirmation-status__actions">' . $actions . '</p>
';
break;
default:
$content .= '<h1>' . wp_kses_post(
// phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
apply_filters(
'woocommerce_thankyou_order_received_title',
esc_html__( 'Order received', 'woocommerce' ),
$order
)
) . '</h1>';
$content .= '<p>' . wp_kses_post(
// phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
apply_filters(
'woocommerce_thankyou_order_received_text',
esc_html__( 'Thank you. Your order has been received.', 'woocommerce' ),
$order
)
) . '</p>';
break;
}
return $content;
}