From ca0264eec3307c0309c06eb7d90da55cb3619147 Mon Sep 17 00:00:00 2001 From: Soare Robert Daniel Date: Fri, 20 Sep 2024 09:41:27 +0300 Subject: [PATCH] refactor: product metabox for fields attach (#382) --- classes/admin.class.php | 42 +++++++++++++ inc/admin.php | 128 +++++++++++++++++++++++++++++----------- 2 files changed, 137 insertions(+), 33 deletions(-) diff --git a/classes/admin.class.php b/classes/admin.class.php index 7083ddd9..9a4c8b25 100644 --- a/classes/admin.class.php +++ b/classes/admin.class.php @@ -398,6 +398,48 @@ function ppom_tabs_custom_style() { td.ppom-files-display a.button { text-align: center; } + + .ppom-settings-container { + display: flex; + flex-direction: column; + gap: 15px; + margin: 10px 15px; + } + + .ppom-settings-container-item { + display: flex; + align-items: center; + gap: 10px; + } + + label.ppom-settings-container-item { + width: 100%; + max-width: 600px; + margin: unset; + } + + .ppom-settings-container .ppom-upsell-link { + display: inline-flex; + align-items: center; + padding: 0.5rem 1rem; + font-size: 0.875rem; + font-weight: 500; + color: #2563eb; + background-color: #eff6ff; + border: 1px solid #bfdbfe; + border-radius: 0.375rem; + text-decoration: none; + transition: all 150ms ease-in-out; + } + + .ppom-settings-container .ppom-upsell-link:hover { + background-color: #dbeafe; + color: #1d4ed8; + } + + .ppom-settings-container .ppom-disabled-text { + color: #8d8d8d; + } ID ); $all_meta = PPOM()->get_product_meta_all(); $ppom_setting = admin_url( 'admin.php?page=ppom' ); + + $html = '
'; + + // UP-SELL + $html .= ''; + $html .= ' '; + $html .= __( 'Using multiple PPOM Fields on the same product is available in PRO.', 'woocommerce-product-addon' ); + $html .= ''; + + // PPOM Fields select table. + $html .= ''; + + $html .= '
'; + $html .= ''; + $html .= '' . __( 'Create New Meta', 'woocommerce-product-addon' ) . ''; + $html .= '
'; - $html = '
'; - $html .= '

' . __( 'Select Meta to Show Fields on this product', 'woocommerce-product-addon' ); - // $html .= __(' Or Create New Meta', 'woocommerce-product-addon'); - $html .= '

'; - - $html .= '

'; - $html .= '

'; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + foreach ( $all_meta as $meta ) { + $html .= ''; + + // Select/Checkbox + $html .= ''; - $html .= ''; - } - $html .= ''; + // ID Column + $html .= ''; - if ( $ppom->single_meta_id != 'None' ) { + // Meta Name Column + $html .= ''; - $ppom_add_args = array( - 'productmeta_id' => $ppom->single_meta_id, - 'do_meta' => 'edit', - 'product_id' => $post->ID, + // Edit Meta Shortcut Column + $url_edit = add_query_arg( + array( + 'productmeta_id' => $meta->productmeta_id, + 'do_meta' => 'edit', + ), + $ppom_setting ); - $url_edit = add_query_arg( $ppom_add_args, $ppom_setting ); - $html .= ' '; - } + $html .= ''; - // $html .= '
'; - // $html .= ' Create New Meta'; + $html .= ''; + } - $html .= '

'; + $html .= '
' . __( 'Select Meta', 'woocommerce-product-addon' ) . '' . __( 'Meta ID', 'woocommerce-product-addon' ) . '' . __( 'Meta Name', 'woocommerce-product-addon' ) . '' . __( 'Edit', 'woocommerce-product-addon' ) . '
'; + $html .= 'meta_id ) && + ( + ( + is_array( $ppom->meta_id ) && + in_array( $meta->productmeta_id, $ppom->meta_id ) + ) || + ( + is_numeric( $ppom->meta_id ) && + $ppom->meta_id === $meta->productmeta_id + ) + ) + ) { + $html .= ' checked '; + } + $html .= 'id="ppom-' . esc_attr( $meta->productmeta_id ) . '">'; + $html .= '' . $meta->productmeta_id . '' . stripslashes( $meta->productmeta_name ) . ''; + $html .= ''; + $html .= '
'; $html .= '
'; - $ppom_add_args = array( - 'action' => 'new', - 'product_id' => $post->ID, - ); - $ppom_setting_url = add_query_arg( $ppom_add_args, $ppom_setting ); + $html .= '
'; + $html .= '
'; + $html .= '' . __( 'PPOM PopUp Settings', 'woocommerce-product-addon' ) . ' (' . __( 'PRO', 'woocommerce-product-addon' ) . ')' . ''; + $html .= ''; + $html .= ''; + $html .= '
'; + + $html .= '
'; + $html .= '
'; + $html .= '' . __( 'PPOM Enquiry Form Settings', 'woocommerce-product-addon' ) . ' (' . __( 'PRO', 'woocommerce-product-addon' ) . ')' . ''; + $html .= ''; + $html .= '
'; + + ?> + +