Category override > Default phone * * @param array $args Arguments (product_id, category_ids, etc). * @return string Phone number in E.164 format. */ public static function resolve_agent_phone( $args = array() ) { $phone = ''; $source = 'default'; // Check for product-specific override (highest precedence). if ( ! empty( $args['product_id'] ) ) { $product_phone = get_post_meta( $args['product_id'], '_oc_agent_phone', true ); if ( $product_phone ) { $phone = $product_phone; $source = 'product_override'; } } // If no product override, check for category override. if ( empty( $phone ) && ! empty( $args['category_ids'] ) && is_array( $args['category_ids'] ) ) { foreach ( $args['category_ids'] as $category_id ) { $cat_phone = get_term_meta( $category_id, '_oc_agent_phone', true ); if ( $cat_phone ) { $phone = $cat_phone; $source = 'category_override'; break; } } } // Fall back to default if no overrides. if ( empty( $phone ) ) { $phone = Settings::get( 'default_phone', '' ); $source = 'default'; } // Add source to context for Pro to check. $args['_resolved_source'] = $source; /** * Filter to resolve which agent phone should handle this order. * * @since 1.0.0 * @param string $phone Default/overridden phone number. * @param array $args Context arguments (includes _resolved_source: 'product_override', 'category_override', or 'default'). */ return apply_filters( 'ordercourier_resolve_agent', $phone, $args ); } /** * Get phone from legacy agent post (for backward compatibility when Pro is not active). * * @param int $agent_id Agent post ID. * @return string Phone number or empty string. */ public static function get_legacy_agent_phone( $agent_id ) { if ( ! $agent_id ) { return ''; } $agent = get_post( $agent_id ); if ( ! $agent || 'oc_agent' !== $agent->post_type ) { return ''; } // Get phone from agent post meta. $phone = get_post_meta( $agent_id, '_oc_phone', true ); return $phone ? $phone : ''; } /** * Check if agent is online. * In FREE, agents are always considered online. * PRO can override via 'ordercourier_agent_online_status' filter. * * @param string $phone Agent phone number. * @param array $context Context data. * @return bool */ public static function is_agent_online( $phone, $context = array() ) { /** * Filter agent online status. * * @since 1.0.0 * @param bool $is_online Default online status (true in FREE). * @param string $phone Agent phone number. * @param array $context Context data. */ return apply_filters( 'ordercourier_agent_online_status', true, $phone, $context ); } }