FormModifier.php
34 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPDesk\FCF\Free\Form; |
| 4 | |
| 5 | use FcfVendor\WPDesk\PluginBuilder\Plugin\Hookable; |
| 6 | |
| 7 | /** |
| 8 | * Default checkout form modifications. |
| 9 | */ |
| 10 | class FormModifier implements Hookable { |
| 11 | |
| 12 | public function hooks() { |
| 13 | add_action( 'woocommerce_before_order_notes', [ $this, 'maybe_hide_order_section' ] ); |
| 14 | } |
| 15 | |
| 16 | /** |
| 17 | * Hides checkout order section ("Additional information") |
| 18 | * when there are no checkout fields to display. |
| 19 | * |
| 20 | * @param \WC_Checkout $checkout. |
| 21 | */ |
| 22 | public function maybe_hide_order_section( $checkout ): void { |
| 23 | if ( ! $checkout instanceof \WC_Checkout ) { |
| 24 | return; |
| 25 | } |
| 26 | |
| 27 | $order_fields = $checkout->get_checkout_fields( 'order' ); |
| 28 | |
| 29 | if ( is_array( $order_fields ) && 0 === count( $order_fields ) ) { |
| 30 | add_filter( 'woocommerce_enable_order_notes_field', '__return_false' ); |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 |