diff --git a/assets/js/admin/meta-boxes-webhook.js b/assets/js/admin/meta-boxes-webhook.js new file mode 100644 index 000000000000..bd2748ebe187 --- /dev/null +++ b/assets/js/admin/meta-boxes-webhook.js @@ -0,0 +1,16 @@ +jQuery( function ( $ ) { + $( '#webhook-options #topic' ).on( 'change', function() { + var current = $( this ).val(), + action_event_field = $( '#webhook-options .action_event_field' ), + custom_topic_field = $( '#webhook-options .custom_topic_field' ); + + action_event_field.hide(); + custom_topic_field.hide(); + + if ( 'action' === current ) { + action_event_field.show(); + } else if ( 'custom' === current ) { + custom_topic_field.show(); + } + }).change(); +}); diff --git a/assets/js/admin/meta-boxes-webhook.min.js b/assets/js/admin/meta-boxes-webhook.min.js new file mode 100644 index 000000000000..a09261dd0fc5 --- /dev/null +++ b/assets/js/admin/meta-boxes-webhook.min.js @@ -0,0 +1 @@ +jQuery(function(a){a("#webhook-options #topic").on("change",function(){var b=a(this).val(),c=a("#webhook-options .action_event_field"),d=a("#webhook-options .custom_topic_field");c.hide(),d.hide(),"action"===b?c.show():"custom"===b&&d.show()}).change()}); \ No newline at end of file diff --git a/includes/admin/class-wc-admin-assets.php b/includes/admin/class-wc-admin-assets.php index ac4fab1de1ad..a4463ccd7176 100644 --- a/includes/admin/class-wc-admin-assets.php +++ b/includes/admin/class-wc-admin-assets.php @@ -196,6 +196,9 @@ public function admin_scripts() { if ( in_array( $screen->id, array( 'shop_coupon', 'edit-shop_coupon' ) ) ) { wp_enqueue_script( 'wc-admin-coupon-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-coupon' . $suffix . '.js', array( 'wc-admin-meta-boxes' ), WC_VERSION ); } + if ( 'shop_webhook' == $screen->id ) { + wp_enqueue_script( 'wc-admin-webhook-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-webhook' . $suffix . '.js', array( 'jquery' ), WC_VERSION, true ); + } if ( in_array( str_replace( 'edit-', '', $screen->id ), array_merge( array( 'shop_coupon', 'product' ), wc_get_order_types( 'order-meta-boxes' ) ) ) ) { $params = array( 'remove_item_notice' => __( 'Are you sure you want to remove the selected items? If you have previously reduced this item\'s stock, or this order was submitted by a customer, you will need to manually restore the item\'s stock.', 'woocommerce' ), @@ -224,16 +227,16 @@ public function admin_scripts() { 'no_customer_selected' => __( 'No customer selected', 'woocommerce' ), 'plugin_url' => WC()->plugin_url(), 'ajax_url' => admin_url( 'admin-ajax.php' ), - 'order_item_nonce' => wp_create_nonce("order-item"), - 'add_attribute_nonce' => wp_create_nonce("add-attribute"), - 'save_attributes_nonce' => wp_create_nonce("save-attributes"), - 'calc_totals_nonce' => wp_create_nonce("calc-totals"), - 'get_customer_details_nonce' => wp_create_nonce("get-customer-details"), - 'search_products_nonce' => wp_create_nonce("search-products"), - 'grant_access_nonce' => wp_create_nonce("grant-access"), - 'revoke_access_nonce' => wp_create_nonce("revoke-access"), - 'add_order_note_nonce' => wp_create_nonce("add-order-note"), - 'delete_order_note_nonce' => wp_create_nonce("delete-order-note"), + 'order_item_nonce' => wp_create_nonce( 'order-item' ), + 'add_attribute_nonce' => wp_create_nonce( 'add-attribute' ), + 'save_attributes_nonce' => wp_create_nonce( 'save-attributes' ), + 'calc_totals_nonce' => wp_create_nonce( 'calc-totals' ), + 'get_customer_details_nonce' => wp_create_nonce( 'get-customer-details' ), + 'search_products_nonce' => wp_create_nonce( 'search-products' ), + 'grant_access_nonce' => wp_create_nonce( 'grant-access' ), + 'revoke_access_nonce' => wp_create_nonce( 'revoke-access' ), + 'add_order_note_nonce' => wp_create_nonce( 'add-order-note' ), + 'delete_order_note_nonce' => wp_create_nonce( 'delete-order-note' ), 'calendar_image' => WC()->plugin_url().'/assets/images/calendar.png', 'post_id' => isset( $post->ID ) ? $post->ID : '', 'base_country' => WC()->countries->get_base_country(), diff --git a/includes/admin/wc-admin-functions.php b/includes/admin/wc-admin-functions.php index cd9568d23315..fbcee3ec605a 100644 --- a/includes/admin/wc-admin-functions.php +++ b/includes/admin/wc-admin-functions.php @@ -35,6 +35,8 @@ function wc_get_screen_ids() { 'edit-product_tag', 'edit-product_shipping_class', 'profile', + 'shop_webhook', + 'edit-shop_webhook' ); foreach ( wc_get_order_types() as $type ) {