Created
September 12, 2024 09:37
-
-
Save pramodjodhani/fbfc2e9d4004f424d1d08af0fe22c689 to your computer and use it in GitHub Desktop.
Iconic WDS - Add Pickup instructions above the delivery slots fields.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Iconic WDS - Add Pickup instructions above the delivery slots fields. | |
| */ | |
| add_filter( 'iconic_wds_after_delivery_details_title', function( $title ) { | |
| // Todo1 - Add URL of the Pickup Instructions Page. | |
| ?> | |
| <a href="#" id="wds-pickup-instructions">Click here to read the Pickup instructions.</a> | |
| <?php | |
| } ); | |
| add_action( 'wp_footer', 'wds_add_custom_js_to_toggle_pickup_instructions' ); | |
| /** | |
| * Add custom JS to toggle pickup instructions. | |
| * | |
| * @return void | |
| */ | |
| function wds_add_custom_js_to_toggle_pickup_instructions() { | |
| ?> | |
| <script> | |
| function iconic_wds_toggle_pickup_instructions() { | |
| // get selected shipping method | |
| var selectedShippingMethod = jQuery( 'input[name="shipping_method[0]"]:checked' ).val(); | |
| // if local pickup is selected the show the pickup instructions else hide | |
| if ( selectedShippingMethod.includes( 'local_pickup' ) ) { | |
| jQuery( '#wds-pickup-instructions' ).show(); | |
| } else { | |
| jQuery( '#wds-pickup-instructions' ).hide(); | |
| } | |
| } | |
| // run iconic_wds_toggle_pickup_instructions on page load and checkout updated event | |
| jQuery( document ).ready( iconic_wds_toggle_pickup_instructions ); | |
| jQuery( document ).on( 'updated_checkout', iconic_wds_toggle_pickup_instructions ); | |
| </script> | |
| <?php | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment