__( 'Deposit', 'advanced-partial-payment-or-deposit-for-woocommerce' ), 'target' => 'apd_deposit_product_data', 'class' => array( 'show_if_simple', 'show_if_variable' ), 'priority' => 80, ); return $tabs; } /** * Render deposit panel on product edit. */ public function render_product_panel() { global $post; $product_id = $post->ID; $context = $this->get_product_deposit_context( $product_id ); ?>

'_apd_enable_deposit', 'label' => __( 'Enable Deposit', 'advanced-partial-payment-or-deposit-for-woocommerce' ), 'options' => array( '' => __( 'Use Global Setting', 'advanced-partial-payment-or-deposit-for-woocommerce' ), 'yes' => __( 'Yes', 'advanced-partial-payment-or-deposit-for-woocommerce' ), 'no' => __( 'No', 'advanced-partial-payment-or-deposit-for-woocommerce' ), ), 'value' => get_post_meta( $product_id, '_apd_enable_deposit', true ), 'desc_tip' => true, 'description' => __( 'Enable or disable deposit for this specific product.', 'advanced-partial-payment-or-deposit-for-woocommerce' ), ) ); woocommerce_wp_select( array( 'id' => '_apd_force_deposit', 'label' => __( 'Force Deposit Only', 'advanced-partial-payment-or-deposit-for-woocommerce' ), 'options' => array( '' => __( 'Use Global Setting', 'advanced-partial-payment-or-deposit-for-woocommerce' ), 'yes' => __( 'Yes', 'advanced-partial-payment-or-deposit-for-woocommerce' ), 'no' => __( 'No', 'advanced-partial-payment-or-deposit-for-woocommerce' ), ), 'value' => get_post_meta( $product_id, '_apd_force_deposit', true ), 'desc_tip' => true, 'description' => __( 'Force this product to show only the deposit/partial payment option and hide full payment.', 'advanced-partial-payment-or-deposit-for-woocommerce' ), ) ); $deposit_type_options = array( 'global' => __( 'Use Global Setting', 'advanced-partial-payment-or-deposit-for-woocommerce' ), 'fixed' => __( 'Fixed Amount', 'advanced-partial-payment-or-deposit-for-woocommerce' ), 'percentage' => __( 'Percentage', 'advanced-partial-payment-or-deposit-for-woocommerce' ), ); if ( defined( 'APD_PRO_VERSION' ) ) { $deposit_type_options['payment_plan'] = __( 'Payment Plan (Pro)', 'advanced-partial-payment-or-deposit-for-woocommerce' ); $deposit_type_options['min_max'] = __( 'Min / Max – Customer Chooses (Pro)', 'advanced-partial-payment-or-deposit-for-woocommerce' ); } woocommerce_wp_select( array( 'id' => '_apd_deposit_type', 'label' => __( 'Deposit Type', 'advanced-partial-payment-or-deposit-for-woocommerce' ), 'options' => $deposit_type_options, 'value' => get_post_meta( $product_id, '_apd_deposit_type', true ) ?: 'global', 'desc_tip' => true, 'description' => __( 'Choose deposit type for this product.', 'advanced-partial-payment-or-deposit-for-woocommerce' ), ) ); echo '
'; woocommerce_wp_text_input( array( 'id' => '_apd_deposit_value', 'label' => __( 'Deposit Value', 'advanced-partial-payment-or-deposit-for-woocommerce' ), 'type' => 'number', 'value' => get_post_meta( $product_id, '_apd_deposit_value', true ), 'placeholder' => __( 'e.g. 50', 'advanced-partial-payment-or-deposit-for-woocommerce' ), 'desc_tip' => true, 'description' => __( 'Enter deposit value. For percentage: enter 50 for 50%. For fixed: enter the exact amount.', 'advanced-partial-payment-or-deposit-for-woocommerce' ), 'custom_attributes' => array( 'step' => '0.01', 'min' => '0', ), ) ); echo '
'; ?>

'_apd_min_deposit', 'label' => __( 'Minimum Deposit', 'advanced-partial-payment-or-deposit-for-woocommerce' ), 'type' => 'number', 'value' => get_post_meta( $product_id, '_apd_min_deposit', true ), 'placeholder' => __( 'Use global', 'advanced-partial-payment-or-deposit-for-woocommerce' ), 'desc_tip' => true, 'description' => __( 'Minimum deposit amount for this product.', 'advanced-partial-payment-or-deposit-for-woocommerce' ), 'custom_attributes' => array( 'step' => '0.01', 'min' => '0', ), ) ); woocommerce_wp_text_input( array( 'id' => '_apd_max_deposit', 'label' => __( 'Maximum Deposit', 'advanced-partial-payment-or-deposit-for-woocommerce' ), 'type' => 'number', 'value' => get_post_meta( $product_id, '_apd_max_deposit', true ), 'placeholder' => __( 'Use global', 'advanced-partial-payment-or-deposit-for-woocommerce' ), 'desc_tip' => true, 'description' => __( 'Maximum deposit amount for this product.', 'advanced-partial-payment-or-deposit-for-woocommerce' ), 'custom_attributes' => array( 'step' => '0.01', 'min' => '0', ), ) ); echo '
'; endif; ?>

$plan ) : ?>

Payment Plans first.', 'advanced-partial-payment-or-deposit-for-woocommerce' ); ?>

'_apd_flexible_payments', 'label' => __( 'Flexible Payments (Pro)', 'advanced-partial-payment-or-deposit-for-woocommerce' ), 'options' => array( '' => __( 'Use Global Setting', 'advanced-partial-payment-or-deposit-for-woocommerce' ), 'yes' => __( 'Yes', 'advanced-partial-payment-or-deposit-for-woocommerce' ), 'no' => __( 'No', 'advanced-partial-payment-or-deposit-for-woocommerce' ), ), 'value' => get_post_meta( $product_id, '_apd_flexible_payments', true ), 'desc_tip' => true, 'description' => __( 'Let the customer pay off the remaining balance in any amount they choose, over as many payments as they like, until this booking is paid in full. Yes or No overrides the global Flexible Payments setting for this product. No extra fields to fill in — the deposit above still decides the first payment; this only decides whether the rest can be paid freely.', 'advanced-partial-payment-or-deposit-for-woocommerce' ), ) ); ?>

0 ? esc_html( $currency . number_format( $eff_min, 2 ) ) : '—'; ?> 0 ) { esc_html_e( 'Source: Global settings', 'advanced-partial-payment-or-deposit-for-woocommerce' ); } else { esc_html_e( 'No minimum set', 'advanced-partial-payment-or-deposit-for-woocommerce' ); } ?>
0 ? esc_html( $currency . number_format( $eff_max, 2 ) ) : '—'; ?> 0 ) { esc_html_e( 'Source: Global settings', 'advanced-partial-payment-or-deposit-for-woocommerce' ); } else { esc_html_e( 'No maximum set', 'advanced-partial-payment-or-deposit-for-woocommerce' ); } ?>
$plan ) : $total_pct = 0; foreach ( $plan['installments'] as $inst ) { $total_pct += floatval( $inst['amount'] ); } $plan_status_active = ( $plan['status'] ?? 'active' ) === 'active'; ?>
*/ private function get_product_deposit_context( $product_id ) { $product = wc_get_product( $product_id ); $product_price = $product ? floatval( $product->get_price() ) : 0; $category_data = array( 'enable' => '', 'force' => '', 'type' => 'global', 'value' => '', 'name' => __( 'No category override', 'advanced-partial-payment-or-deposit-for-woocommerce' ), ); if ( $product ) { foreach ( $product->get_category_ids() as $category_id ) { $term = get_term( $category_id, 'product_cat' ); $cat_name = ( $term && ! is_wp_error( $term ) ) ? $term->name : __( 'Category rule', 'advanced-partial-payment-or-deposit-for-woocommerce' ); $cat_enable = get_term_meta( $category_id, '_apd_enable_deposit', true ); $cat_force = get_term_meta( $category_id, '_apd_force_deposit', true ); $cat_type = get_term_meta( $category_id, '_apd_deposit_type', true ); $cat_value = get_term_meta( $category_id, '_apd_deposit_value', true ); if ( '' === $category_data['enable'] && in_array( $cat_enable, array( 'yes', 'no' ), true ) ) { $category_data['enable'] = $cat_enable; $category_data['name'] = $cat_name; } if ( '' === $category_data['force'] && in_array( $cat_force, array( 'yes', 'no' ), true ) ) { $category_data['force'] = $cat_force; $category_data['name'] = $cat_name; } if ( 'global' === $category_data['type'] && ! empty( $cat_type ) && 'global' !== $cat_type ) { $category_data['type'] = $cat_type; $category_data['name'] = $cat_name; } if ( '' === $category_data['value'] && '' !== (string) $cat_value && ! empty( $cat_type ) && 'global' !== $cat_type ) { $category_data['value'] = $cat_value; $category_data['name'] = $cat_name; } } } return array( 'product' => array( 'enable' => get_post_meta( $product_id, '_apd_enable_deposit', true ), 'force' => get_post_meta( $product_id, '_apd_force_deposit', true ), 'type' => get_post_meta( $product_id, '_apd_deposit_type', true ) ?: 'global', 'value' => get_post_meta( $product_id, '_apd_deposit_value', true ), ), 'category' => $category_data, 'global' => array( 'enable' => apd_get_option( 'enable_deposit', 'yes' ), 'force' => apd_get_option( 'force_deposit', 'no' ), 'type' => apd_get_option( 'deposit_type', 'percentage' ), 'value' => apd_get_option( 'deposit_value', 50 ), ), 'min_max' => array( 'global_min' => defined( 'APD_PRO_VERSION' ) ? floatval( apd_get_option( 'min_deposit_amount', 0 ) ) : 0, 'global_max' => defined( 'APD_PRO_VERSION' ) ? floatval( apd_get_option( 'max_deposit_amount', 0 ) ) : 0, 'product_min' => defined( 'APD_PRO_VERSION' ) ? get_post_meta( $product_id, '_apd_min_deposit', true ) : '', 'product_max' => defined( 'APD_PRO_VERSION' ) ? get_post_meta( $product_id, '_apd_max_deposit', true ) : '', ), 'plans' => $this->get_product_plan_context( $product_id ), 'product_price' => $product_price, 'currency_symbol' => html_entity_decode( get_woocommerce_currency_symbol(), ENT_QUOTES, 'UTF-8' ), 'currency_pos' => get_option( 'woocommerce_currency_pos', 'left' ), 'price_decimals' => wc_get_price_decimals(), ); } /** * Build product payment plan context for the admin summary panel. * * @param int $product_id Product ID. * @return array */ private function get_product_plan_context( $product_id ) { $context = array( 'assigned' => array(), 'available' => array(), ); if ( ! defined( 'APD_PRO_VERSION' ) || ! class_exists( 'APD_Payment_Plans' ) ) { return $context; } $context['assigned'] = array_values( array_filter( array_map( 'strval', (array) get_post_meta( $product_id, '_apd_assigned_plans', true ) ) ) ); foreach ( APD_Payment_Plans::get_plans() as $plan_id => $plan ) { $context['available'][] = array( 'id' => (string) $plan_id, 'name' => $plan['name'] ?? '', 'status' => $plan['status'] ?? 'active', 'price_type' => $plan['price_type'] ?? 'percentage', 'installments_count' => ! empty( $plan['installments'] ) && is_array( $plan['installments'] ) ? count( $plan['installments'] ) : 0, 'installments' => ! empty( $plan['installments'] ) && is_array( $plan['installments'] ) ? array_values( $plan['installments'] ) : array(), ); } return $context; } }