Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent Additional Checkout Fields values being shown on shortcode order confirmation #47333

Merged
merged 4 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Prevent empty checkboxes added by Additional Checkout Fields API showing in the order confirmation when the order was placed using the shortcode checkout experience.
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ protected function render_content( $order, $permission = false, $attributes = []
}

// Contact and additional fields are currently grouped in this section.
$additional_fields = array_merge(
Package::container()->get( CheckoutFields::class )->get_fields_for_location( 'contact' ),
Package::container()->get( CheckoutFields::class )->get_fields_for_location( 'order' )
// If none of the additional fields for contact or order have values then the "Additional fields' section should
// not show in the order confirmation.
$additional_field_values = array_merge(
Package::container()->get( CheckoutFields::class )->get_order_additional_fields_with_values( $order, 'contact' ),
Package::container()->get( CheckoutFields::class )->get_order_additional_fields_with_values( $order, 'order' )
);

return empty( $additional_fields ) ? '' : $content;
return empty( $additional_field_values ) ? '' : $content;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1279,6 +1279,15 @@ function ( $field ) {
* @return array An array of fields definitions as well as their values formatted for display.
*/
public function get_order_additional_fields_with_values( WC_Order $order, string $location, string $group = 'other', string $context = 'edit' ) {

// Because the Additional Checkout Fields API only applies to orders created with Store API, we should not
// return any values unless it was created using Store API. This is mainly to prevent "empty" checkbox values
// from being shown on the order confirmation page for orders placed using the shortcode. It's rare that this
// will happen but not impossible.
if ( 'store-api' !== $order->get_created_via() ) {
return [];
}

if ( 'additional' === $location ) {
wc_deprecated_argument( 'location', '8.9.0', 'The "additional" location is deprecated. Use "order" instead.' );
$location = 'order';
Expand Down