__( '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 ); ?>
*/ 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