Skip to content

Commit

Permalink
Improve rendering of Order Attribution inputs (#44333)
Browse files Browse the repository at this point in the history
- Expose public method to render OA input fields 
- Render OA inputs on `woocommerce_checkout_after_customer_details` 
   in case the checkout form does not contain `woocommerce_checkout_shipping`, `woocommerce_after_order_notes`.

Addresses part of #44159

Co-authored-by: Justin Palmer <228780+layoutd@users.noreply.github.com>
Co-authored-by: github-actions <github-actions@github.com>
  • Loading branch information
3 people committed Feb 21, 2024
1 parent c601a0b commit 0d3008b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: update

Move rendering of Order Attribution inputs to `woocommerce_checkout_after_customer_details`. Expose a method for custom theming.
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,8 @@ function() {
}
);

// Include our hidden `<input>` elements on order notes and registration form.
$source_form_elements = function() {
$this->source_form_elements();
};

add_action( 'woocommerce_after_order_notes', $source_form_elements );
add_action( 'woocommerce_register_form', $source_form_elements );
add_action( 'woocommerce_checkout_after_customer_details', array( $this, 'source_form_elements' ) );
add_action( 'woocommerce_register_form', array( $this, 'source_form_elements' ) );

// Update order based on submitted fields.
add_action(
Expand Down Expand Up @@ -347,10 +342,11 @@ private function output_origin_column( WC_Order $order ) {
}

/**
* Add `<input type="hidden">` elements for source fields.
* Used for checkout & customer register froms.
* Print `<input type="hidden">` elements for source fields.
* To be picked up and populated with data by the JS.
* Used for checkout & customer register forms.
*/
private function source_form_elements() {
public function source_form_elements() {
foreach ( $this->field_names as $field_name ) {
printf( '<input type="hidden" name="%s" value="" />', esc_attr( $this->get_prefixed_field_name( $field_name ) ) );
}
Expand Down

0 comments on commit 0d3008b

Please sign in to comment.